3

I'm trying to get multiple snapshots of a single input file using Input Seeking. I want to seek to different keyframes and save each to different output images.

I can use this using multiple calls:

ffmpeg -ss 280 -i sample.mp4 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out1.jpg
ffmpeg -ss 300 -i sample.mp4 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out2.jpg
ffmpeg -ss 302 -i sample.mp4 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out3.jpg

Unfortunately I have to call ffmpeg programmatically using exec. Is there a way to batch process the tasks above? It has to use input seeking. Thanks.

1 Answer 1

1

There are two basic ways to do this:

1) feed file as multiple inputs and extract one image from each input

ffmpeg -ss 280 -i sample.mp4 -ss 300 -i sample.mp4 -ss 302 -i sample.mp4
-map 0 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out1.jpg
-map 1 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out2.jpg
-map 2 -aspect 1.7777777777778 -vframes 1 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p out3.jpg

This method can get unwieldy with many targets or if the input is read from over a network.

2) feed it as one input but only decode keyframes and output as one stream.

ffmpeg -skip_frame nokey -i sample.mp4 -vf "select='lt(abs(t-280),0.2)+lt(abs(t-300),0.2)+lt(abs(t-302),0.2)'" -aspect 1.7777777777778 -qmax 9 -qmin 8 -bt 10000000 -y -pix_fmt yuv420p -vsync 0 out%d.jpg

This allows a leeway of 0.2 seconds in identified keyframe timings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.