问题
I am trying to overlay a video with another video. I followed the original command OP posted here. And it works, but it overlays the video from time 0:
ffmpeg -i 720480.mp4 -i sdbug.mov -filter_complex "[0:0][1:0]overlay[out]" -shortest -map [out] -map 0:1 -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18 new.mp4
I tried the correct answer to specify a time, but it is not working for me: 1) the overlay starts at around second 12
, and 2) video is not played after the overlay is finished.
ffmpeg -i 720480.mp4 -i sdbug.mov -filter_complex "[1:v]setpts=PTS+10/TB[a]; [0:v][a]overlay=enable=gte(t\,5):shortest=1[out]" -map [out] -map 0:a -c:v libx264 -crf 18 -pix_fmt yuv420p -c:a copy new.mp4
Anything changed recently on FFmpeg
?! Why isn't it working?
Here is the output of this command (it finishes very fast):
ffmpeg version N-92906-g54109b1d14 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181201
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 43.100 / 58. 43.100
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 46.101 / 7. 46.101
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '720480.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2018-07-26T09:23:16.000000Z
Duration: 00:01:50.17, start: 0.000000, bitrate: 3181 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 720x480 [SAR 8:9 DAR 4:3], 2785 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : VideoHandler
timecode : 00:59:55:12
Stream #0:1: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:2: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:3: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:4: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:5: Data: none (tmcd / 0x64636D74) (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : TimecodeMediaHandler
timecode : 00:59:55:12
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'sdbug.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2018-08-29T14:50:13.000000Z
Duration: 00:00:10.01, start: 0.000000, bitrate: 10504 kb/s
Stream #1:0(eng): Video: qtrle (rle / 0x20656C72), bgra(progressive), 720x486, 9666 kb/s, SAR 109:120 DAR 109:81, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
Metadata:
creation_time : 2018-08-29T14:50:13.000000Z
handler_name : Apple Video Media Handler
encoder : Animation
timecode : 00:00:00;00
Stream #1:1(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
creation_time : 2018-08-29T14:50:13.000000Z
handler_name : Time Code Media Handler
timecode : 00:00:00;00
Stream mapping:
Stream #0:0 (h264) -> overlay:main
Stream #1:0 (qtrle) -> setpts
overlay -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)
Stream #0:3 -> #0:3 (copy)
Stream #0:4 -> #0:4 (copy)
Press [q] to stop, [?] for help
[libx264 @ 000002b902a3f480] using SAR=8/9
[libx264 @ 000002b902a3f480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000002b902a3f480] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 000002b902a3f480] 264 - core 157 r2935 545de2f - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'new.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.25.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
encoder : Lavc58.43.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:2: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:3: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
Stream #0:4: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 98 kb/s (default)
Metadata:
creation_time : 2018-07-26T09:23:16.000000Z
handler_name : SoundHandler
frame= 599 fps= 92 q=-1.0 Lsize= 11556kB time=00:01:50.01 bitrate= 860.5kbits/s speed=16.8x
video:6173kB audio:5288kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.828358%
[libx264 @ 000002b902a3f480] frame I:8 Avg QP:13.24 size: 44134
[libx264 @ 000002b902a3f480] frame P:174 Avg QP:18.62 size: 20916
[libx264 @ 000002b902a3f480] frame B:417 Avg QP:21.31 size: 5583
[libx264 @ 000002b902a3f480] consecutive B-frames: 6.0% 1.7% 5.5% 86.8%
[libx264 @ 000002b902a3f480] mb I I16..4: 15.9% 58.9% 25.2%
[libx264 @ 000002b902a3f480] mb P I16..4: 1.4% 13.6% 4.2% P16..4: 36.6% 22.8% 12.3% 0.0% 0.0% skip: 9.0%
[libx264 @ 000002b902a3f480] mb B I16..4: 0.1% 0.9% 0.3% B16..8: 46.4% 10.6% 2.9% direct: 5.5% skip:33.3% L0:53.4% L1:36.9% BI: 9.7%
[libx264 @ 000002b902a3f480] 8x8 transform intra:68.5% inter:65.1%
[libx264 @ 000002b902a3f480] coded y,uvDC,uvAC intra: 77.5% 89.5% 77.2% inter: 26.8% 48.1% 10.1%
[libx264 @ 000002b902a3f480] i16 v,h,dc,p: 50% 13% 13% 23%
[libx264 @ 000002b902a3f480] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 12% 17% 6% 8% 10% 7% 9% 7%
[libx264 @ 000002b902a3f480] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 13% 10% 7% 12% 11% 9% 9% 7%
[libx264 @ 000002b902a3f480] i8c dc,h,v,p: 51% 15% 24% 10%
[libx264 @ 000002b902a3f480] Weighted P-Frames: Y:5.2% UV:2.9%
[libx264 @ 000002b902a3f480] ref P L0: 60.1% 19.6% 15.8% 4.4% 0.1%
[libx264 @ 000002b902a3f480] ref B L0: 91.6% 7.3% 1.1%
[libx264 @ 000002b902a3f480] ref B L1: 97.2% 2.8%
[libx264 @ 000002b902a3f480] kb/s:2529.97
回答1:
Change PTS-
to PTS+
. Remove shortest=1
. Add eof_action=pass
:
ffmpeg -i 720480.mp4 -i sdbug.mov -filter_complex "[1:v]setpts=PTS+10/TB[a];[0:v][a]overlay=enable=gte(t\,10):eof_action=pass,format=yuv420p[out]" -map "[out]" -map 0:a? -c:v libx264 -crf 18 -c:a copy new.mp4
See the setpts and overlay filter documentation for more info.
来源:https://stackoverflow.com/questions/54029929/overlay-a-video-on-another-video-at-specific-time-with-ffmpeg