LaVOZs

The World’s Largest Online Community for Developers

'; Slice a video with ffmpeg based on frame position - LavOzs.Com

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?

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.

Related
Rotating videos with FFmpeg
cutting a video with ffmpeg with an absolute endposition
Cutting the videos based on start and end time using ffmpeg
Fastest way to extract a specific frame from a video (PHP/ffmpeg/anything)
In ffmpeg, can I specify time in frames rather than seconds?
Extract all video frames as images with FFMPEG
How to extract a fixed number of frames with ffmpeg?
ffmpeg extract frame timestamps from video
ffmpeg break up videos with frame persecond