You can extract images every time interval by using fractions. If you want to prefix with 0's on the output images, use image_%03d.jpg for image_001.jpg, image_002.jpg etc. Outputs will be image_1.png, image_2.png, image_3.png You can specify a value up to 31 for more compressed images, but I go with the highest quality and perform my image manipulation later with other tools. The -q:v 1 tells FFmpeg to take the highest quality image possible. There is a chance this may result in artifacts, but it is much faster.
ffmpeg \īy placing -ss parameter ahead of the input, FFmpeg will seek to the closest point in the file first, and then take the screenshot.
The code below will extract 1 frame from an input file at the specified time. Examples Extract 1 Image At Specific Point Setting Image Quality/Compressionįor all the examples below, when outputting as a jpg file, you can specify -q:v 1 to tell FFmpeg to take the highest quality image possible. The examples below show you various ways to extract images from videos using FFmpeg. The most common need for this is for creating thumbnails for your video files on a website. Unfortunately, it will also reset the time, so that you have to adjust the end time (set with -to) based on the new beginning time of the video file.Sometimes it's useful to extract images from videos. When -ss comes first, it will adjust to the nearest keyframe of the video. This is a trick described in the seeking part of the FFmpeg tutorial. So a trick is to move the -ss command before -i in the example above: ffmpeg -ss 01:19:27 -i input.mp4 -to 02:18:51 -c:v copy -c:a copy output.mp4 After some digging around I found that this may be because of lacking keyframes. I have sometimes experienced that the above commands leave black frames at the beginning of the video. This will extract 1min5sec (using the -t flag) starting from 1min10sec (the -ss flag) in the file. You may instead want to specify a fixed duration to extract, in which case you can use: ffmpeg -i input.mp4 -ss 00:01:10 -t 00:01:05 -c:v copy -c:a copy output.mp4 This means that the above command only takes a few seconds to run. The copy parts of the command are meant to copy both the original audio and video content without recompressing. This will cut the section from about 1h19min (after the -ss command) to 2h18min (after the -to command). This is all you need to do: ffmpeg -i input.mp4 -ss 01:19:27 -to 02:18:51 -c:v copy -c:a copy output.mp4 Fortunately, a simple way is to do this with the beautiful command-line utility FFmpeg. A much better solution is to perform “lossless” trimming. You can split and trim files in most graphical video editing software, but these will typically recompress the export file, reducing the video quality. Cropping a video means cutting out parts of the image, and I have another blog post on cropping video files using FFmpeg. Splitting and trimming are temporal transformations and should not be confused with the spatial transformation cropping. I often have long video recordings that I want to split or trim.
This is a note to self, and hopefully others, about how to easily and quickly trim videos without recompressing the file.