How can I extract an image from a particular time of a video in Xubuntu 16.04?
Solution 1
You can use mplayer
(from package mplayer
, not installed by default):
mplayer -vo jpeg -ss 00:00:26 -frames 1 sample-video.mp4
This will create the file 00000001.jpg
so you have to rename it. As far as I know there's no way to specify a filename.
-vo jpeg
means you want JPEG output, -ss 00:00:26
seeks to the given position, -frames 1
means to process one frame and then quit.
Solution 2
You can use ffmpeg
ffmpeg -loglevel quiet -ss 26 -i sample-video.mp4 -t 1 -f image2 anyfilename.jpeg
- -loglevel set the logoutput to quiet because ffmpeg is very chatty
- -ss is seek (in seconds, i.e. where you want to take the snapshot)
- -i input video file
- -t timeframe of the snapshot (in seconds)
- -f filetype
You can also play around with the options, like control quality of the jpeg output -q:v <linear integer 1-10>
or resolution -s 480x300
.
Some more ideas here
VLC Method
cvlc sample-video.mp4 --start-time=26 --run-time=1 --rate=1 --video-filter=scene --vout=dummy --aout=dummy --scene-ratio=24 --scene-prefix=sample-image --scene-replace vlc://quit
cvlc - because its command-line and we don't want any windows opening. also, this means we can run it without X11.
--start-time=26 - is the exact position of the snapshot in seconds
- --run-time=1 - how long the video will "play" in seconds. We play it for one second to make a screenshot of this second
- --rate=1 when to take the screenshot. This basically means "every second" and is useful, if you have longer files, to take a screenshot every 60 seconds or every 5 minutes
- --video-filter=scene tell VLC that we want to take screenshots
- --vout=dummy no output for video on X11, we don't need it
- --aout=dummy no output for audio, we don't need it
- --scene-ratio=24 we tell VLC that there are approx 24 frames per second
- --scene-prefix=sample-image the filename of your screenshot
-
--scene-replace replace any files that are called like your screenshot
sample-image.png
with your current screenshot. If you omit this, VLC will start numbering the screenshots - vlc://quit quit vlc once we are finished
Complete documentation here
Related videos on Youtube
Sonevol
Sexually I am transsexual lesbian. Please consider me to be female and address me by "she" and "her" and be compassionate to my feelings. Pets are my love and my pet Bhutu (female balck and white tuxedo cat) means everything to me. Also I love my mom, my grand-mom and the girl named Puja. I also love the two children which Puja has. We six are almost family. I like UNIX and UNIX based operating systems. I love to play around with Linux and learn newer things. Professionally I am front end web developer working independently. Also I am a weed addict.
Updated on September 18, 2022Comments
-
Sonevol over 1 year
I am looking for a command line option.
For example, if I have the video
sample-video.mp4
, and I want to generate an image filesample-image.jpg
from the video at time 00:00:26, what command should I give?Also, it would be very helpful if you can explain in detail what the function of every argument of the command is.
-
Sonevol over 6 yearsWhat is the advantage of getting more than 1 frames? Will those be copies or each frame will differ by a second?
-
Christopher B. Adkins over 6 yearsImages created from more frames will differ by fractions of a second. Tjhe exact value depends on the video.
-
Sonevol over 6 yearsWhat do you mean by chatty? And I want a snapshot at the 26th second. So why specify timeframe by -t. I am taking image not video.
-
Robert Riedl over 6 years"Chatty" because ffmpeg prints over 40 lines of log output with this command, like the current version, setup type and information about the input video file - which is uninteresting for you. For your purpose you can probably omit "-t 1". Seems the default is one second or a fraction of that, which is fine for the screenshot. The nice difference is the possibility to define the output filename and tweak quality/resolution, etc
-
xDaizu over 6 years@Sonevol The frame exactly at 0:00:26 may not be exactly what you want. You may want to take the ~50 frames between 0:00:25 and 0:00:27 (or even just 3-4 frames around the 0:00:26 mark) and then browse through them to pick the best one.
-
andrew.46 over 6 years@FlorianDiesch Possible also to output to png with something like:
-vo png:z=9
with the -z setting specifying compression level. For jpeg you could also add in a quality setting:-vo jpeg:quality=100
. But your answer is great as it is already :)