[FFmpeg-user] Adapting videos for -filter_complex concat

Donovan Watteau tsoomi at gmail.com
Fri Aug 24 09:23:32 CEST 2012


Hello,

I'm trying to automate the following procedure with ffmpeg:

- We have some videos, most of them are H264/AAC .mp4.  However, their
  size, bitrate, and such vary.
- We'd like to merge these videos with a jingle.
- We'd like to keep as much quality from the original video as
  possible.  The new video shouldn't get much bigger than the original
  one.

So far, here's my algorithm:

1) I use ffprobe to get as much information about the original video
   as possible.
2) I use these informations to adapt the jingle to the video.
3) Then, I use "-filter_complex concat" to concatenate the adapted
   jingle to the video.  This way, the original video and its quality
   are preserved.

Looking at FAQ #3.14, I think I'm using the best approach, but if
there's a better way to do that in the first place, please tell me so.

I think my problem lies within step 2), because I can't get the jingle
to be exactly the same as the video, and eventually I'm having
problems creating or playing the final video.

Let's say this is my jingle:
http://www.808.dk/pics/video/gizmo.mp4
and this is my video:
http://static.clipcanvas.com/sample/clipcanvas_14348_H264_640x360.mp4

Here's how I adapt the jingle (see the attached adapted_jingle.log):
/usr/local/bin/ffmpeg -threads 2 \
  -i gizmo.mp4 \
  -vf "scale=iw*min(640/iw\,360/ih):ih*min(640/iw\,360/ih),pad=640:360:(640-iw)/2:(360-ih)/2,setsar=255:254,setdar=680:381" \
  -codec:v h264 -b:v 2004545 -r 25/1 -frames:v 200 -codec:a aac \
  -ar 44100 -ac 2 -b:a 128791 -frames:a 347 -strict -2 \
  adapted_jingle.mp4

(the "-vf scale" line comes from stackoverflow.com/questions/8133242)

Then I try to to concatenate the new jingle and the video this way:
/usr/local/bin/ffmpeg -threads 2 \
  -i adapted_jingle.mp4 -i clipcanvas_14348_H264_640x360.mp4 \
  -filter_complex concat final_video.mp4

which gives me the following error (see the attached concat.log):
[Parsed_concat_0 @ 0x87e4a40] Input link in1:v0 parameters (size 640x360, SAR 255:254) do not match the corresponding output link in0:v0 parameters (640x360, SAR 1:1)
[Parsed_concat_0 @ 0x87e4a40] Failed to configure output pad on Parsed_concat_0

The two SAR don't match, though I gave an explicit "setsar=255:254"
option.

But when I'm not having this problem, I see that the bitrates I gave
on the command line are not used.  Playing with -minrate, -maxrate or
CBR doesn't help much either.  They differ, and eventually the video
I'm creating has playing issues: when the jingle ends, the rest of
the video is played slower than it should be (MPlayer gives a "Too
many video packets in the buffer" warning at this moment).

How can I force ffmpeg to follow all the options it is given? I need
the two video sizes to be the same, even if that means that the
jingle will have black borders or something.  I also need the
bitrates to be the same, even if the _jingle_ is losing some quality.
But I don't know if it's possible for ffmpeg to do that.

If it's not possible, what are my options? FAQ #3.14.2?

Thanks for you help.
-------------- next part --------------
ffmpeg version N-35114-g081a822 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 23 2012 09:11:11 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-x11grab --enable-libopencore-amrwb --enable-libopencore-amrnb --enable-shared --enable-version3 --enable-ffprobe --disable-ffplay --disable-ffserver --disable-devices --disable-network --enable-libx264 --enable-libfaac --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libxvid --enable-libvpx --enable-gpl --enable-nonfree --enable-pthreads
  libavutil      51. 70.100 / 51. 70.100
  libavcodec     54. 54.100 / 54. 54.100
  libavformat    54. 25.104 / 54. 25.104
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 13.100 /  3. 13.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'gizmo.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 1940-02-13 15:00:55
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
    Metadata:
      creation_time   : 1940-02-13 15:00:55
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, s16, 83 kb/s
    Metadata:
      creation_time   : 1940-02-13 15:00:55
[libx264 @ 0x86adbe0] using SAR=1/1
[libx264 @ 0x86adbe0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 @ 0x86adbe0] profile High, level 3.0
[libx264 @ 0x86adbe0] 264 - core 125 r2208 d9d2288 - 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=-2 threads=3 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=abr mbtree=1 bitrate=2004 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'adapted_jingle.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf54.25.104
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 2004 kb/s, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 1940-02-13 15:00:55
    Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, flt, 128 kb/s
    Metadata:
      creation_time   : 1940-02-13 15:00:55
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
  Stream #0:1 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame=   65 fps=0.0 q=17.0 size=     112kB time=00:00:00.64 bitrate=1430.4kbits/s dup=0 drop=10    
frame=   91 fps= 87 q=11.0 size=     388kB time=00:00:01.68 bitrate=1893.4kbits/s dup=0 drop=15    
frame=  111 fps= 72 q=15.0 size=     664kB time=00:00:02.48 bitrate=2194.9kbits/s dup=0 drop=19    
frame=  131 fps= 63 q=16.0 size=     931kB time=00:00:03.28 bitrate=2326.0kbits/s dup=0 drop=23    
frame=  141 fps= 44 q=-1.0 Lsize=    1379kB time=00:00:05.56 bitrate=2031.5kbits/s dup=0 drop=25    

video:1285kB audio:88kB subtitle:0 global headers:0kB muxing overhead 0.425851%
[libx264 @ 0x86adbe0] frame I:1     Avg QP:14.46  size: 35804
[libx264 @ 0x86adbe0] frame P:37    Avg QP: 7.88  size: 22980
[libx264 @ 0x86adbe0] frame B:103   Avg QP:12.10  size:  4163
[libx264 @ 0x86adbe0] consecutive B-frames:  2.1%  0.0%  4.3% 93.6%
[libx264 @ 0x86adbe0] mb I  I16..4: 36.6% 26.5% 36.8%
[libx264 @ 0x86adbe0] mb P  I16..4:  3.9%  4.0%  2.7%  P16..4: 35.7% 22.7% 24.8%  0.0%  0.0%    skip: 6.1%
[libx264 @ 0x86adbe0] mb B  I16..4:  0.2%  0.2%  0.3%  B16..8: 40.5% 11.2%  5.0%  direct: 7.5%  skip:35.2%  L0:43.5% L1:46.4% BI:10.1%
[libx264 @ 0x86adbe0] final ratefactor: 8.62
[libx264 @ 0x86adbe0] 8x8 transform intra:35.5% inter:38.9%
[libx264 @ 0x86adbe0] coded y,uvDC,uvAC intra: 78.9% 94.3% 87.8% inter: 22.6% 43.7% 28.2%
[libx264 @ 0x86adbe0] i16 v,h,dc,p:  1% 22%  0% 78%
[libx264 @ 0x86adbe0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  4% 63%  9%  1%  3%  1% 13%  1%  4%
[libx264 @ 0x86adbe0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 38% 14%  3%  8%  3% 13%  2%  5%
[libx264 @ 0x86adbe0] i8c dc,h,v,p: 45% 41%  8%  6%
[libx264 @ 0x86adbe0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x86adbe0] ref P L0: 69.9%  3.5% 18.8%  7.7%
[libx264 @ 0x86adbe0] ref B L0: 87.2% 10.5%  2.3%
[libx264 @ 0x86adbe0] ref B L1: 94.6%  5.4%
[libx264 @ 0x86adbe0] kb/s:1865.00
-------------- next part --------------
ffmpeg version N-35114-g081a822 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 23 2012 09:11:11 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-x11grab --enable-libopencore-amrwb --enable-libopencore-amrnb --enable-shared --enable-version3 --enable-ffprobe --disable-ffplay --disable-ffserver --disable-devices --disable-network --enable-libx264 --enable-libfaac --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libxvid --enable-libvpx --enable-gpl --enable-nonfree --enable-pthreads
  libavutil      51. 70.100 / 51. 70.100
  libavcodec     54. 54.100 / 54. 54.100
  libavformat    54. 25.104 / 54. 25.104
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 13.100 /  3. 13.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'adapted_jingle.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.25.104
  Duration: 00:00:05.64, start: 0.000000, bitrate: 2002 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1866 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 129 kb/s
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'clipcanvas_14348_H264_640x360.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp41avc1
    creation_time   : 1939-01-07 18:53:40
  Duration: 00:00:08.04, start: 0.000000, bitrate: 2128 kb/s
    Stream #1:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 255:254 DAR 680:381], 2004 kb/s, 25 fps, 25 tbr, 600 tbn, 50 tbc
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?Apple Video Media Handler
    Stream #1:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?Apple Sound Media Handler
    Stream #1:2(eng): Data: none (mp4s / 0x7334706D)
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?
    Stream #1:3(eng): Data: none (mp4s / 0x7334706D)
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?
File 'final_video.mp4' already exists. Overwrite ? [y/N] ffmpeg version N-35114-g081a822 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 23 2012 09:11:11 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-x11grab --enable-libopencore-amrwb --enable-libopencore-amrnb --enable-shared --enable-version3 --enable-ffprobe --disable-ffplay --disable-ffserver --disable-devices --disable-network --enable-libx264 --enable-libfaac --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libxvid --enable-libvpx --enable-gpl --enable-nonfree --enable-pthreads
  libavutil      51. 70.100 / 51. 70.100
  libavcodec     54. 54.100 / 54. 54.100
  libavformat    54. 25.104 / 54. 25.104
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 13.100 /  3. 13.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'adapted_jingle.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.25.104
  Duration: 00:00:05.64, start: 0.000000, bitrate: 2002 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1866 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 129 kb/s
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'clipcanvas_14348_H264_640x360.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp41avc1
    creation_time   : 1939-01-07 18:53:40
  Duration: 00:00:08.04, start: 0.000000, bitrate: 2128 kb/s
    Stream #1:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 255:254 DAR 680:381], 2004 kb/s, 25 fps, 25 tbr, 600 tbn, 50 tbc
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?Apple Video Media Handler
    Stream #1:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?Apple Sound Media Handler
    Stream #1:2(eng): Data: none (mp4s / 0x7334706D)
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?
    Stream #1:3(eng): Data: none (mp4s / 0x7334706D)
    Metadata:
      creation_time   : 1939-01-07 18:53:40
      handler_name    : ?
[Parsed_concat_0 @ 0x87e4a40] Input link in1:v0 parameters (size 640x360, SAR 255:254) do not match the corresponding output link in0:v0 parameters (640x360, SAR 1:1)
[Parsed_concat_0 @ 0x87e4a40] Failed to configure output pad on Parsed_concat_0


More information about the ffmpeg-user mailing list