Results 1 to 5 of 5

Thread: make screen captures from videos recursive?

  1. #1
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    make screen captures from videos recursive?

    I have a folder with 50 videos and I need to take some screen shots from each video recursively

    the following works for one file only
    Code:
    ffmpeg -i name.mp4 -r 1/20 %03d.jpg
    I tried
    Code:
    *.mp4
    but it said do I want to overwrite the video? I said no then it stopped so what I am doing wrong?

    thanks

  2. #2
    Join Date
    Sep 2006
    Beans
    3,713

    Re: make screen captures from videos recursive?

    You can use a bash "for" loop:
    Code:
    for f in *.mp4; do ffmpeg -i "$f" -r 1/20 %03d.jpg; done
    Unfortunately that will not create unique files names so the next video will overwrite them, or perhaps ffmpeg will halt asking you if you want to overwrite. It's easy to fix. You can give unique output file names:
    Code:
    for f in *.mp4; do ffmpeg -i "$f" -r 1/20 "${f%.mp4}-%03d.jpg"; done
    Alternatively, you can make a separate directory for each video.
    Code:
    for f in *.mp4; do mkdir "${f%.mp4}" && ffmpeg -i "$f" -r 1/20 "${f%.mp4}/%03d.jpg"; done
    If the output files look too crappy then add "-qscale" as an output option with a value between 2-31 (2 is best quality, and 31 is absolute worst).
    Last edited by FakeOutdoorsman; November 1st, 2012 at 08:00 PM.

  3. #3
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    Re: make screen captures from videos recursive?

    Quote Originally Posted by FakeOutdoorsman View Post
    You can use a bash "for" loop:
    Code:
    for f in *.mp4; do ffmpeg -i "$f" -r 1/20 %03d.jpg; done
    Unfortunately that will not create unique files names so the next video will overwrite them, or perhaps ffmpeg will halt asking you if you want to overwrite. It's easy to fix. You can give unique output file names:
    Code:
    for f in *.mp4; do ffmpeg -i "$f" -r 1/20 "${f%.mp4}-%03d.jpg"; done
    Alternatively, you can make a separate directory for each video.
    Code:
    for f in *.mp4; do mkdir "${f%.mp4}" && ffmpeg -i "$f" -r 1/20 "${f%.mp4}/%03d.jpg"; done
    If the output files look too crappy then add "-qscale" as an output option with a value between 2-31 (2 is best quality, and 31 is absolute worst).

    that's awesome! a couple more questions if you dont mind, how do I ensure the screenshot is the the same size as the video? some are 640x480 and some are 720x576 and how can I to take 5 screenshots from each video? I think the current setting takes a shot every x seconds because I am getting more shots from some of the longer videos?

    thanks

  4. #4
    Join Date
    Sep 2006
    Beans
    3,713

    Re: make screen captures from videos recursive?

    Quote Originally Posted by sohlinux View Post
    how do I ensure the screenshot is the the same size as the video? some are 640x480 and some are 720x576.
    By default the outputs will be the same frame size as the input, so you don't have to do anything extra.

    Quote Originally Posted by sohlinux View Post
    how can I to take 5 screenshots from each video? I think the current setting takes a shot every x seconds because I am getting more shots from some of the longer videos?
    Probably a dozen ways to do this, but here's a method using the "select" filter. Let's assume your input frame rate is 24.98 or more accurately 24000/1001 (NTSC film) and it is 120 seconds long in duration:

    1. (24000/1001) frame rate * 120 duration = ~2877 total frames
    2. 2877 / (number of frames desired - 1) = ~719 frames between output images


    Please double check my math since I've always been deficient in that area. Which results in:
    Code:
    ffmpeg -i input select="eq(n\,0)+eq(n\,719)+eq(n\,1438)+eq(n\,2157)+eq(n\,2876),setpts=N/((24000/1001)*TB)" output-%03d.png
    You probably don't want the very first frame or the very last so you may want to add a few seconds buffer (±3 seconds in this example, or roughly 75 frames) for the first and last values:
    Code:
    ffmpeg -i input select="eq(n\,75)+eq(n\,719)+eq(n\,1438)+eq(n\,2157)+eq(n\,2801),setpts=N/((24000/1001)*TB)" output-%03d.png
    It's kind of tricky but can be scripted.

  5. #5
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    Re: make screen captures from videos recursive?

    Quote Originally Posted by FakeOutdoorsman View Post
    By default the outputs will be the same frame size as the input, so you don't have to do anything extra.



    Probably a dozen ways to do this, but here's a method using the "select" filter. Let's assume your input frame rate is 24.98 or more accurately 24000/1001 (NTSC film) and it is 120 seconds long in duration:

    1. (24000/1001) frame rate * 120 duration = ~2877 total frames
    2. 2877 / (number of frames desired - 1) = ~719 frames between output images


    Please double check my math since I've always been deficient in that area. Which results in:
    Code:
    ffmpeg -i input select="eq(n\,0)+eq(n\,719)+eq(n\,1438)+eq(n\,2157)+eq(n\,2876),setpts=N/((24000/1001)*TB)" output-%03d.png
    You probably don't want the very first frame or the very last so you may want to add a few seconds buffer (±3 seconds in this example, or roughly 75 frames) for the first and last values:
    Code:
    ffmpeg -i input select="eq(n\,75)+eq(n\,719)+eq(n\,1438)+eq(n\,2157)+eq(n\,2801),setpts=N/((24000/1001)*TB)" output-%03d.png
    It's kind of tricky but can be scripted.
    thanks a lot!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •