Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

windows - My ffmpeg output always add extra 30s of silence at the end

This is a code / argument I use to merge 1 audio and 1 image into 1 video. For some reason it adds 30s silence to the end of output video no matter the source.

I run this on Win10 x64, with latest ffmpeg installed. I have checked the code but cannot identify where it makes the silence.

ffmpeg -y -loop 1 -framerate 2 -i "some.png" -i "with.mp3" 
-c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest "result.mkv"

The output should not conatin the additional 30s of silence. It should end when audio runs out.

I should add that I copied most of the arguments from some website, and that OP seems to use it just fine, so I'm not sure if this is just my problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use

ffmpeg -y -loop 1 -framerate 2 -i "some.png" -i "with.mp3" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest -fflags +shortest -max_interleave_delta 100M "result.mkv"

Containers (AVI, MP4, MKV) usually store multiple streams in an interleaved fashion i.e. a few seconds of video, then a few seconds of audio, and so on. So ffmpeg buffers data from all streams, when writing.

-shortest acts at a relatively high-level and is triggered when the first of the streams has finished. However, buffered data from other streams will still be written to file. -fflags shortest acts at a lower level and stops the buffered data from being written when used with a sufficiently high max_interleave_delta.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...