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.
+ Reply to Thread
Results 1 to 20 of 20
-
Last edited by vmackey; 4th Aug 2021 at 12:24.
-
-
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. -
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
output00000.mp4
output00001.mp4
.
.
.
Where output00000.mp4 has frames 0-9, 00001.mp4 has frames 10-19, etc... -
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"
-
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. -
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 -
Last edited by jagabo; 4th Aug 2021 at 17:09.
-
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")
-
-
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 -
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... -
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" )
Similar Threads
-
Virtual Dub frames cut off at 14001. How to increase?
By Sonario648 in forum Newbie / General discussionsReplies: 15Last Post: 19th Dec 2020, 22:23 -
ffmpeg cut point wrong with 5 reference frames video
By Budman1 in forum EditingReplies: 9Last Post: 8th Aug 2020, 12:06 -
Incorrect video cut timing on MKV video with lossless quality
By may5224 in forum EditingReplies: 8Last Post: 19th Nov 2019, 15:02 -
Trying to cut MKV video, I get corrupt video
By Wilykit in forum EditingReplies: 2Last Post: 29th Nov 2017, 02:12 -
Cut Out Segments Of Video Using Womble MPEG Video Wizard DVD
By luckyace in forum Newbie / General discussionsReplies: 2Last Post: 4th May 2017, 03:46