ffmpeg - output silent audio track if source has n

2019-07-28 12:21发布

I need a video file whose audio and video track duration are always the same. The file must contain an audio track even if source audio has no audio track. How do I tell ffmpeg to add a silent audio track when source has no audio trace. Also, if source has an audio track that is a different duration than the video, I need ffmpeg to append silent audio to make both output audio and video the same duration. Is this possible in one line with ffmpeg?

标签: ffmpeg
1条回答
The star\"
2楼-- · 2019-07-28 12:48

The command below will add a silent track of the same length* as the video, if there is no audio** in the source file.

ffmpeg -i video -f lavfi -i anullsrc=cl=1 -shortest -c:v libx264 -c:a aac output.mov

*Since video frame duration and audio frame duration aren't usually identical, the lengths won't be exactly the same.

**when map is not specified, ffmpeg selects a single audio stream from among the inputs with the highest channel count. If there are two or more streams with same no. of channels, it selects stream with lowest index. anullsrc here has one channel, so it will be passed over except when source has no audio.

查看更多
登录 后发表回答