Thursday 3 May 2018

How to extract one frame of a video every N seconds to an image?


How can I convert a video file to a sequence of images, for example one frame every N seconds. Can mplayer or ffmpeg do this? I have used MPlayer to grab screenshots manually but I would like to automate this for a long video.



Answer



mplayer -vo jpeg -sstep 5 file.avi

will save a frame as a jpeg file every 5 seconds.


However, it will not stop at the end of the file, it will continue producing copies of the last frame. To avoid this, find the duration of the video in seconds, using another player, or with mplayer:


mplayer -vo null -ao null -frames 0 -identify file.avi

and look for a line like "ID_LENGTH=147.00".


Subtract 2 from the length, and use this value for the -endposoption. For example, for a 147 second video:


mplayer -vo jpeg -sstep 5 -endpos 145 file.avi

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...