问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/55800185/my-ffmpeg-output-always-add-extra-30s-of-silence-at-the-end