-
Notifications
You must be signed in to change notification settings - Fork 19
Still Image Conversion
First you need to confirm that your video sequence you want to export into images is consisting of only I-frames. You can do that using the ffprobe utility:
ffprobe -v quiet \
-of csv=p=0 \
-read_intervals %+5 \
-select_streams v \
-show_frames \
-show_entries frame=pict_type \
/path/to/input_file.xxx
This command will show you the type of the frames for the first 5 seconds (read_intervals) of the /path/to/input_file.xxx video sequence. If you see only "I" you can proceed if not, then you should convert your sequence using one of the intra-frames codecs supported in FFMPEG like FFV1, etc.. You can find a list of the most popular codecs at this link.
You can convert your video sequence with FFV1 using the following syntax:
ffmpeg -i input_file.xxx \
-c:v ffv1 \
-level 3 \
-threads 8 \
-coder 1 \
-context 1 \
-g 1 \
-c:a copy output.mkv
Here I am converting the input_file.xxx using FFV1 using GoP (group of pictures) 1, which will ensure that my output video sequence is consisted of only I-frames. The explanation of the rest of the parameters you can find in the table below:
Name | FFmpeg argument | Valid values | Comments |
---|---|---|---|
Coder | -coder |
0, 1, 2 | 0=Golomb-Rice, 1=Range Coder, 2=Range Coder (with custom state transition table) |
Context | -context |
0, 1 | 0=small, 1=large |
GOP size | -g |
integer >= 1 | For archival use, GOP-size should be "1". |
Version | -level |
1, 3 | Select which FFV1 version to use. |
Threads | -threads |
integer >= 1 | The number of threads to use while processing. Adjust this to match how many of your available CPU cores you want to use. |
Slices | -slices |
4, 6, 9, 12, 16, 24, 30 | Each frame is split into this number of slices. This affects multithreading performance, as well as filesize: Increasing the number of slices might speed up performance, but also increases the filesize. |
Error correction/detection | -slicecrc |
0, 1 | 0=off, 1=on. Enabling this option adds CRC information to each slice. This makes it possible for a decoder to detect errors in the bitstream, rather than blindly decoding a broken slice. |
You can find more information at the official FFMPEG FFV1 encoding guide
You can export the video into a single screenshot or multiple screenshots using the following command:
-
ffmpeg -ss 0 -i input.mkv -c copy -vframes 1 -y -f mjpeg first.png
- extracts the first frame in a video file. You can define the timestamp at which you want to export the video frame. For example for 50fps video the first frame will be at-ss 0
, the second at-ss 0.02
, the third-ss 0.04
and so on. For 25fps, it would be 0, 0.04 and 0.08. You can find the duration of the frame dividing 1 by the number of frames per second, which you can find out using the following ffprobe command:ffprobe -v 0 -of csv=p=0 -select_streams 0 -show_entries stream=r_frame_rate input_file.xxx
-
ffmpeg -i input.mkv -c copy -f mjpeg lossless%05d.png
- extracts all the frames from the input video and creates png files called lossless00001.png, lossless00002.png and so on, the%05d
defines the length of the preceding zeros.