[英]Convert videos in ffmpeg filter_complex with different timebases to use xfade
I'd like to use ffmpeg's new xfade filter to crossfade between two videos.我想使用 ffmpeg 的新xfade过滤器在两个视频之间交叉淡入淡出。 In theory this is easy:理论上这很容易:
ffmpeg -i v1.mp4 -i v2.mp4 \
-filter_complex "[0][1]xfade=duration=1:offset=5,format=yuv420p" \
out.mp4
However, this fails with the error:但是,这失败并出现错误:
First input link main timebase (1/1500) do not match the corresponding second input link xfade timebase (1/30000)
Obviously these two videos do have different timebases.显然,这两个视频确实有不同的时基。 This is confirmed by the ffmpeg output: ffmpeg output 证实了这一点:
Stream #0:0(eng): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1280x720 [SAR 1:1 DAR 16:9], 536 kb/s, 15 fps, 15 tbr, 1500 tbn, 30 tbc (default)
...
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/bt709), 1280x720 [SAR 1:1 DAR 16:9], 1117 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
I don't want to convert each video and save the results and then combine the two new temporary disk files.我不想转换每个视频并保存结果,然后合并两个新的临时磁盘文件。 Is it possible to use -filter_complex
to convert the videos before xfade
so that they have the same timebase?是否可以在-filter_complex
之前使用 -filter_complex 转换视频, xfade
使它们具有相同的时基? So that I can run one command which takes any two videos and crossfades between them?这样我就可以运行一个命令来获取任意两个视频并在它们之间进行淡入淡出吗?
Attempting to set the timebase explicitly with the settb
filter seems to work at first but then gets "stuck" on frame 3 and never makes any more progress:尝试使用settb
过滤器显式设置时基一开始似乎可行,但随后“卡住”在第 3 帧上,再也没有取得任何进展:
$ ffmpeg -i v1.mp4 -i v2.mp4 -filter_complex "[0]settb=1/AVTB[v0];[1]settb=1/AVTB[v1];[v0][v1]xfade=duration=1:offset=5,format=yuv420p" out.mp4
ffmpeg version N-53546-g5eb4405fc5-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 56.100 / 56. 56.100
libavcodec 58. 97.100 / 58. 97.100
libavformat 58. 49.100 / 58. 49.100
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'v1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomiso2
creation_time : 2014-08-20T20:47:56.000000Z
encoder : x264
Duration: 00:00:12.67, start: 0.000000, bitrate: 538 kb/s
Stream #0:0(eng): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1280x720 [SAR 1:1 DAR 16:9], 536 kb/s, 15 fps, 15 tbr, 1500 tbn, 30 tbc (default)
Metadata:
creation_time : 2014-08-20T20:47:56.000000Z
handler_name : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'v2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 00:00:04.31, start: 0.000000, bitrate: 1286 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/bt709), 1280x720 [SAR 1:1 DAR 16:9], 1117 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
Metadata:
handler_name : SoundHandler
File 'out.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 (h264) -> settb (graph 0)
Stream #1:0 (h264) -> settb (graph 0)
format (graph 0) -> Stream #0:0 (libx264)
Stream #1:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x69aaac0] using SAR=1/1
[libx264 @ 0x69aaac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x69aaac0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x69aaac0] 264 - core 161 r3018 db0d417 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - 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=6 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=15 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 'out.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomiso2
encoder : Lavf58.49.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 15 fps, 15360 tbn, 15 tbc (default)
Metadata:
encoder : Lavc58.97.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.97.100 aac
frame= 3 fps=0.0 q=0.0 size= 0kB time=00:00:02.94 bitrate= 0.1kbits/s
frame= 3 fps=3.0 q=0.0 size= 0kB time=00:00:04.24 bitrate= 0.1kbits/s
frame= 3 fps=2.0 q=0.0 size= 0kB time=00:00:04.24 bitrate= 0.1kbits/s
frame= 3 fps=1.5 q=0.0 size= 0kB time=00:00:04.24 bitrate= 0.1kbits/s
(and repeat this line forever)
You can use the settb filter to set a common TB.您可以使用 settb 过滤器来设置一个普通的 TB。
ffmpeg -i v1.mp4 -i v2.mp4 \
-filter_complex "[0]settb=AVTB[v0];[1]settb=AVTB[v1];\
[v0][v1]xfade=duration=1:offset=5,format=yuv420p" \
out.mp4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.