0

I'm trying to use avconv to overlay data onto a video. I generate PNG files representing the overlay data at 4fps. The PNG files are the 120px wider and 60px taller than the original video, because there is information added to the border -- 60px to each side and 30px top and bottom.

Here's the avconv command I'm running:

avconv -y \
    -i video/trailer.mp4 \
    -f image2 -r 4 -i overlay/frame%04d.png \
    -filter_complex 'pad=iw+120:ih+60:60:30:white;overlay=0:0' \
    output.mp4

Here's the output:

avconv version 11-6:11-1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 26 2014 14:36:31 with gcc 4.9.1 (Ubuntu 4.9.1-15ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video/trailer.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: mp41
    creation_time   : 2013-10-11 06:00:10
  Duration: 00:02:17.67, start: 0.000000, bitrate: 2651 kb/s
    Stream #0.0(eng): Video: h264 (Constrained Baseline), yuv420p, 1024x430, 2519 kb/s, 29.97 fps, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 1947-10-11 06:00:10
      encoder         : h264
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 1947-10-11 06:00:10
[image2 @ 0x2333580] max_analyze_duration 5000000 reached
Input #1, image2, from 'overlay/frame%04d.png':
  Duration: 00:02:18.00, start: 0.000000, bitrate: N/A
    Stream #1.0: Video: png, gray16be, 1144x490, 4 fps, 4 tbn
[libx264 @ 0x236b1e0] MB rate (66960000) > level limit (2073600)
[libx264 @ 0x236b1e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x236b1e0] profile High, level 5.2
[libx264 @ 0x236b1e0] 264 - core 142 r2431 a5831aa - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=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 'final.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: mp41
    creation_time   : 2013-10-11 06:00:10
    encoder         : Lavf56.1.0
    Stream #0.0: Video: libx264, yuv420p, 1144x490, q=-1--1, 29.97 fps, 30k tbn, 30k tbc (default)
    Metadata:
      encoder         : Lavc56.1.0 libx264
    Stream #0.1(eng): Audio: libvo_aacenc, 44100 Hz, stereo, s16, 200 kb/s (default)
    Metadata:
      creation_time   : 1947-10-11 06:00:10
      encoder         : Lavc56.1.0 libvo_aacenc
Stream mapping:
  Stream #0:0 (h264) -> pad (graph 0)
  Stream #1:0 (png) -> fps (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (aac (native) -> aac (libvo_aacenc))
Press ctrl-c to stop encoding
Error while decoding stream #1:0
    Last message repeated 130 times
Error while decoding stream #1:0      0kB time=10000000000.00 bitrate=   0.0kbits/s    
    Last message repeated 127 times
Error while decoding stream #1:0      0kB time=10000000000.00 bitrate=   0.0kbits/s    
    Last message repeated 127 times
Error while decoding stream #1:0      0kB time=10000000000.00 bitrate=   0.0kbits/s    
    Last message repeated 136 times
Error while decoding stream #1:0      0kB time=10000000000.00 bitrate=   0.0kbits/s    
    Last message repeated 26 times
frame= 4126 fps=224 q=29.0 Lsize=    3714kB time=137.57 bitrate= 221.1kbits/s    
video:240kB audio:3362kB other streams:0kB global headers:0kB muxing overhead: 3.110874%
[libx264 @ 0x236b1e0] frame I:17    Avg QP:15.26  size:  6537
[libx264 @ 0x236b1e0] frame P:1040  Avg QP:10.32  size:    40
[libx264 @ 0x236b1e0] frame B:3069  Avg QP:13.67  size:    30
[libx264 @ 0x236b1e0] consecutive B-frames:  0.8%  0.0%  0.0% 99.2%
[libx264 @ 0x236b1e0] mb I  I16..4: 60.3% 32.6%  7.1%
[libx264 @ 0x236b1e0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
[libx264 @ 0x236b1e0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.1%  0.0%  0.0%  direct: 0.0%  skip:99.9%  L0:52.2% L1:47.8% BI: 0.0%
[libx264 @ 0x236b1e0] 8x8 transform intra:32.4% inter:0.0%
[libx264 @ 0x236b1e0] coded y,uvDC,uvAC intra: 3.5% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x236b1e0] i16 v,h,dc,p: 55% 39%  5%  0%
[libx264 @ 0x236b1e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13%  3% 83%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x236b1e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 29% 28%  1%  1%  2%  1%  2%  2%
[libx264 @ 0x236b1e0] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x236b1e0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x236b1e0] ref P L0: 80.6%  0.2% 19.2%
[libx264 @ 0x236b1e0] ref B L0: 35.1% 64.9%
[libx264 @ 0x236b1e0] kb/s:14.24

I tried this with GIF files, and it worked well, except that GIF doesn't handle transparency nearly as well as PNG, making the overlay ugly.

A sample of the PNG files I'm trying to overlay can be found at http://engineering.mercuryanalytics.com/~scottb/frame0000.png

Here's the output from a similar ffmpeg command: The output above was from avconv... here's what ffmpeg has to say...

$ ffmpeg -y -i /var/www/assets/video/epic_trailer_e_1080p_1024w_2249-1.mp4 -f image2 -r 4 -i images/frame%04d.png -vf 'pad=iw+120:ih+60:60:30:white,overlay=0:0' final.mp4
ffmpeg version 0.8.12, Copyright (c) 2000-2011 the FFmpeg developers
  built on Jun 13 2012 09:57:38 with gcc 4.6.3 20120306 (Red Hat 4.6.3-2)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --enable-bzlib --enable-libcelt --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  8. 0 / 53.  8. 0
  libavformat  53.  5. 0 / 53.  5. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/assets/video/epic_trailer_e_1080p_1024w_2249-1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: mp41
    creation_time   : 2013-10-11 06:00:10
  Duration: 00:02:17.67, start: 0.000000, bitrate: 2651 kb/s
    Stream #0.0(eng): Video: h264 (Constrained Baseline), yuv420p, 1024x430, 2519 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 1947-10-11 06:00:10
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 1947-10-11 06:00:10
[image2 @ 0x15c5460] max_analyze_duration 5000000 reached at 5000000
Input #1, image2, from 'images/frame%04d.png':
  Duration: 00:02:18.00, start: 0.000000, bitrate: N/A
    Stream #1.0: Video: png, 1144x490, 4 fps, 4 tbr, 4 tbn, 4 tbc
[buffer @ 0x15bd700] Invalid pixel format string '-1'
Error opening filters!

EDIT: Since I wanted the code to work with either ffmpeg or avconv, and since the problem occurred with both, I was treating them as more or less equivalent.

I downloaded the latest static build of ffmpeg and it seems to be more or less working, though the resulting composite video is pretty ugly -- as if it's still not really interpreting the PNG files correctly.

The command line I'm using is: ffmpeg -y -i epic.mp4 -loglevel panic -r 4 -f image2 -i frame%04d.png -filter_complex 'pad=iw+120:ih+60:60:30:white,overlay=0:0' 1202_epic.mp4

The input files and resulting mp4 can be seen at, e.g. http://engineering.mercuryanalytics.com/~scottb/epic/epic.zip

In that same path, the original files (non-zipped) can be found -- I can't post links because not enough rep, but replace "epic.zip" with, e.g., frame0000.png, epic.mp4, or 1202_epic.mp4.

The quality of the overlay is just horrible.

  • @LordNeckbeard -- you edited this to take out the ffmpeg references, and to remove the avconv and ffmpeg tags but offer no explanation. That makes it far less likely someone will provide a real answer by reducing the audience, and to do that without even giving your reasoning is kind of lame. BTW... FFmpeg has basically the same problem, just slightly different errors. I'll update the question with ffmpeg's output. – scottb Dec 4 '14 at 22:14
  • The ffmpeg tag is for FFmpeg. The libav tag is for Libav (but could possibly be confused for FFmpeg/Libav libav* libraries such as libavcodec, libavformat, etc). These are separate projects and I don't like to see their tags get muddled, but now that you added ffmpeg from FFmpeg info I'll re-introduce the tag. Could you test a current version of ffmpeg? Yours is an antique. Downloading a static build will probably be the easiest method. – llogan Dec 4 '14 at 23:59
  • Is it possible that ffmpeg is treating the alpha values in the PNG image incorrectly? The alpha value is supposed to indicate "opacity", with small values meaning transparent and large values meaning opaque. The PNG currently uses an alpha of 0.3, but if I change it to 0.7 and redo the overlay, it becomes more transparent. – scottb Dec 10 '14 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.