【问题标题】:Ffmpeg command to add shorter audio to video with loopFfmpeg 命令通过循环向视频添加更短的音频
【发布时间】:2018-04-06 00:19:33
【问题描述】:

Ffmpeg 命令通过循环将较短的音频添加到视频中

我正在使用此命令向视频添加音频,音频长 18 秒,视频长 3 分 29 秒,此命令添加音频但仅在前 18 秒,然后停止

"-y","-stream_loop","-1","-i", audio,"-i",j, "-filter_complex",
                        "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];" +
                        "[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" +
                        " [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
                        "-map","1:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", out

我们如何在循环中添加音频并将其添加到视频中

编辑

对于时间问题,我做了以下更改

"-y","-i",video,"-filter_complex","amovie="+audio+":loop=999,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];" +[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" +"[a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
"-t", timetoedit,
"-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", out 

如果我们想在整个视频中添加音频,这很有效

现在,当我们尝试添加在特定时间开始并持续特定持续时间的音频时,它会失败 这里有两件事, 1) 创建一个包含特定持续时间的音频和视频的新剪辑 此命令不起作用

"-y","-i",video,,"ss",starttime,"-t", timetoedit,"-filter_complex","amovie="+audio+":loop=999,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];" +[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" +"[a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
"-ss", starttime,"-t", timetoedit,
"-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", out 

或者如果我们只想在特定时间添加音频

喜欢

"-y","-i",video,"-filter_complex","amovie="+audio+":loop=999,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];" +[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" +"[a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
    "-ss", starttime,"-t", timetoedit,
    "-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", out 

如何做到这一点

这很有用 https://superuser.com/questions/708125/add-audio-at-specific-time-in-video-using-ffmpeg

但是我们如何在特定的开始时间和持续时间内使用它

【问题讨论】:

    标签: ffmpeg


    【解决方案1】:

    使用

    "-y","-i",j, "-filter_complex",
                            "amovie=audio:loop=999,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];" +
                            "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" +
                            " [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]",
                            "-map","0:v","-map","[out]","-c:v","copy","-c:a","aac","-shortest","-preset", "ultrafast", out
    

    -stream_loop 有问题。改用电影滤镜,它有一个循环选项。

    【讨论】:

    • 这确实有效,但视频时长为 3 分 29 秒,它仅在 2 分 30 秒后才添加音频
    • 最后 45 秒没有添加音频,不知道是什么问题
    • 我在创建图像文件的视频时使用了类似 -t 100 的循环命令,我们如何使用类似的命令来获得音频和视频的确切持续时间
    • "-filter_complex","amovie="+audio+":loop=999,asetpts=N/SR/TB,aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5 [a1];" + "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];" + " [a1][a2]amerge,pan=stereo:c0
    • 我在最后添加了视频时间,可能对其他人有帮助,更多测试虽然稍后会确认,感谢您的帮助 Mulvya
    【解决方案2】:

    使用代码

    ./ffmpeg -i long.mp3 -filter_complex "amovie=background_music.mp3:loop=999[s];[0][s]amix=duration=shortest" test.mp3
    

    【讨论】:

    • 虽然此代码可能会解决问题,但您应该添加说明为什么提问者应该使用此代码以及它究竟实现了什么。
    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 2016-04-11
    • 2021-03-10
    • 1970-01-01
    相关资源
    最近更新 更多