

We set the start time and end time for the clip, but note that the cut will jump to the nearest keyframe.

You can only cut at the closest keyframe. This will give a pretty decent video quality, close to lossless.Ĭutting video (roughly) without transcodingĪs explained above, without transcoding the video, it is impossible to cut at an exact point in time, because of how keyframes work.

-crf 18 sets the video CRF to quality preset 18.-preset slow means we will use more time to encode the video, thus better quality.-c:v libx264 means we want to transcode the video to H.264/AVC format.-c:a copy means we will not be transcoding the audio.You can read more on how to encode video to H.264 with FFmpeg if you want. This example will cut the video at the start and end point, and convert the result to an MP4 file. There are a million ways to transcode video, so in this example, we will use the most common video encoder H.264/AVC. Unfortunately this will introduce generation loss, depending on the settings. Cutting video (exactly) with transcodingīy re-encoding the video, FFmpeg is able to cut the video at exact points in time. To understand why this happens you can read more about keyframes. Instead, FFmpeg tries to find the closest keyframe and cut it there. However, FFmpeg cannot cut at exact points in time unless it re-encodes the video. This is a great way to maintain the original quality, thus avoiding generation loss. If you’d like to learn more I recommend diving into the documentation.FFmpeg is able to cut, trim and extract videos without transcoding the media. Using FFmpeg to quickly trim a video is only touching the surface of what the tool is capable of. Note: both -ss and -to are optional if you’d like to include content from the start or end of the source video. copy is a special value in FFmpeg that tells FFmpeg not to reencode your video. In this case the copy codec is used to help improve the speed of encoding. This will cause the exported clip to only include content up to the provided time in the input source. -to 00:10:00: is used to set an end time for the clip.This will skip the amount of time specified forward in the input source and then begin the edited clip. -ss 00:05:00: is used to set a start time offset.In this case we’re referring to a video file named source.mp4. source.mp4: is used to specify an input source.
