ffmpeg:混合不同长度的音频和视频 [英] ffmpeg : mix audio and video of different length

查看:130
本文介绍了ffmpeg:混合不同长度的音频和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件:1个视频文件(无声音)-长度6秒,1个音频-长度10秒.音频和视频都包含相同的对话,但是音频在开始播放视频之前提前4秒开始播放.

I have 2 files: 1 video file (without sound) - length 6 seconds, 1 audio - length 10 seconds. Both audio and video contains same conversation, but audio starts 4 seconds earlier and after that was started video.

[----------] audio
    [------] video

因此,我想将它们混合在一起以生成10秒长的视频文件,其中前4秒出现黑屏并显示音频,然后显示真实的视频和音频.

So, I want to mix them together to video file with length 10 seconds where first 4 seconds black screen with audio then goes real video and audio.

[====------] audio+video (where '=' is black screen)

我希望我的描述足够清楚).我该如何用ffmpeg或gstreamer做到这一点?

I hope my description was clear enough ). How can I do this with ffmpeg or gstreamer ?

推荐答案

假设视频的分辨率为WxH,帧频为F,持续时间之差为D秒,那么命令为

Let's say the video's resolution is WxH and framerate is F, and the difference in durations is D seconds, then the command is

ffmpeg -i video.mp4 -i audio.mp3 -f lavfi -i color=s=WxH:r=F -filter_complex
          "[0]setpts=PTS-STARTPTS+D/TB[v];[2][v]overlay=eof_action=endall[vid]"
       -map "[vid]" -map 1:a output.mp4

这篇关于ffmpeg:混合不同长度的音频和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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