ffmpeg concat 与音频

ffmpeg concat with audio

我有三个视频。第二个视频有音频。其他视频没有音频。我会 运行 代码但视频完全静音

我想把它们结合起来。忽略视频数量。有时这个数字可能非常大。

我可能会尝试另一个视频扩展。如果你能帮上一点忙,我会很高兴。

os.system("ffmpeg -f concat -i {f_list} -c copy a.mp4 -y".format(f_list=r"liste.txt"))

ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000025914e24540] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'C:\Users\User\PycharmProjects\YoutubeCCPanel\helper/../static/videos/V758npfi-w4/liste.txt':
  Duration: N/A, start: 0.000000, bitrate: 10155 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 10155 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to 'a.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, q=2-31, 10155 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000025914e24540] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0000025914e1a600] New audio stream 0:1 at pos:170778 and DTS:26.4438s
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000025914e2c480] Auto-inserting h264_mp4toannexb bitstream filter
    Last message repeated 2 times
[concat @ 0000025914e1a600] DTS 1054188 < 1065501 out of order
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065501, current: 1054188; changing to 1065502. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065502, current: 1054700; changing to 1065503. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065503, current: 1055212; changing to 1065504. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065504, current: 1055724; changing to 1065505. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065505, current: 1056236; changing to 1065506. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065506, current: 1056748; changing to 1065507. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065507, current: 1057260; changing to 1065508. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065508, current: 1057772; changing to 1065509. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065509, current: 1058284; changing to 1065510. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065510, current: 1058796; changing to 1065511. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065511, current: 1059308; changing to 1065512. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065512, current: 1059820; changing to 1065513. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065513, current: 1060332; changing to 1065514. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065514, current: 1060844; changing to 1065515. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065515, current: 1061356; changing to 1065516. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065516, current: 1061868; changing to 1065517. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065517, current: 1062380; changing to 1065518. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065518, current: 1062892; changing to 1065519. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065519, current: 1063404; changing to 1065520. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065520, current: 1063916; changing to 1065521. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065521, current: 1064428; changing to 1065522. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065522, current: 1064940; changing to 1065523. This may result in incorrect timestamps in the output file.
[mp4 @ 0000025914eedbc0] Non-monotonous DTS in output stream 0:0; previous: 1065523, current: 1065452; changing to 1065524. This may result in incorrect timestamps in the output file.
frame= 2422 fps=0.0 q=-1.0 Lsize=   94874kB time=00:01:35.06 bitrate=8175.5kbits/s speed= 386x    
video:94862kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.012716%

Process finished with exit code 0

我的档案liste.txt

file part0.mp4
file video_with_audio.mp4
file part1.mp4

video_with_audio 创建

ffmpeg_merge_video_audio("temp.mp4",
                                     "temp.m4a',
                                     "video_with_audio.mp4",
                                     vcodec='libx264',
                                     acodec='aac')

注意:如果我把 liste.txt 改成那个底部。视频有音频

file video_with_audio.mp4
file part0.mp4
file part1.mp4 

如果视频没有声音请添加声音这是我的解决方案

Solition Source

 videos_all= []
 videos_all.append(r"C:\.../no-sound.mp4 -f lavfi -t 0.1 -i anullsrc ")
 videos_all.append(r"C:\.../withaudio.mp4")
 videos_all.append(r"C:\.../no-sound-1.mp4 -f lavfi -t 0.1 -i anullsrc ")
 os.system("ffmpeg -y -i {videos} \
         -filter_complex \"concat=n={video_len}:v=1:a=1 [v] [a]\" \
         -map \"[v]\" -map \"[a]\" {save}".format(video_len=len(videos_all),videos=" -i ".join(videos_all),save="output.mp4"))