I'd like to extract a slice of video from a video. Unfortunately, I do not have the start time position and duration to run ffmpeg like so:
ffmpeg -sameq -ss [start_seconds] -t [duration_seconds] -i [input_file] [outputfile]
Instead, I have the first and the last frame number. So... is it possible to slice a mp4 video with ffmpeg based on frame position?
FFmpeg offers different commands that you can use to split up a video. We'll take a look at how to use the seeking parameter -ss , but you can also use other commands such as the trim filter. To cut a specific part of a video, you use the seeking option -ss to get to a specific part that you want to cut.
Use the FFmpeg executable with the seek option. You'll need to convert to a time first, e.g. if I want frame 150 and my video is 29.97 FPS the command will be ffmpeg -ss 00:00:05.01 -i myvideo. avi -frames:v 1 myimage. jpg .
How to change the frame rate. There are two ways to change the output frame rate: With the -r option used as an output option. With the fps filter.
If the file has audio, which also needs to be correspondingly sliced, then you will need to know the start time and duration. Unless the video is variable frame rate, start frame index I
is at time I/FPS
and end frame O
is at time O/FPS
where FPS is the frame rate of the video. Running ffprobe [input_file]
will give you the frame rate reading.
Else use,
ffmpeg -i input.mp4 -vf trim=start_frame=I:end_frame=O+1 -an output.mp4
-sameq
is deprecated and does not mean same quality. This command will skip the audio as it can't be cut with reference to video frame indices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With