问题遇到的现象和发生背景
使用FFmpeg 合并多个视频,并添加音频,图片和水印文字
遇到的问题的是问题,我input了5个视频,但是只合成功了4个视频, 第5个视频,只有部分音频插入进来了 而且视频和音频不同步了
用代码块功能插入代码,请勿粘贴截图
ffmpeg -stats -benchmark -y \
-ss 00:00:00 -t 5 -i in/4.mp4 \
-ss 00:00:00 -t 5 -i in/5.mp4 \
-ss 00:00:00 -t 5 -i in/6.mp4 \
-ss 00:00:15 -t 5 -i in/7.mp4 \
-ss 00:00:00 -t 5 -i in/8.mp4 \
-i in/img1.png \
-i in/para.mp3 \
-filter_complex \
"[0]scale=w=720:h=480:force_original_aspect_ratio=1,fps=24,pad=720:480:(ow-iw)/2:(oh-ih)/2:red,setsar=1:1,settb=AVTB[0:v];
[1]scale=w=720:h=480:force_original_aspect_ratio=1,fps=24,pad=720:480:(ow-iw)/2:(oh-ih)/2:blue,setsar=1:1,settb=AVTB[1:v];
[2]scale=w=720:h=480:force_original_aspect_ratio=1,fps=24,pad=720:480:(ow-iw)/2:(oh-ih)/2:pink,setsar=1:1,settb=AVTB[2:v];
[3]scale=w=720:h=480:force_original_aspect_ratio=1,fps=24,pad=720:480:(ow-iw)/2:(oh-ih)/2:green,setsar=1:1,settb=AVTB[3:v];
[4]scale=w=720:h=480:force_original_aspect_ratio=1,fps=24,pad=720:480:(ow-iw)/2:(oh-ih)/2:white,setsar=1:1,settb=AVTB[4:v];
[0:v][1:v]xfade=transition=fade:duration=0.500000:offset=2.500000[v01];
[v01][2:v]xfade=transition=fade:duration=0.500000:offset=5.500000[v12];
[v12][3:v]xfade=transition=fade:duration=0.500000:offset=8.500000[v23];
[v23][4:v]xfade=transition=fade:duration=0.500000:offset=11.500000,format=yuv420p[video];
[0:a][1:a]acrossfade=d=0.000000[a01];
[a01][2:a]acrossfade=d=0.000000[a12];
[a12][3:a]acrossfade=d=0.000000[a23];
[a23][4:a]acrossfade=d=0.000000[audio];
[video][5:v]overlay=0:100:enable='between(t,2,4)',drawtext=text='hello world':x=40:y=360:enable='between(t,3,5)':fontsize=24:fontcolor=purple[outv];
[audio][6:a]amix=duration=first[outa]" \
-preset:v veryfast -level 3.1 -x264opts crf=14 -vsync cfr \
-c:v libx264 -r 24 -b:v 1000k -maxrate 2000k -bufsize 1M \
-b:a 96K -c:a aac \
-map [outv] -map [outa] out/out10.mp4
运行结果及报错内容
ffmpeg version 5.1.1-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2022 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 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
-vsync is deprecated. Use -fps_mode
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x6e1b6c0] overread end of atom 'colr' by 1 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in/4.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
copyright :
copyright-eng :
Duration: 00:00:08.97, start: 0.000000, bitrate: 1567 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 960x544, 1512 kb/s, 30 fps, 30 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 47 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'in/5.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: isommp41mp42
creation_time : 2022-09-21T06:36:46.000000Z
copyright :
copyright-eng :
Duration: 00:02:09.04, start: 0.000000, bitrate: 706 kb/s
Stream #1:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 960x544, 654 kb/s, 25 fps, 25 tbr, 600 tbn (default)
Metadata:
creation_time : 2022-09-21T06:36:46.000000Z
handler_name : Core Media Video
vendor_id : [0][0][0][0]
Stream #1:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 48 kb/s (default)
Metadata:
creation_time : 2022-09-21T06:36:46.000000Z
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'in/6.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: isommp41mp42
creation_time : 2022-09-21T06:52:29.000000Z
copyright :
copyright-eng :
Duration: 00:03:34.20, start: 0.000000, bitrate: 843 kb/s
Stream #2:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 960x544, 790 kb/s, 30 fps, 30 tbr, 600 tbn (default)
Metadata:
creation_time : 2022-09-21T06:52:29.000000Z
handler_name : Core Media Video
vendor_id : [0][0][0][0]
Stream #2:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 47 kb/s (default)
Metadata:
creation_time : 2022-09-21T06:52:29.000000Z
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'in/7.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.16.100
Duration: 00:00:19.49, start: 0.000000, bitrate: 824 kb/s
Stream #3:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1280x720, 787 kb/s, 29.83 fps, 30 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #3:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 31 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'in/8.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: isommp41mp42
creation_time : 2022-09-28T02:40:03.000000Z
copyright :
copyright-eng :
Duration: 00:02:46.70, start: 0.000000, bitrate: 829 kb/s
Stream #4:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 960x544, 776 kb/s, 30 fps, 30 tbr, 600 tbn (default)
Metadata:
creation_time : 2022-09-28T02:40:03.000000Z
handler_name : Core Media Video
vendor_id : [0][0][0][0]
Stream #4:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 48 kb/s (default)
Metadata:
creation_time : 2022-09-28T02:40:03.000000Z
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
Input #5, png_pipe, from 'in/img1.png':
Duration: N/A, bitrate: N/A
Stream #5:0: Video: png, rgba(pc), 345x297 [SAR 3779:3779 DAR 115:99], 25 fps, 25 tbr, 25 tbn
Input #6, mp3, from 'in/para.mp3':
Metadata:
encoder : Lavf58.29.100
Duration: 00:01:56.27, start: 0.050113, bitrate: 63 kb/s
Stream #6:0: Audio: mp3, 22050 Hz, stereo, fltp, 63 kb/s
[Parsed_drawtext_35 @ 0x70e6580] Using "/usr/share/fonts/aajohan-comfortaa/Comfortaa-Regular.ttf"
Stream mapping:
Stream #0:0 (h264) -> scale:default
Stream #0:1 (aac) -> acrossfade
Stream #1:0 (h264) -> scale:default
Stream #1:1 (aac) -> acrossfade
Stream #2:0 (h264) -> scale:default
Stream #2:1 (aac) -> acrossfade
Stream #3:0 (h264) -> scale:default
Stream #3:1 (aac) -> acrossfade
Stream #4:0 (h264) -> scale:default
Stream #4:1 (aac) -> acrossfade
Stream #5:0 (png) -> overlay
Stream #6:0 (mp3float) -> amix
drawtext:default -> Stream #0:0 (libx264)
amix:default -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[Parsed_drawtext_35 @ 0x7429400] Using "/usr/share/fonts/aajohan-comfortaa/Comfortaa-Regular.ttf"
[libx264 @ 0x70e2c40] using SAR=1/1
[libx264 @ 0x70e2c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 0x70e2c40] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x70e2c40] 264 - core 164 r3098 7628a56 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=1 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=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=14.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=2000 vbv_bufsize=1000 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out/out10.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
copyright-eng :
copyright :
encoder : Lavf59.27.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 720x480 [SAR 1:1 DAR 3:2], q=2-31, 1000 kb/s, 24 fps, 12288 tbn
Metadata:
encoder : Lavc59.37.100 libx264
Side data:
cpb: bitrate max/min/avg: 2000000/0/1000000 buffer size: 1000000 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 96 kb/s
Metadata:
encoder : Lavc59.37.100 aac
frame= 396 fps= 51 q=19.0 Lsize= 4162kB time=00:00:16.43 bitrate=2073.9kbits/s speed=2.12x
video:3951kB audio:200kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.265645%
bench: utime=7.448s stime=0.187s rtime=7.771s
bench: maxrss=345048kB
[libx264 @ 0x70e2c40] frame I:5 Avg QP:10.19 size: 36453
[libx264 @ 0x70e2c40] frame P:127 Avg QP:15.63 size: 16787
[libx264 @ 0x70e2c40] frame B:264 Avg QP:17.73 size: 6555
[libx264 @ 0x70e2c40] consecutive B-frames: 6.3% 11.1% 9.8% 72.7%
[libx264 @ 0x70e2c40] mb I I16..4: 31.4% 15.6% 53.0%
[libx264 @ 0x70e2c40] mb P I16..4: 10.4% 15.4% 16.5% P16..4: 15.5% 12.8% 10.8% 0.0% 0.0% skip:18.6%
[libx264 @ 0x70e2c40] mb B I16..4: 2.8% 5.2% 3.1% B16..8: 18.8% 14.3% 4.2% direct:11.1% skip:40.5% L0:35.1% L1:41.5% BI:23.4%
[libx264 @ 0x70e2c40] 8x8 transform intra:38.7% inter:18.4%
[libx264 @ 0x70e2c40] coded y,uvDC,uvAC intra: 63.6% 67.1% 45.0% inter: 21.5% 22.5% 4.1%
[libx264 @ 0x70e2c40] i16 v,h,dc,p: 40% 42% 13% 6%
[libx264 @ 0x70e2c40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 29% 12% 4% 5% 6% 5% 5% 4%
[libx264 @ 0x70e2c40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 25% 11% 5% 7% 7% 6% 6% 4%
[libx264 @ 0x70e2c40] i8c dc,h,v,p: 43% 30% 21% 6%
[libx264 @ 0x70e2c40] Weighted P-Frames: Y:11.8% UV:11.0%
[libx264 @ 0x70e2c40] kb/s:1961.04
[aac @ 0x70e3640] Qavg: 1230.148
我想要达到的结果
想到的结果就是 5个视频顺序合并,并且视频和音频同步