leo charre

contact links about resume

dev design near life experience heroes




how to get a movie screenshot with bash and mplayer

Imagine you have a movie, and you want to get a screen capture (screenshot, screencap, what have you..).
What should you do? Open the movie, pause and then get a screenshot of our desktop?
Nah…

Use mplayer..

Let’s create a directory to store the screenshot..
$ mkdir /tmp/moviecap

Now let’s tell mplayer go take a screenshot of the movie at 15 minutes and 20 seconds..
$ mplayer -vo jpeg:outdir=/tmp/moviecap/ -nosound -ss 15:20 -frames 1 source_movie.avi
$ ls /tmp/moviecap
Voila. You get a 0000001.jpg file, it’s a movie frame.

Ok. Easy enough.
What if we want to convert the entire movie to frames? So we can select some of the frames we want..
(This will take a while..)
$ mkdir /tmp/allframes
$ mplayer -vo jpeg:outdir=/tmp/allframes -nosound source_movie.avi
$ ls /tmp/allframes
Yeah, you’ll see a few thousand files.
How do we get rid of some of these?
$ for num in 1 3 5 7 9; do rm /tmp/allframes/*$num.jpg; done;
That deleted all images ending in odd numbers.

Great. But we still have all these freaking images named very vague- Let’s rename these suckers..
$ cd /tmp/allframes
$ rename 0 source_movie_ ./0*.jpg

Now you have to view and pick out..
$ gqview /tmp/allframes

Ok. That should make it easier for ya :-)


Linux User