存在一个问题,即叠加视频的最后一帧会保留在输出视频中,直到完整视频完成。完整视频为 10 秒,叠加视频为 5 秒。叠加从视频开头开始。
例子:
myoverlay.mov
是 5 秒myvideo.mp4
是10秒
最终视频( )显示视频剩余 5 秒内“卡住”outputvideo.mp4
的最后一帧。myoverlay.mov
期望:当覆盖完成时,应该消失,并且视频的剩余 5 秒将继续,而不会看到覆盖的任何内容。
使用的命令:
ffmpeg -y -i myvideo.mp4 -r 30 -itsoffset 00:00:00.000 -i myoverlay.mov \
-filter_complex [1:v]scale=640:360[ovrl], [0:v][ovrl]overlay=0:0[outv]; \
[0:a][1:a]amix[outa] -map [outv] -map [outa] -c:v libx264 -vcodec mpeg4 \
-r 30 -strict experimental -b:v 1500000 outputvideo.mp4
完整输出:
ffmpeg version N-70223-g7296716 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
libavutil 54. 19.100 / 54. 19.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 23.105 / 56. 23.105
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.101 / 5. 11.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'basevideo.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
creation_time : 2015-07-13 21:32:46
encoder : Lavf53.21.1
Duration: 00:00:45.10, start: 0.000000, bitrate: 2436 kb/s
Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2234 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
Metadata:
creation_time : 2015-07-13 21:32:46
handler_name : DataHandler
encoder : mpeg4
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 199 kb/s (default)
Metadata:
creation_time : 2015-07-13 21:32:46
handler_name : DataHandler
Guessed Channel Layout for Input Stream #1.1 : mono Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'overlayvideo.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2015-03-29 22:27:01
Duration: 00:00:08.00, start: 0.000000, bitrate: 85613 kb/s
Stream #1:0(eng): Video: png (png / 0x20676E70), rgba, 640x360 [SAR 2834:2834 DAR 16:9], 84889 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc (default)
Metadata:
creation_time : 2015-03-29 22:27:01
handler_name : Apple Alias Data Handler
encoder : PNG
timecode : 00:00:00:00
Stream #1:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 44100 Hz, 1 channels, s16, 705 kb/s (default)
Metadata:
creation_time : 2015-03-29 22:27:01
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
Stream #1:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
creation_time : 2015-03-29 22:27:39
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
Output #0, mp4, to 'finalvideo.mp4':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf56.23.105
Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1500 kb/s, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
encoder : Lavc56.26.100 mpeg4
Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 128 kb/s (default)
Metadata:
encoder : Lavc56.26.100 libvo_aacenc
Stream mapping:
Stream #0:0 (mpeg4) -> overlay:main
Stream #0:1 (aac) -> amix:input0
Stream #1:0 (png) -> scale
Stream #1:1 (pcm_s16le) -> amix:input1
overlay -> Stream #0:0 (mpeg4)
amix -> Stream #0:1 (libvo_aacenc)
Press [q] to stop, [?] for help
frame= 1351 fps=108 q=24.8 Lsize= 15213kB time=00:00:45.10 bitrate=2762.7kbits/s dup=1 drop=0
video:14467kB audio:705kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.261860%
答案1
已修复。需要使用覆盖=eof_action=通过代替覆盖=0:0
更新后的命令有效:
ffmpeg -y -i myvideo.mp4 -r 30 -itsoffset 00:00:00.000 -i myoverlay.mov -filter_complex "[1:v]scale=640:360[ovrl], [0:v][ovrl]overlay=eof_action=pass[outv];[0:a][1:a]amix[outa]" -map [outv] -map [outa] -c:v libx264 -vcodec mpeg4 -r 30 -strict experimental -b:v 1500000 outputvideo.mp4