我正在尝试使用以下命令录制 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 代码要求维度不是四的倍数而是十六的倍数。