March 28, 2013

[HOW TO] Extract frames from video - Linux

To extract frames from a video do the following:

Install ffmpeg:

sudo apt-get install ffmpeg
Then decide how many frames you want to extract and do one of the following:

To extract each and every frame:

ffmpeg -i Video.mpg Pictures%d.jpg
For example:
ffmpeg -i /home/user/Desktop/Video.mpg Pictures%d.jpg
If you want to specify the number of frames to be extracted, the quality of the extracted frames or to start extracting from a particular point adjust your command by adding one of the following flags or all of them.
  • -r How many frames you want to be extracted per second (The default value is 25).
  • -f Defines the format.
  • Picture%3d.jpg %3d means that the names of the images will be like Picture001, Picture002 and so on. You can use any format you like.
  • -s You can define the image size.
  • -t You can set the duration of the extraction.
  • -vframes You can define how many frames you want to be extracted.
  • -ss Defines the time you want the extraction to start.
For example:
To extract 1 frame every second type:
ffmpeg -i Video.mpg -r 1 Picture%3d.jpg
To extract the frames from the first 10 seconds of the video type:
ffmpeg -i Video.mpg -t 10 Picture%3d.jpg
To start the extraction at a given time type: (for example: 0:34:14)
ffmpeg -i Video.mpg -ss 0:34:14 Picture%3d.jpg
To define the number of frames you want to be extracted type: (for example 80)
ffmpeg -i Video.mpg -vframes 80 Picture%3d.jpg
You can also be more specific by using all of the above flags together:
ffmpeg -i Video.mpg -r 2 -t 150 Picture%3d.jpg
The above command will extract 2 frames per second for 150 seconds.

No comments:

Post a Comment