I am trying to create image sequences from video clips
I've tried several different command lines but I keep getting an unresolved error[s]
Ideally I would like to extract every nth frame to jpg/png
The documentation that I have seen suggests:
a) ffmpeg -i video.avi image%d.png
Unable to find a suitable output format for 'imaged.png'
b) ffmpeg -i video.avi -vcodec png image%d.png
Unable to find a suitable output format for 'imaged.png'
c) ffmpeg -i video.avi -f image2 -vcodec png image%d.png
Output #0, image2, to 'imaged.png':
Stream #0.0: Video: png, rgb24, 640x416, q=2-31, 200 kb/s, 23.95 tb(c)
Stream #0.0 -> #0.0
Press [q] to stop encoding
av_interleaved_write_frame(): I/O error occurred
Usually that means that input file is truncated and/or corrupted.
and re ffmpeg wiki:
You need to use %05d in the file name, this will add the frame number to the end of the images name. If you do not do this you will most likely end up with FFMPEG overwriting the same frame, leaving you with only the last fame accessible.
_%05d Is a numerical place holder and broken up as follows.
_ (under score) is just there to make reading the produced file name easier and can be removed.
% (percentage sign) indicates a special piece of code to follow for FFMPEG.
0 (zero) what character is used to pad the sequence, this often help programs associate sequences more easily.
5 (numerical value), how may placeholders there should be this should generate 99 999 picture frames. (+- 1hour 6min of Pal video)
d tell FFMPEG to use decimal and will count using whole integers.
Any help would be appreciated
ffmpeg -qmin 1 -y -i my.AVS -an -r 1 -f image2 -s 1920x1080 -pix_fmt rgb24 my.jpg
works great for a single image
+ Reply to Thread
Results 1 to 16 of 16
I have been using avisynth's selectevery() and trying to use ffmpeg - but it is not working for me
I have used VirtualDub for this - but I want to automate with ffmpeg
when I try ffmpeg -i input.avi -vcodec png output%05d.png [I renamed an avi file to input.avi]
Input #0, avi, from 'input.avi':
Duration: 00:08:08.50, start: 0.000000, bitrate: 813 kb/s
Stream #0.0: Video: msmpeg4, yuv420p, 640x416, 23.95 tb(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 96 kb/s
Unable to find a suitable output format for 'outputC:\ffmpeg-1\1.bat5d.png'
This post suggests you can do every nth frame with -vf select
Also see this
# select one frame every 100 select='not(mod(n\,100))'
I downloaded the latest static binary from zeronoe
ffmpeg -i d:\track_1.mp4 -vcodec png output%05d.png
I still get the same error
[image2 @ 02163980] Could not open file : outputC:\ffmpeg\1.bat5d.png
av_interleaved_write_frame(): Input/output error
I'll have to try it on my other computer
I was able to get mplayer to extract images but it was very slow
VirtualDub is way faster - but I want to do this commandline . . .
I have taken the jpg's from vdub and used gm.exe montage to do a quick layout
I have written a video thumbnail generator that is working great for me - very fast - no problems
I thought I could speed it up using a SelectEvery command - encode the every nth frame to jpg and then do a quick layout using gm.exe montage
P.S. Thanks for the links - I've copied the info -I'll see if I can implement . . .
Last edited by wiseant; 14th Mar 2012 at 22:07. Reason: P.S.
The "%05d" means your sequence will have names with 5 digits, 00001.png, 00002.png etc.
This is how it works.
If your video is 15fps.
And you want every 5th frame.
r is 15 divided by 5, which is 3.
So the command is:-
ffmpeg -i video.avi -r 3 -f image2 foo-%05d.png
Last edited by bat999; 14th Mar 2012 at 22:43.
This batch file is used to save images from a video at a set interval.
The default is to save a frame as a jpg every 30 seconds @ 24fps
The creation date of this batch file is 2/1/2009. Haven't used it for a couple of years.
Seems to work still.
The batch file 'frames_2_jpg.cmd' (double click on it to start) creates the output folder, then an AVS script,
and then starts Virtualdub with the AVS script as input.
To extract the images play the clip. (hit the space bar)
JPGs are saved in the output folder with the same name as the video (not including the extension).
The figure 720 is the frame count for 30 seconds - change 'frames_2_jpg.cmd' as needed.
for %%a in ("*.avi") do echo SelectRangeEvery(720, 1).ImageWriter("%%~na\", 0, 0,"jpg") >> "%%~n.avs"
FPS for 30 seconds :
24 fps - 720
25 fps - 750
29 fps - 870
@echo off echo For avi, press 1. echo For mpg, press 2. echo For vob, press 3. set /p v=Please make a selection and press Enter. [1,2,3]? if %v%==3 set v=vob if %v%==2 set v=mpg if %v%==1 set v=avi for %%a in ("*.%v%") do if not exist "%%~na\*.*" md "%%~na" if %v%==avi (for %%a in ("*.%v%") do echo avisource("%%a", audio=false) >> "%%~na.avs") else for %%a in ("*.%v%") do echo directshowsource("%%a", audio=false) >> "%%~na.avs" for %%a in ("*.%v%") do echo ConverttoRGB() >> "%%~na.avs" for %%a in ("*.%v%") do echo SelectRangeEvery(720, 1).ImageWriter("%%~na\", 0, 0,"jpg") >> "%%~na.avs" goto end for %%a in ("*.%v%") do "vdub\virtualdub.exe" "%%~na.avs" :end
Last edited by pcspeak; 14th Mar 2012 at 23:22.
Thanks bat999 and pcspeak
I'll try these out tomorrow and report back
OK - got it to work
Before I was just double-clicking a batch file in the ffmpeg directory - this wasn't working for me
But when I opened a dosbox and typed the commands it worked - and didn't work when I tried to run the batch file from the dos prompt
ffmpeg -i "test.avi" -r 0.08 -f image2 -s 128x96 %4d.png
the avi file has 17151 frames, fps=25
-r 0.08 -> 25fps/.08=312.5
so I should get 17151/312.5 = 54.8832 -> 55 frames and I ended up getting 54 frames [png's]
then I used test.avs:
this test.avs file shows 55 frames with an fps of 0.08
and used the same commandline
ffmpeg -i "test.avs" -r 0.08 -f image2 -s 128x96 %4d.png
and I got 55 images
so perhaps the rule of thumb using SelectEvery(,) is to use the derived framerate as the -r parameter
@pcspeak -> I hope to try out your batch file tomorrow
Last edited by wiseant; 15th Mar 2012 at 23:50.
If inputting the video directly to ffmpeg, you do need -r in order to tell ffmpeg the effective output frame rate. This causes ffmpeg to do the frame decimation and leave you with the required number of frames/images.
Change you command line to this:
ffmpeg -i "test.avs" -r 0.08 -f image2 -s 128x96 %%4d.png
You have to use double percentages "%%" with windows batch files and the FFMPEG command line because the % is a windows batch keyword.Signed up just to say thank-you, because this little tidbit right here.. is gold. Everywhere, people would keep saying "use %03d", which is of course correct, but only when running ffmpeg manually. So thanks!