尝试使用以下方式在视频上添加透视滤镜时ffmpeg当结果格式为 MP4 时,我得到的是带有声音的黑屏。
ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" combined.mp4
结果是电影能播放声音但图像是黑的。
如果我将所需输出的容器格式更改为 MPEG 或 AVI,如下所示:
ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" combined.mpg
我既能得到图像,又能得到声音。
我应该怎么做才能获得经过过滤的视频而不需要额外的转码?
ffmpeg的输出如下:
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 3 2013 18:39:11 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-frei0r
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
Input #0, flv, from '2416593.flv':
Metadata:
moovPosition : 8369817
avcprofile : 77
avclevel : 30
aacaot : 2
videoframerate : 25
audiochannels : 2
Duration: 00:00:52.24, start: 0.000000, bitrate: 764 kb/s
Stream #0:0: Video: h264 (Main), yuv420p, 768x432 [SAR 1:1 DAR 16:9], 25 tbr, 1k tbn, 50 tbc
Stream #0:1: Audio: aac, 48000 Hz, stereo, fltp
[libx264 @ 0x7fce828f5600] using SAR=1/1
[libx264 @ 0x7fce828f5600] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x7fce828f5600] profile High 4:4:4 Predictive, level 3.0, 4:4:4 8-bit
[libx264 @ 0x7fce828f5600] 264 - core 125 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - 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=4 threads=12 lookahead_threads=2 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 'combined.mp4':
Metadata:
moovPosition : 8369817
avcprofile : 77
avclevel : 30
aacaot : 2
videoframerate : 25
audiochannels : 2
encoder : Lavf54.63.104
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv444p, 768x432 [SAR 1:1 DAR 16:9], q=-1--1, 12800 tbn, 25 tbc
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> libfaac)
Press [q] to stop, [?] for help
frame= 753 fps= 88 q=-1.0 Lsize= 3145kB time=00:00:30.04 bitrate= 857.7kbits/s dup=2 drop=0
video:2653kB audio:469kB subtitle:0 global headers:0kB muxing overhead 0.750993%
[libx264 @ 0x7fce828f5600] frame I:10 Avg QP:18.43 size: 22903
[libx264 @ 0x7fce828f5600] frame P:234 Avg QP:25.39 size: 7449
[libx264 @ 0x7fce828f5600] frame B:509 Avg QP:28.63 size: 1461
[libx264 @ 0x7fce828f5600] consecutive B-frames: 6.1% 9.8% 4.4% 79.7%
[libx264 @ 0x7fce828f5600] mb I I16..4: 8.7% 67.6% 23.7%
[libx264 @ 0x7fce828f5600] mb P I16..4: 1.9% 5.1% 2.7% P16..4: 22.9% 13.4% 6.9% 0.0% 0.0% skip:47.1%
[libx264 @ 0x7fce828f5600] mb B I16..4: 0.1% 0.1% 0.1% B16..8: 24.4% 3.5% 0.9% direct: 1.0% skip:69.9% L0:41.2% L1:50.2% BI: 8.6%
[libx264 @ 0x7fce828f5600] 8x8 transform intra:57.4% inter:57.5%
[libx264 @ 0x7fce828f5600] coded y,u,v intra: 47.3% 27.1% 22.4% inter: 8.0% 2.4% 1.2%
[libx264 @ 0x7fce828f5600] i16 v,h,dc,p: 17% 37% 7% 39%
[libx264 @ 0x7fce828f5600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 16% 38% 3% 3% 7% 4% 6% 5%
[libx264 @ 0x7fce828f5600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 25% 19% 5% 5% 9% 5% 8% 5%
[libx264 @ 0x7fce828f5600] Weighted P-Frames: Y:3.4% UV:2.6%
[libx264 @ 0x7fce828f5600] ref P L0: 56.2% 11.7% 20.1% 11.8% 0.2%
[libx264 @ 0x7fce828f5600] ref B L0: 88.1% 8.3% 3.6%
[libx264 @ 0x7fce828f5600] ref B L1: 96.5% 3.5%
[libx264 @ 0x7fce828f5600] kb/s:721.32
答案1
通常怀疑的是输出视频的图片格式 –yuv444p
即非子采样视频。虽然您的输入使用 4:2:0 子采样,但将过滤器与 H.264 视频结合使用会将格式上采样为 4:4:4 以保持质量。一些播放器不支持此功能,并且通常只会显示黑色视频,或者完全崩溃。
解决方案是添加-pix_fmt yuv420p
作为输出选项:
ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" -pix_fmt yuv420p combined.mp4
您可能想知道为什么当您选择 MPEG 或 AVI 作为输出容器时它会起作用。在这种情况下,ffmpeg 将不会默认使用 x264 编码器(对于 H.264 编解码器),而是转换为 MPEG-1(对于 MPG)或 MPEG-4 Part 2 视频(对于 AVI)。MPEG-1 和 MPEG-4 Part 2 编码器都不支持 4:4:4,因此使用 4:2:0。
最新的 ffmpeg 版本应该会警告您有关自动像素格式转换的信息,以便让您意识到某些播放器不支持此功能。考虑升级您的 ffmpeg 版本 — 尽管如果您像我一样使用 Homebrew 停留在 1.2.1 版本,除非您手动编译,否则目前还不可能。