Ffmpeg命令通过循环向视频添加较短的音频

时间:2017-10-03 10:49:13

标签: ffmpeg

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

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

2 个答案:

答案 0 :(得分: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是错误的。请改用电影过滤器,它有一个循环选项。

答案 1 :(得分:-1)

使用代码

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