2

我目前在 CentOS 6.3 上使用 FFMPEG v1.1。

我配置了 FFMPEG:

./configure --arch=x86_64  --enable-libmp3lame  --enable-librtmp  --enable-libtheora --enable-libvorbis  --enable-libx264 --enable-pthreads --enable-gpl --enable-runtime-cpudetect 

当我运行一个简单的命令通过以下方式将实时输入记录到 MP4 时:

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 /home/irdb/Desktop/test.mp4

我什么也没得到,只是一个灰色的屏幕,边缘有一些伪影。但是,当我运行与 .MPG 相同的命令时,结果很好。但是,我需要 MP4 格式的。

附带说明一下,我正在运行通过 yum 安装的 x264-0.120

我的问题是,我编译ffmpeg的方式有问题吗?或者它可能是别的什么?

编辑:

根据要求输出示例:

# ffmpeg -f video4linux2 -s 640x480 -t 5 -i /dev/video0 -strict 2 /home/irdb/Desktop/test.mp4
ffmpeg version N-50546-g1f5b5b8 Copyright (c) 2000-2013 the FFmpeg developers
built on Mar  7 2013 00:17:44 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --enable-libmp3lame --enable-librtmp --enable-libtheora --enable-   libvorbis --enable-libx264 --enable-pthreads --enable-gpl --enable-runtime-cpudetect
libavutil      52. 18.100 / 52. 18.100
libavcodec     54. 92.100 / 54. 92.100
libavformat    54. 63.104 / 54. 63.104
libavdevice    54.  3.103 / 54.  3.103
libavfilter     3. 42.103 /  3. 42.103
libswscale      2.  2.100 /  2.  2.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  2.100 / 52.  2.100
[video4linux2,v4l2 @ 0x3025120] Estimating duration from bitrate, this may be   inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 128.640356, bitrate: 147456 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
[libx264 @ 0x3026f80] using cpu capabilities: MMX2 SSE2Fast SSEMisalign LZCNT
[libx264 @ 0x3026f80] profile High 4:2:2, level 3.0, 4:2:2 8-bit
[libx264 @ 0x3026f80] 264 - core 130 r2274 c832fe9 - H.264/MPEG-4 AVC codec -  Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3  deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1  me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1  interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1  b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/home/irdb/Desktop/test.mp4':
Metadata:
encoder         : Lavf54.63.104
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv422p, 640x480, q=-1--1, 15360 tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> libx264)
Press [q] to stop, [?] for help
frame=   32 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=21    drframe=   46 fps= 46 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=28 drframe=    62 fps= 41 q=29.0 size=      71kB time=00:00:00.33 bitrate=1735.2kbits/frame=   76 fps=  38 q=29.0 size=     169kB time=00:00:00.80 bitrate=1731.2kbits/frame=   93 fps= 37  q=29.0 size=     311kB time=00:00:01.36 bitrate=1862.3kbits/frame=  107 fps= 35 q=29.0  size=     423kB time=00:00:01.83 bitrate=1891.0kbits/frame=  123 fps= 35 q=29.0 size=      537kB time=00:00:02.36 bitrate=1860.2kbits/frame=  139 fps= 34 q=29.0 size=     664kB  time=00:00:02.90 bitrate=1876.0kbits/frame=  150 fps= 29 q=-1.0 Lsize=    1174kB  time=00:00:04.93 bitrate=1948.7kbits/s dup=81 drop=0    
video:1172kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.133409%
[libx264 @ 0x3026f80] frame I:2     Avg QP:23.22  size: 28460
[libx264 @ 0x3026f80] frame P:136   Avg QP:24.45  size:  8397
[libx264 @ 0x3026f80] frame B:12    Avg QP:26.18  size:    42
[libx264 @ 0x3026f80] consecutive B-frames: 88.0%  4.0%  0.0%  8.0%
[libx264 @ 0x3026f80] mb I  I16..4: 47.1% 28.8% 24.1%
[libx264 @ 0x3026f80] mb P  I16..4:  4.3%  1.9%  1.2%  P16..4: 29.0% 11.4%  9.2%      0.0%  0.0%    skip:43.0%
[libx264 @ 0x3026f80] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  1.5%  0.0%  0.0%   direct: 0.0%  skip:98.5%  L0:16.5% L1:83.5% BI: 0.0%
[libx264 @ 0x3026f80] 8x8 transform intra:26.4% inter:30.7%
[libx264 @ 0x3026f80] coded y,uvDC,uvAC intra: 85.2% 95.6% 83.5% inter: 10.9% 38.6% 24.0%
[libx264 @ 0x3026f80] i16 v,h,dc,p: 33% 19% 40%  8%
[libx264 @ 0x3026f80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  6% 12% 55%  5%  3%  4%  4%  3%  8%
[libx264 @ 0x3026f80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15%  9% 63%  3%  2%  2%  2%  2%  2%
[libx264 @ 0x3026f80] i8c dc,h,v,p: 66% 11% 14%  9%
[libx264 @ 0x3026f80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x3026f80] ref P L0: 56.6%  7.5%  8.1% 27.8%
[libx264 @ 0x3026f80] ref B L0: 83.3% 16.7%
[libx264 @ 0x3026f80] ref B L1: 90.7%  9.3%
[libx264 @ 0x3026f80] kb/s:1918.95
4

1 回答 1

6

您用于显示视频的播放器可能不支持您输出视频的像素格式。如果您观察您的输出日志,您可以看到yuv422p被选为格式。这是平面格式的 4:2:2子采样色度

选择-pix_fmt yuv420p(4:2:0 子采样)应该会给您一个 H.264 编码的视频,可以在任何地方观看。

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 \
-c:v libx264 -pix_fmt yuv420p /home/irdb/Desktop/test.mp4

我在这里明确设置了视频编解码器。养成一个好习惯,以免在 FFmpeg 默认使用另一个编码器的格式时感到惊讶。例如,选择 MPEG 输出格式会使 FFmpeg 选择另一个默认编码器 MPEG-1 ( mpeg1video),它再次使用 4:2:0 二次采样。

于 2013-03-07T21:10:26.067 回答