Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slice a video with ffmpeg based on frame position

Tags:

video

ffmpeg

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?

like image 950
Jabb Avatar asked Jan 25 '16 23:01

Jabb


People also ask

How do I cut part of a video in FFmpeg?

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.

How do I extract a frame from a video using FFmpeg?

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 do I change frame rate in FFmpeg?

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.


1 Answers

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.

like image 147
Gyan Avatar answered Oct 25 '22 19:10

Gyan