If you want to extract images from a video file. You can use
ffmpeg to get images from a video.
ffmpeg
ffmpeg is a very useful command line program which can be used to transcode media files. It is part of the FFmpeg leading multimedia framework that has many functionalities such as the ability to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created.
There are many various tools included in the framework each of which has a specific role. For example the ffserver is used to stream multimedia for live broadcasts, ffprobe is used to analyze multimedia stream, ffplay can be used as a simple media player and ffmpeg has the ability to convert multimedia files between formats.
Steps:
You need to install the ffmpeg command line utility in your linux machine for extracting images from the video file.
Ubuntu users can easily install the ffmpeg utility by typing and running the following command in their terminal.
- sudo apt-get install ffmpeg
Fedora/Centos users can install ffmpeg directly from the repos.
After that,
- cd /usr/local/src/wget http://www.ffmpeg.org/releases/ffmpeg-2.2.3.tar.bz2
- ./configure
- tar -xvjf ffmpeg-2.2.3.tar.bz2
- cd ffmpeg-*
- ./configure
Note: If the following error occurs,
yasm/nasm not found or too old. Use --disable-yasm for a crippled build.
Execute the command below.
- ./configure --disable-yasm
continue by compiling,
Once the compile is finished run the following command to install ffmpeg.
Note: Everything has been finished now, you have to type a few commands in your terminal and you will be able to extract images from any type of video file.
Before going any further make sure you are in the same directory with the video file from which you want to extract images from. Use the cd command to navigate to the right directory. Since the video I am using for the purpose of this tutorial is in my Desktop i use the following command to navigate to my desktop.
Then I use the following command to extract images from my video file.
- ffmpeg -i "Exapmle_video.mp4" -r 1 -q:v 2 -f image2 image-3%d.jpeg
The
-i option serves to get the input which in my case is the video file named "Exapmle_video.mp4", the
-r option sets the number of frames to be extracted as images every second. I like to extract one frame every second.
Then a very important option that should be mentioned and I like to use is the
-q:v which is used to set the image quality of the images being extracted. I always get high quality images when extracting them from a video by using the value of 2.
FFmpeg Basic Commands
Here is the list of few ffmepg basic commands list.
- ffmpeg -version : show version
- ffmpeg -formats : show available formats
- ffmpeg -codecs : show available codecs
- ffmpeg -decoders : show available decoders
- ffmpeg -encoders : show available encoders
- ffmpeg -bsfs : show available bit stream filters
- ffmpeg -protocols : show available protocols
- ffmpeg -filters : show available filters
- ffmpeg -pix_fmts : show available pixel formats
- ffmpeg -layouts : show standard channel layouts
- ffmpeg -sample_fmts: show available audio sample formats
Try it :-)