30

I mean, how to generate images files from a video like screenshots.

1

4 Answers 4

46

Try with ffmpeg

ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg

You can read the documentation here

  • -i inputfile.avi The video input file is inputfile.avi
  • -r 1 extract 1 image per second of video. Replace that number for the number of images you want to get per second.
  • -f image2 force image output format, you may probable be able to omit this since the program tries to choose the output images format from the file extension.
  • image-%3d.jpeg name of the output images, the %3d indicates that the output generated images will have a sequence number there of 3 decimals, if you want the number padded with zeroes you just need to use %03d.
5
  • 1
    your link seems be broken
    – Nolwennig
    Commented Feb 24, 2016 at 9:10
  • @Nolwennig. Fixed, not as specific as the previous one but at least is the official documentation and hardly to be broken.
    – YoMismo
    Commented Jun 23, 2016 at 6:41
  • 12
    -r 1 is for the number of images per sec. So for 60ips, or 24, it's -r 24. And to limit the extract, it's -ss [start] -t [duration].
    – Sandburg
    Commented Jun 1, 2018 at 21:12
  • Thanks, work fine on Xubuntu Commented Jul 27, 2019 at 2:45
  • it does not work : [swscaler @ 0x5560a2cf5500] [swscaler @ 0x5560a2d05300] deprecated pixel format used, make sure you did set range correctly
    – Marietto
    Commented Apr 30, 2023 at 13:57
7

I have just downloaded the latest version of VLC for Windows 32 - 2.1.2 Rincewind and it works fine to do this.

Steps:

1 - Click Tools > Preferences and click radio button All

2 - Scroll down and click the + sign next to Video to expand

3 - Scroll down and click on Scene Filter and fill in the info for Directory Path prefix (where you want to save frames). Don't click Save.

4 - Scroll up and click on the word Video under Filters

5 - Click the check box for Scene video filter and click Save.

6 - Open and run a video and it will save .png's

7 - To stop saving frames go back to step 5 and uncheck Scene video filter. Easy really once you know where to find the settings.

1
  • I had to restart VLC to get changes to the Scene Filter preference to take effect. My platform is macOS; not sure if this applies to Unix/Linux/Win versions. VLC 3.0.11.1.
    – Mat Gessel
    Commented Jan 11, 2021 at 22:52
7

In VLC you can right click, Video, Take Snapshot

2
  • This sounds a bit labour-intensive if one would need images for e.g. each frame in scene.
    – Kusalananda
    Commented Oct 6, 2019 at 8:06
  • Unfortunately on Linux VLC crashes. (I found postings dating back to 2015, so this is a really old problem)
    – arved
    Commented Jan 6, 2021 at 11:10
0

Hope this help

#!/bin/bash
source_dir="."
output_dir="."
input_file_types=(avi wmv flv mkv mpg mp4)
output_file_type="jpg"

convert() {
        echo "" | ffmpeg -ss $ss -y -i "$in_file" -an -f image2 -vframes 1 "$output_dir/$out_file"
}

for input_file_types in "${input_file_types[@]}"
do

        find "$source_dir" -name "*.$input_file_types" -print0 | while IFS= read -r -d $'\0' in_file
        do
                echo "Processing…"
                echo ">Input  "$in_file
                # Replace the file type
                out_file=$(echo $in_file|sed "s/\(.*\.\)$input_file_types/\1$output_file_type/g")
            echo ">Output "$out_file

# get video duration
#    fulltime=`ffmpeg -i "$in_file" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//`;
#    hour=`echo $fulltime | cut -d ':' -f 1`;
#    minute=`echo $fulltime | cut -d ':' -f 2`;
#    second=`echo $fulltime | cut -d ':' -f 3 | cut -d '.' -f 1`;

#    seconds=`expr 3600 \* $hour + 60 \* $minute + $second`;
#    ss=`expr $seconds / 2`; # from the middle of video



    ss=`expr 10`; # from the 10sec of video



    # Convert the file
                convert "$in_file" "$out_file"

                if [ $? != 0 ]
                then
                    echo "$in_file had problems" >> ffmpeg-errors.log
                fi

                echo ">Finished "$out_file "\n\n"
        done
done
2
  • Tom : your script does not work : [image2 @ 0x56081d0f9b00] The specified filename '././video-nano.jpg' does not contain an image sequence pattern or a pattern is invalid. [image2 @ 0x56081d0f9b00] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
    – Marietto
    Commented Apr 30, 2023 at 13:54
  • @Marietto That message is a warning, not an error — it doesn't stop ffmpeg writing the file anyway.
    – gidds
    Commented Jun 26, 2023 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .