Dump last frame of video file using ffmpeg/mencoder/transcode et. al

bobbogo picture bobbogo · Mar 9, 2011 · Viewed 13.9k times · Source

I'd like to grab the last frame in a video (.mpg, .avi, whatever) and dump it into an image file (.jpg, .png, whatever). Toolchain is a modern Linux command-line, so things like mencoder, transcode, ffmpeg &c.

Cheers, Bob.

Answer

blahdiblah picture blahdiblah · Nov 4, 2011

This isn't a complete solution, but it'll point you along the right path.

Use ffprobe -show_streams IN.AVI to get the number of frames in the video input. Then

ffmpeg -i IN.AVI -vf "select='eq(n,LAST_FRAME_INDEX)'" -vframes 1 LAST_FRAME.PNG

where LAST_FRAME_INDEX is the number of frames less one (frames are zero-indexed), will output the last frame.