gpt4 book ai didi

ffmpeg - 如何在没有音频同步问题的情况下使用 FFMPEG 连接多个 MP4 视频?

转载 作者:行者123 更新时间:2023-12-04 23:12:27 26 4
gpt4 key购买 nike

我的程序如下:

  • 以 60 FPS 将视频转换为 1920x1080(某些视频只有 30 FPS)
  • 将转换后的视频保存在文本文件中
  • 通过 FFMPEG concat
  • 合并视频

    视频合并后,音频与视频不同步。
    要转换视频,我使用以下命令: ffmpeg -i input.mp4 -vf scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1 -r 60 output.mp4(从这里得到它: How can I upscale videos with FFmpeg to a fixed resolution?)
    我用来连接视频的 FFMPEG 命令: ffmpeg -f concat -safe 0 -i videolist.txt -c copy final.mp4当我连接视频时,有时会收到很多这样的警告:
    [mp4 @ 0x55740b62ad40] Non-monotonous DTS in output stream 0:1; previous: 336921, current: 336064; changing to 336922. This may result in incorrect timestamps in the output file.
    FFMPEG 专业人士的问题,如何确保视频和音频同步?

    更新:
    以下是 videolist.txt 中列出的文件的详细信息
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'intro.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:07.04, start: 0.000000, bitrate: 291 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 187 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 91 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '4t6Brqa4E5BnD6vC5inICusEtPtd3nU88NgbmUJ.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:37.66, start: 0.000000, bitrate: 1608 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1532 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'cut.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:00.65, start: 0.000000, bitrate: 7128 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 7576 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 115 kb/s (default)
    Metadata:
    handler_name : IsoMedia File Produced by Google, 5-11-2011
    Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '80SEh7RoTyVPNj3zTZSaixxATvUYXMNyzu15evs.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:07.75, start: 0.000000, bitrate: 1191 kb/s
    Stream #3:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1106 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #3:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 70 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'outro.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:15.17, start: 0.000000, bitrate: 3417 kb/s
    Stream #4:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3286 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #4:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
    handler_name : SoundHandler

    最佳答案

    所有属性必须相同,但您的音频具有不同的 channel 布局(立体声和单声道)和采样率(48000 和 44100)。
    添加 -ar 48000 -ac 2到你的命令:

    ffmpeg -i input.mp4 -vf scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1 -r 60 -ar 48000 -ac 2 output.mp4
    或者,如果您想避免任何临时文件,您可以使用 concat 过滤器在一个命令中完成所有操作,如 How to concatenate videos in ffmpeg with different attributes? 所示。 .

    关于ffmpeg - 如何在没有音频同步问题的情况下使用 FFMPEG 连接多个 MP4 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63233947/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com