Converting bgra stream to mp4

1

I am trying to record video of iOS simulator using the following command;

./fbsimctl stream --bgra --fps 12 - | ffmpeg -f rawvideo -pix_fmt bgra -s 414x736 -framerate 12 -i - -f h264 -r 12 - | ffplay -

The problem is the resulting video is garbled.

It seems like ffmpeg is not converting bgra format properly.

Are there any other parameters that I need to pass?

There is a warning in the middle of the sample output pasted below:

Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264)) [swscaler @ 0x7f8342009000] Warning: data is not aligned! This can lead to a speed loss

Here is the sample output;

./fbsimctl stream --bgra --fps 12 - | ffmpeg -f rawvideo -pix_fmt bgra -s 414x736 -framerate 12  -i - -f h264 -r 12 - | ffplay -
ffmpeg version 4.0.2ffplay version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers Copyright (c) 2003-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)

  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      56. 14.100 / 56. 14.100
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libavfilter     7. 16.100 /  7. 16.100
  libavresample   4.  0.  0 /  4.  0.  0
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  1.100 /  5.  1.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Running /usr/bin/xcode-select --print-path with environment {
    HOME = "/Users/sumancherukuri";
    PATH = "/Users/sumancherukuri/Projects/webrtc/webrtc_ios/depot_tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
}
Connection Did Connect => Bridge: Framebuffer ((null)) | HID (null) | (null)
079C6C51-C335-4273-A566-7D0667693F99 | iPhone X | Booted | iPhone X | iOS 11.4 | x86_64: launch: Bridge: Framebuffer ((null)) | HID (null) | (null)

Mounting Surface with Attributes: {
    format = BGRA;
    "frame_size" = 11069184;
    height = 2436;
    "row_size" = 4544;
    width = 1125;
}
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 117006 kb/s
    Stream #0:0: Video: rawvideo (BGRA / 0x41524742), bgra, 414x736, 117006 kb/s, 12 tbr, 12 tbn, 12 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[swscaler @ 0x7f8342009000] Warning: data is not aligned! This can lead to a speed loss
[libx264 @ 0x7f8343801800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f8343801800] profile High 4:4:4 Predictive, level 2.2, 4:4:4 8-bit
Output #0, h264, to 'pipe:':
  Metadata:
    encoder         : Lavf58.12.100
    Stream #0:0: Video: h264 (libx264), yuv444p, 414x736, q=-1--1, 12 fps, 12 tbn, 12 tbc
    Metadata:
      encoder         : Lavc58.18.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

listen started: Streaming Video
frame=   56 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   79 fps= 77 q=26.0 size=     950kB time=00:00:01.75 bitrate=4448.9kbits/frame=  116 fps= 76 q=26.0 size=    2501kB time=00:00:04.83 bitrate=4239.1kbits/Input #0, h264, from 'pipe:':q=    0KB vq=    0KB sq=    0B f=0/0   
  Duration: N/A, bitrate: N/A

Thanks,

--Suman

suman cherukuri

Posted 2018-08-03T21:51:17.520

Reputation: 11

Does ./fbsimctl stream --bgra --fps 12 - | ffplay -f rawvideo -video_size 414x736 -framerate 12 -pixel_format bgra - play fine? – Gyan – 2018-08-04T05:03:42.083

No, it plays a garbled black and white noise on the screen. Thanks for looking into this! – suman cherukuri – 2018-08-05T05:49:16.450

Answers

1

The problem is the resulting video is garbled.

I encountered exactly the same problem today. The cause is, fbsimctl bgra output is in BMP file style and each image array is padded by 0 so that its length becomes a multiple of 4 (see https://en.wikipedia.org/wiki/BMP_file_format for the detail).

By extending the specified image size to a multiple of 4, I resolved this problem. For your case, you should change -s 414x736 to -s 416x736.

Nozomi Ito

Posted 2018-08-03T21:51:17.520

Reputation: 11