我正在尝试使用avconv
将数据叠加到视频上。我生成了表示 4fps 叠加数据的 PNG 文件。PNG 文件比原始视频宽 120px,高 60px,因为边框中添加了信息——每边 60px,顶部和底部 30px。
这是avconv
我正在运行的命令:
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
输出如下:
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
我尝试用 GIF 文件进行此操作,并且效果很好,但 GIF 处理透明度的效果不如 PNG,导致覆盖层不好看。
我尝试叠加的 PNG 文件示例可在以下位置找到:http://engineering.mercuryanalytics.com/~scottb/frame0000.png
以下是类似 ffmpeg 命令的输出: 上面的输出来自 avconv...以下是 ffmpeg 所说的内容...
$ 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!
编辑:因为我希望代码能够与 ffmpeg 或 avconv 一起工作,而且这两者都存在问题,所以我将它们视为或多或少等效的。
我下载了最新的静态版本的 ffmpeg,它似乎或多或少可以工作,尽管生成的复合视频相当丑陋——好像它仍然不能真正正确地解释 PNG 文件。
我使用的命令行是: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
输入文件和生成的 mp4 可以在以下位置查看:http://engineering.mercuryanalytics.com/~scottb/epic/epic.zip
在同一路径中,可以找到原始文件(非压缩文件)——我无法发布链接,因为代表数量不够,但可以将“epic.zip”替换为例如 frame0000.png、epic.mp4 或 1202_epic.mp4。
覆盖的质量实在太差了。