ffmpeg 1个视频文件中包含2个音频文件 [英] ffmpeg 2 audio files in one video file

查看:240
本文介绍了ffmpeg 1个视频文件中包含2个音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我有一个视频文件(video.mp4)和两个音频文件(audio1.mp3和audio2.mp3.)视频的长度为60秒,每个音频文件的长度为30秒.

我要达到的目标是: 视频的前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

上面的命令获取第一个输入的视频流和第三个输入的音频流.第二个输入的音频流似乎已被覆盖.如何将所有音频流放在一起?如何定义音频流开始时的偏移量?

解决方案

我假设您要在一个流中合并音频程序.即使您对其他音频应用了时间戳偏移,大多数播放器也不会在播放中切换音频流.

所以

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

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.

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.

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

这篇关于ffmpeg 1个视频文件中包含2个音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆