将不同长度的音频/视频与ffmpeg混合 [英] Mix audio/video of different lengths with ffmpeg
问题描述
我想将video.mp4
(持续时间为1分钟)中的视频和audio.mp3
(持续时间为10分钟)中的音频混合到一个输出文件中,持续时间为1分钟.来自audio.mp3
的音频应位于4分钟-5分钟的位置.如何使用ffmpeg
做到这一点?
I want to mix video from video.mp4
(1 minute duration) and audio from audio.mp3
(10 minute duration) into one output file with a duration of 1 minute. The audio from audio.mp3
should be from the 4 min - 5 min position. How can I do this with ffmpeg
?
推荐答案
如果video.mp4
没有音频
您可以使用以下命令:
If video.mp4
has no audio
You can use this command:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c copy -shortest output.mkv
-
音频将按照问题的要求从4分钟位置(
-ss 00:04:00
)开始播放.The audio will be from the 4 minute position (
-ss 00:04:00
) as requested in the question.此示例将流复制(重新混合)视频和音频-不会重新编码.
This example will stream copy (re-mux) the video and audio–no re-encoding will happen.
您将必须按以下说明添加
-map
选项: FFmpeg多路复用视频和音频(来自另一个视频)-映射问题.You will have to add the
-map
option as described here: FFmpeg mux video and audio (from another video) - mapping issue.添加 apad 过滤器以添加无声填充:
Add the apad filter to add silent padding:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c:v copy -af apad -shortest output.mkv
请注意,过滤需要重新编码,因此在此示例中将对音频进行重新编码.
Note that filtering requires re-encoding, so the audio will be re-encoded in this example.
这篇关于将不同长度的音频/视频与ffmpeg混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!