我想合并两个视频文件,并在它们之间添加淡入淡出效果(大约一秒钟),但不会淡入黑色或白色或任何颜色 - 它必须是从一个视频到另一个视频的平滑过渡。
我发现这个答案迄今为止最有帮助的 - 这是我的示例(基于该解决方案):
ffmpeg -i e:/ffmpeg/part1.mp4 -i e:/ffmpeg/part2.mp4 -f lavfi -i color=black:s=1920x1080 -filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=10:d=1:alpha=1,setpts=PTS-STARTPTS[va0]; \
[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+10/TB[va1]; \
[2:v]trim=duration=18[over]; \
[over][va0]overlay[over1]; \
[over1][va1]overlay=format=yuv420[outv]" \
-vcodec libx264 -map [outv] e:/ffmpeg/output.mp4
ffmpeg version N-66278-g91459bd Copyright (c) 2000-2014 the FFmpeg developers
built on Sep 14 2014 22:14:38 with gcc 4.8.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzli
b --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-
libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --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 --enab
le-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'e:/ffmpeg/part1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
Duration: 00:00:11.24, start: 0.000000, bitrate: 19916 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9],
19768 kb/s, 29.65 fps, 30 tbr, 30k tbn, 60k tbc (default)
Metadata:
handler_name : VideoHandler
encoder : AVC Coding
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 97 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'e:/ffmpeg/part2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
Duration: 00:00:08.23, start: 0.000000, bitrate: 19795 kb/s
Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9],
19670 kb/s, 29.50 fps, 30 tbr, 30k tbn, 60k tbc (default)
Metadata:
handler_name : VideoHandler
encoder : AVC Coding
Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 97 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #2, lavfi, from 'color=black:s=1920x1080':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #2:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25 tbr,
25 tbn, 25 tbc
[libx264 @ 0000000004330980] using SAR=1/1
[libx264 @ 0000000004330980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0000000004330980] profile High, level 4.0
[libx264 @ 0000000004330980] 264 - core 142 r2479 dd79a61 - H.264/MPEG-4 AVC codec - Copyleft 2003-2
014 - 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 dead
zone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 deci
mate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 dir
ect=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahe
ad=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 'e:/ffmpeg/output.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
encoder : Lavf56.4.101
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:
9], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
encoder : Lavc56.1.100 libx264
Stream mapping:
Stream #0:0 (h264) -> format
Stream #1:0 (h264) -> format
Stream #2:0 (rawvideo) -> trim
overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame= 451 fps=4.5 q=-1.0 Lsize= 11032kB time=00:00:17.96 bitrate=5031.9kbits/s dup=0 drop=7
video:11028kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.036493%
[libx264 @ 0000000004330980] frame I:11 Avg QP:20.72 size: 63930
[libx264 @ 0000000004330980] frame P:368 Avg QP:23.84 size: 26880
[libx264 @ 0000000004330980] frame B:72 Avg QP:25.29 size: 9679
[libx264 @ 0000000004330980] consecutive B-frames: 69.0% 28.8% 1.3% 0.9%
[libx264 @ 0000000004330980] mb I I16..4: 16.7% 70.0% 13.3%
[libx264 @ 0000000004330980] mb P I16..4: 4.6% 10.7% 0.5% P16..4: 56.9% 7.8% 5.4% 0.0% 0.0%
skip:14.2%
[libx264 @ 0000000004330980] mb B I16..4: 0.2% 0.4% 0.0% B16..8: 42.9% 1.8% 0.2% direct: 3.3
% skip:51.3% L0:39.3% L1:59.7% BI: 0.9%
[libx264 @ 0000000004330980] 8x8 transform intra:68.1% inter:89.7%
[libx264 @ 0000000004330980] coded y,uvDC,uvAC intra: 43.7% 66.3% 4.2% inter: 21.4% 52.4% 0.0%
[libx264 @ 0000000004330980] i16 v,h,dc,p: 38% 17% 10% 35%
[libx264 @ 0000000004330980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 16% 28% 4% 5% 5% 5% 5% 4%
[libx264 @ 0000000004330980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 23% 15% 4% 6% 5% 5% 4% 3%
[libx264 @ 0000000004330980] i8c dc,h,v,p: 51% 18% 25% 6%
[libx264 @ 0000000004330980] Weighted P-Frames: Y:3.5% UV:2.7%
[libx264 @ 0000000004330980] ref P L0: 76.4% 9.8% 10.4% 3.3% 0.1%
[libx264 @ 0000000004330980] ref B L0: 91.4% 8.5% 0.0%
[libx264 @ 0000000004330980] ref B L1: 99.6% 0.4%
[libx264 @ 0000000004330980] kb/s:5007.46
问题是输出视频中没有声音。
我正在寻找一种可以合并两个视频而不删除音频的方法。我最终可以使用其他软件(例如 Audacity)单独合并音频,但如果有办法在 FFmpeg 中完成所有这些操作,那么我想知道。
抱歉,这个问题问得有点无聊,但我对视频滤镜或视频编码一点都不熟悉。我只是发现 FFmpeg 最适合我(通常我只用它来进行文件转换),我尝试使用过渡效果合并两个视频,但我找到的解决方案都没有奏效。
答案1
对于音频交叉淡入淡出,您可以使用类似这样的方法。
ffmpeg -i input_video_1 -i input_video_2 -filter_complex "
[0:a]afade=t=out:st=9:d=2[a0];
[1:a]afade=t=in:st=0:d=2[a1];
aevalsrc=0:d=9[s1];
[s1][a1]concat=n=2:v=0:a=1[ac1];
[a0][ac1]amix[a]" -map [a] -c:a libfdk_aac -ac 2 -b:a 128k output_audio
此处将淡入淡出两个视频文件中的音频并输出一个音频文件。我在第二个视频的开头附加了一个与第一个音频的持续时间相同的静音持续时间,并在结尾处混合两者。这样,您可以避免混合时音频重叠。