將 bgra 流轉換為 mp4

將 bgra 流轉換為 mp4

我正在嘗試使用以下命令錄製iOS模擬器的影片;

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

問題是生成的影片是亂碼。

ffmpeg 似乎沒有正確轉換 bgra 格式。

我還需要傳遞其他參數嗎?

下面貼上的範例輸出中間有一條警告:

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

這是範例輸出;

./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

謝謝,

——蘇曼

答案1

問題是生成的影片是亂碼。

我今天遇到了完全相同的問題。原因是,fbsimctl bgra 輸出是 BMP 檔案格式,每個圖像數組都用 0 填充,使其長度變為 4 的倍數(參見https://en.wikipedia.org/wiki/BMP_file_format以獲得詳細資訊)。

透過將指定的圖像大小擴展到 4 的倍數,我解決了這個問題。對於您的情況,您應該更改-s 414x736-s 416x736.

答案2

警告:數據未對齊!這可能會導致速度損失

這意味著縮放時輸入或輸出維度之一不是 16 的整數倍。

ffmpeg 加速縮放程式碼(例如 MMX 或 SSE)在編碼時不會以最佳方式運行,即可能會很慢。這沒什麼好擔心的,也不需要做任何事。

當然,如果輸入檔案的影片尺寸不是 16 的精確倍數,那麼您對此無能為力。

這裡發布的另一個答案建議將一個維度更改 4,但關鍵是 ffmpeg 程式碼要求維度精確為 16 的倍數而不是 4 的倍數。

相關內容