I use
ffmpeg -i my_video.mp4 -vf scale=1024:-1 my_video.avi
to encode/transcode a video. Now i would like to do the same thing but start at frame X. How can I do that?
I use
ffmpeg -i my_video.mp4 -vf scale=1024:-1 my_video.avi
to encode/transcode a video. Now i would like to do the same thing but start at frame X. How can I do that?
To Larry's point, videos are commonly variable frame rate so using a timestamp may not be accurate. However, you can use -fps_mode
to convert a video to constant frame rate.
ffmpeg -i <input> -fps_mode cfr -c:v copy -c:a copy <output>
Identify the start frame for your trim then calculate the time in the video your start frame occurs. This will require you to know the frame number of your start frame and the video's fps (obtainable with ffprobe).
frame_time = frame number / frames per second
In the below command the -ss
flag will trim the video starting at a given time. Input the frame timestamp we just calculated, I labeled it <frame_time>
.
ffmpeg -ss <frame_time> -i <input> <output.avi>
Additionally, if you have a set number of frames for your output video use:
ffmpeg -ss <frame_time> -i <input> -frames:v <number_of_frames> <output.avi>
For the original question, you can insert -vf scale=1024:-1
into either of the above commands (before the output).