2

When trying to add a perspective filter on a video using ffmpeg I get a black picture with sound when the resulting format is MP4.

ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" combined.mp4 

Results in a movie where the sound is played but the picture is black.

If I change the container format of the wanted output to MPEG or AVI, like this:

ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" combined.mpg

I get both picture and sound.

What should I do to get to a filtered video without the need for extra transcoding?

The output of ffmpeg is as follows:

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 Answer 1

3

The usual suspect is the picture format of your output video – yuv444p, i.e. non-subsampled video. While your input uses 4:2:0 subsampling, adding the filter in combination with H.264 video upsamples the format to 4:4:4 to preserve the quality. Several players do not support this and will often just show black video, or crash altogether.

The solution is to add -pix_fmt yuv420p as an output option:

ffmpeg -i 2416593.flv -vf "frei0r=perspective:0.2/0.2:0.8/0.2" -pix_fmt yuv420p combined.mp4     

You might be curious about why it works when you choose MPEG or AVI as output containers. In that case, ffmpeg will not default to the x264 encoder (for the H.264 codec), but convert to MPEG-1 (in the case of MPG) or MPEG-4 Part 2 video (in the case of AVI) instead. Both MPEG-1 and MPEG-4 Part 2 encoders do not support 4:4:4, so 4:2:0 is used.

Recent ffmpeg versions should warn you about automatic pixel format conversions to make you aware of the fact that some players do not support it. Consider upgrading your ffmpeg version — although if you're stuck on 1.2.1 with Homebrew like me, it's not possible yet, unless you compile manually.

1
  • Alternatively the format video filter (such as format=yuv420p) can be used anywhere in the filterchain, but I assume it probably does not make much of a difference in this case.
    – llogan
    Sep 3, 2013 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .