I mean, how to generate images files from a video like screenshots.
-
1Related: https://superuser.com/questions/984850/linux-how-to-extract-frames-from-a-video-lossless | https://askubuntu.com/questions/587686/how-to-extract-images-from-a-video – Ciro Santilli OurBigBook.com Sep 08 '19 at 03:20
4 Answers
Try with ffmpeg
ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg
You can read the documentation here
-i inputfile.aviThe video input file is inputfile.avi-r 1extract 1 image per second of video. Replace that number for the number of images you want to get per second.-f image2force 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.jpegname 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.
- 4,005
- 1
- 15
- 31
-
1
-
@Nolwennig. Fixed, not as specific as the previous one but at least is the official documentation and hardly to be broken. – YoMismo Jun 23 '16 at 06:41
-
10`-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 Jun 01 '18 at 21:12
-
-
it does not work : [swscaler @ 0x5560a2cf5500] [swscaler @ 0x5560a2d05300] deprecated pixel format used, make sure you did set range correctly – Marietto Apr 30 '23 at 13:57
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.
- 81
- 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 Jan 11 '21 at 22:52
In VLC you can right click, Video, Take Snapshot
- 61
- 1
- 1
-
This sounds a bit labour-intensive if one would need images for e.g. each frame in scene. – Kusalananda Oct 06 '19 at 08:06
-
Unfortunately on Linux VLC crashes. (I found postings dating back to 2015, so this is a really old problem) – arved Jan 06 '21 at 11:10
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
- 1
-
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 Apr 30 '23 at 13:54
-
@Marietto That message is a warning, not an error — it doesn't stop ffmpeg writing the file anyway. – gidds Jun 26 '23 at 10:47