简体   繁体   English

ffmpeg 2个音频文件在一个视频文件中

[英]ffmpeg 2 audio files in one video file

lets say I have a video file (video.mp4) and 2 audio files (audio1.mp3 and audio2.mp3.) The video has a length of 60 seconds, every audio file has a length of 30 seconds. 可以说我有一个视频文件(video.mp4)和两个音频文件(audio1.mp3和audio2.mp3。)视频的长度为60秒,每个音频文件的长度为30秒。

What I am trying to achive is: the first 20 seconds of the video is with original audio stream, followed by 20 seconds of the first audio file (offset of 5 seconds with a length of 20s) and the same with the second audio file. 我要达到的目标是:视频的前20秒是原始音频流,然后是第一个音频文件的20秒(偏移量为5秒,长度为20s),而第二个音频文件是相同的。

ffmpeg -i video.mp4 -ss 5 -t 20 -i audio1.mp3 -ss 5 -t 20 -i audio2.mp3 -vcodec copy -acodec copy  -copyinkf -map 0:v:0 -map 1:a:0 -map 2:a:0 -shortest final.mp4

The command above takes the video stream of the first input and the audio stream of the third input. 上面的命令获取第一输入的视频流和第三输入的音频流。 The audio stream of the second input seems to be overwritten. 第二个输入的音频流似乎已被覆盖。 How can I put all audio streams together and how can I define the offset when the audio streams should begin? 如何将所有音频流放在一起,如何定义音频流开始时的偏移量?

I assume that you want the combined audio programme in one stream. 我假设您要在一个流中合并音频程序。 Even if you applied timestamp offsets to the other audios, most players won't switch audio streams mid-playback. 即使您将时间戳偏移量应用于其他音频,大多数播放器也不会在播放中切换音频流。

So, 所以,

ffmpeg -i video.mp4 -ss 5 -t 20 -i audio1.mp3 -ss 5 -t 20 -i audio2.mp3
    -filter_complex
       "[0]atrim=0:20[a];[1]adelay=20000|20000[b];[2]adelay=40000|40000[c];[a][b][c]amix=3"
    -vcodec copy -copyinkf -shortest final.mp4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM