VideoHelp Forum
+ Reply to Thread
Results 1 to 16 of 16
Thread
  1. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    Hi

    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 mapping:
    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
    _%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

    Incidentally

    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

    TIA
    Quote Quote  
  2. you need "%05d" where "05" is the number of placeholder digits

    ffmpeg -i input.avi -vcodec png output%05d.png
    not sure how to do every nth frame in ffmpeg , but you can do it with avisynth's selectevery()

    ffmpeg can accept avs scripts if it has support compiled

    vdub can also export image sequence
    Quote Quote  
  3. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    hi pdr

    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]

    I get

    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'
    Quote Quote  
  4. maybe you have a bad binary? it works here with these builds
    http://ffmpeg.zeranoe.com/builds/

    what do you want to automate? processing a directory of files?
    Quote Quote  
  5. This post suggests you can do every nth frame with -vf select
    http://directed-procrastination.blogspot.com/2011/10/time-lapse-fun-with-ffmpeg-and-mencoder.html

    Also see this
    http://forum.doom9.org/showthread.php?t=156516

    libavfilter
    http://ffmpeg.org/libavfilter.html#select

    # select one frame every 100 select='not(mod(n\,100))'
    Quote Quote  
  6. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    I downloaded the latest static binary from zeronoe

    i used

    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
    [from graphicsmagick]

    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.
    Quote Quote  
  7. Member bat999's Avatar
    Join Date
    Feb 2008
    Location
    United Kingdom
    Search Comp PM
    Hi
    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:-
    Code:
    ffmpeg -i video.avi -r 3 -f image2 foo-%05d.png
    Last edited by bat999; 14th Mar 2012 at 22:43.
    Quote Quote  
  8. Member
    Join Date
    Apr 2007
    Location
    Australia
    Search Comp PM
    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)
    Close VirtualDub.

    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

    Batch File:
    Code:
    @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.
    Quote Quote  
  9. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    Thanks bat999 and pcspeak

    I'll try these out tomorrow and report back
    Quote Quote  
  10. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    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:
    AVISource("D:\Test.avi")
    selectevery(312,0)

    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.
    Quote Quote  
  11. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by wiseant View Post
    then I used test.avs:
    AVISource("D:\Test.avi")
    selectevery(312,0)

    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
    When using SelectEvery(), you don't need the -r parameter, because (as you have seen) the video is already known to have 0.08 fps, with the required 55 frames delivered by Avisynth.

    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.
    Quote Quote  
  12. Member
    Join Date
    Jun 2007
    Location
    Canada
    Search Comp PM
    @Gavino
    Yes, after doing some more tests I figured this out - seems ffmpeg's lowest value for -r is 0.05 - at least that's what I found and you definitely do not want to use -r if you are using selectevery()
    Quote Quote  
  13. 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.
    Quote Quote  
  14. Member
    Join Date
    Sep 2012
    Location
    Denmark
    Search PM
    Originally Posted by mwiggi1 View Post
    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!
    Quote Quote  
  15. I am executing ffmpeg -i filename.avi output%05d.png
    I have done it other times, but now, the proccess never stop! and it give me thousands of png files until the hard disk is full!
    I can't find a solution.
    I need help!
    Quote Quote  
  16. Member
    Join Date
    Apr 2013
    Location
    Northern Tablelands, NSW, Australia
    Search PM
    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!
    I also just signed up to say thank you! It was seriously annoying running around the internet trying to find what the problem was when everyone just kept on telling me to use %03d! Someone needs to spread the word about this

    Clonkex
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!