VideoHelp Forum
+ Reply to Thread
Results 1 to 20 of 20
Thread
  1. Hello,

    I need to cut videos (mp4, mkv mostly) every 10 frames (to create some sorts of diaporama), and export them as separate 10 frames files. So far, the best solution I have found was to move 10 frame by 10 frame then cut and export the parts with "Davinci Resolve". But it takes too much time.
    I have also tried with ffmpeg, but I'm no good when it comes to commands, so I'd rather have a gui.
    Do you know an easy solution/software to perform that task?

    Thanks.
    Last edited by vmackey; 4th Aug 2021 at 13:24.
    Quote Quote  
  2. hi, try "MKVTOOLNIX" you have the option to cut video every "x" frames
    Quote Quote  
  3. 10 seconds or ten frames? You mix the two in your post.
    Quote Quote  
  4. Originally Posted by KNON View Post
    hi, try "MKVTOOLNIX" you have the option to cut video every "x" frames
    Thanks! I'm checking it out.
    Quote Quote  
  5. Originally Posted by jagabo View Post
    10 seconds or ten frames? You mix the two in your post.
    Oops, it's 10 frames. I edited the post.
    Quote Quote  
  6. Originally Posted by KNON View Post
    hi, try "MKVTOOLNIX" you have the option to cut video every "x" frames
    Unfortunately, it didn't work for me. I specified 10 frames, but the files I got were about 1 or 2 seconds. Any other suggestion of software?
    Quote Quote  
  7. Take a look at this:

    https://stackoverflow.com/questions/61893366/create-multiple-thumbnails-from-a-video-a...imes-intervals

    Create multiple thumbnails from a video at equal times / intervals

    Output one frame every 5 seconds

    Using the select filter:

    ffmpeg -i input.mp4 -vf "select='not(mod(t,5))',setpts=N/FRAME_RATE/TB" output_%04d.jpg

    Changing the interval from 5 to 10 should give you what you want.
    Quote Quote  
  8. Unless your input files have 10 frame or shorter keyframe intervals, this operation usually requires re-encoding (can't use stream copy, so you couldn't use mkvmerge/mkvtoolnix)

    It would look something like this. (You can change the re-encoding quality , or omit audio if you want)
    Code:
    ffmpeg -i input.ext -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 output%05d.mp4
    it will give you

    output00000.mp4
    output00001.mp4
    .
    .
    .

    Where output00000.mp4 has frames 0-9, 00001.mp4 has frames 10-19, etc...
    Quote Quote  
  9. MkvToolnix will only cut on keyframes. So you can't get 10 frame segments unless there are keyframes at those intervals. With long GOP codecs there can be hundreds of frames between keyframes. So you'll have to re-compress -- which MkvToolnix cannot do.

    This ffmpeg command will create 10 second segments from any video:

    Code:
    set LENGTH=0.333333
    ffmpeg -i %1 -segment_time %LENGTH% -f segment -reset_timestamps 1 -force_key_frames "expr: gte(t, n_forced * %LENGTH%)" -c:v libx264 -c:a aac "%~dpn1.%%6d.%~x1"
    Put that in a batch file and drag/drop a video onto it. It will produce a sequence of videos with the same base name with a six digit number and the same extension. So movie.mp4 will produce movie.000000.mp4, movie.000001.mp4, etc. The video will be encoded with x264, the audio with aac. Change the LENGTH value reflect the running time of each segment. Divide 10 (the number of frames you want) by the frame rate to get that number. The value 0.333333 used in the example will get you 10 frame segments from a 30 fps video.
    Quote Quote  
  10. Upon trying this, I found the instructions to be more than a little obscure.

    In fact, I've been unable to get any of the examples on that web page to work, I don't know why.

    ffmpeg -i input.mp4 -vf "select='not(mod(t,5))',setpts=N/FRAME_RATE/TB" output_%04d.jpg

    which results in:

    Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

    I also went to https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect where there are various examples:

    Select one frame every 100:

    -vf "select='not(mod(n\,100))'"

    this should work if you replace 100 with the number of frames in 10 seconds. It does select a pile of frames, but doesn't seem to be 10 seconds when I try it:

    I:\Downloads\test>ffmpeg -i "input.mp4" -vf "select='not(mod(t,240))'" output_%04d.jpg

    which also results in:

    Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

    on a video which is 24 frames per second and is 3 minutes long.

    ffmpeg -i "input.mp4" -vf "select='not(mod(n,4000))'" output_%04d.jpg

    I get 4002 output jpgs. They do move through the video, but not at 10 second intervals.

    From the ffmpeg.org documentation page,

    Select frames with a minimum distance of 10 seconds:

    select='isnan(prev_selected_t)+gte(t-prev_selected_t\,10)'

    ffmpeg -i "input.mp4" -vf "select='isnan(prev_selected_t)+gte(t-prev_selected_t\,100)'" output_%04d.jpg

    gets me over 2000 images, but not at 10 second intervals.

    Create a mosaic of the first scenes:

    ffmpeg -i video.avi -vf select='gt(scene\,0.4)',scale=160:120,tile -frames:v 1 preview.png

    might be close to what you eventually want, I tried this:

    ffmpeg -i input.mp4 -vf select='gt(scene\,0.1)',scale=160:120,tile -frames:v 1 preview.jpg

    This worked fairly well. It's not fixed time intervals, but it could be useful in creating a preview image for an entire video, if you can get it to do the entire video. There must be some parameters not in the example that can set the size of the output file or the number of frames.

    I found this on a different Stack Overflow Page:

    ffmpeg -i "input.mp4" -filter:v "select=(gte(t\,10))*(isnan(prev_selected_t)+g te(t-prev_selected_t\,10))" output_%04d.jpg

    This is close.


    One of the examples really, really, really ought to work: but as seems to happen far too often, nobody actually checks to see if their posted examples work.

    I think ffmpeg will do what you want if we can find someone who knows how the select filter actually works.

    I give up for now.
    Quote Quote  
  11. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    The OP reads as if the intent is to separate the source video into 10 second *video* clips. Poisondeathray and jagabo provided a solution above,
    based on the fact that the clips will have to be re-encoded
    Quote Quote  
  12. Originally Posted by BartZLederman View Post
    I give up for now.
    To output every 10th frame of a video as a JPG image:

    Code:
    SET DEC=10
    ffmpeg -i %1 -vf select='not(mod(n,%DEC%))',setpts=PTS/%DEC% "%~dpn1.%%6d.jpg"
    Last edited by jagabo; 4th Aug 2021 at 18:09.
    Quote Quote  
  13. Here's a video with frames numbered and timestamped for easy testing:

    Code:
    # 2500 frames at 25 fps
    BlankClip(width=1280, height=720, length=2500, fps=25)
    ShowFrameNumber(x=10, y=20)
    ShowTime(x=72, y=40)
    ConvertToYV12(matrix="rec709")
    Image Attached Files
    Quote Quote  
  14. Originally Posted by poisondeathray View Post
    Unless your input files have 10 frame or shorter keyframe intervals, this operation usually requires re-encoding (can't use stream copy, so you couldn't use mkvmerge/mkvtoolnix)

    It would look something like this. (You can change the re-encoding quality , or omit audio if you want)
    Code:
    ffmpeg -i input.ext -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 output%05d.mp4
    it will give you

    output00000.mp4
    output00001.mp4
    .
    .
    .

    Where output00000.mp4 has frames 0-9, 00001.mp4 has frames 10-19, etc...
    Thanks, your solution worked the best, but unfortunately, I got issues with it too. I would say the length of 70% of the clips I got are 10 frames. But then I also have other lengths in the mix. 4, 5, 8, 9 frames. Would you happen to know why?
    Quote Quote  
  15. Maybe your source is variable frame rate.
    Quote Quote  
  16. Understood.
    And how can I set things up to do a bulk job, while being able to keep the original output file for each part. For example, I have three videos sun.mp4, bird.mp4 and moon.mp4. And I process these in bulk. And each output clips keep the name of these original files. So:

    sun00000.mp4
    sun00001.mp4
    sun00002.mp4
    etc...

    bird00000.mp4
    bird00001.mp4
    bird00002.mp4
    etc...

    moon00000.mp4
    moon00001.mp4
    moon00002.mp4
    etc...

    Is it possible by modifying this command:

    ffmpeg -i input.mp4 -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 output%05d.mp4
    Quote Quote  
  17. ffmpeg windows batch - eg. process a folder of *mp4's sequentially

    Code:
    for %a in ("*.mp4") do ffmpeg -i "%a" -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 "%~na_%05d.mp4"
    Quote Quote  
  18. Originally Posted by poisondeathray View Post
    ffmpeg windows batch - eg. process a folder of *mp4's sequentially

    Code:
    for %a in ("*.mp4") do ffmpeg -i "%a" -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 "%~na_%05d.mp4"
    Works like a charm. thanks! If I may request an alternative.
    How can I set each of these parts into different folders accordingly to the video. Here for example. A folder sun, a folder bird and a folder moon, containing our respective clips.

    sun00000.mp4
    sun00001.mp4
    etc...

    bird00000.mp4
    bird00001.mp4
    etc...

    moon00000.mp4
    moon00001.mp4
    etc...
    Quote Quote  
  19. Code:
    for %a in ("*.mp4") do (
        mkdir "%~pna" 2>NUL
        ffmpeg -i "%a" -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 "%~pna\%~na%05d.mp4"
    )
    Quote Quote  
  20. Originally Posted by poisondeathray View Post
    Code:
    for %a in ("*.mp4") do (
        mkdir "%~pna" 2>NUL
        ffmpeg -i "%a" -f segment -segment_time 00:00:00.10 -reset_timestamps 1 -c:v libx264 -crf 18 -c:a aac -g 10 "%~pna\%~na%05d.mp4"
    )
    Perfect thanks
    Quote Quote  



Similar Threads

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