Cut Video with FFmpeg: No Re-encoding (Minimal)
In this article, we will discuss how to cut a video using the popular command-line tool FFmpeg without re-encoding. This method is also known as the "minimal" method because it preserves the original quality of the video and is faster than re-encoding. We will also cover the use of subtitles and the -avoid_negative_ts make_zero option for dealing with timing issues.
Prerequisites
Before we begin, make sure you have FFmpeg installed on your system. You can download it from the official website here. Also, make sure you have a video file (in this example, we will use an MP4 file) that you want to cut.
Cutting the Video
To cut a video without re-encoding, you can use the -ss and -t options in FFmpeg. The -ss option specifies the start time of the cut, and the -t option specifies the duration of the cut. For example, to cut a 60-second clip starting at 120 seconds, you can use the following command:
ffmpeg -i input.mp4 -ss 120 -t 60 -c copy output.mp4In this command:
-i input.mp4specifies the input file-ss 120specifies the start time of the cut (120 seconds)-t 60specifies the duration of the cut (60 seconds)-c copytells FFmpeg to copy the existing video and audio streams without re-encodingoutput.mp4specifies the output file
Using Subtitles
If your video has subtitles, you can use the -map option to include them in the cut. For example, to include subtitles in the cut, you can use the following command:
ffmpeg -i input.mp4 -ss 120 -t 60 -c copy -map 0:v:0 -map 0:a:0 -map 0:s:0 output.mp4In this command:
-map 0:v:0maps the first video stream from the input file-map 0:a:0maps the first audio stream from the input file-map 0:s:0maps the first subtitle stream from the input file
Dealing with Timing Issues
Sometimes, cutting a video can result in timing issues, such as negative timestamps. To fix this, you can use the -avoid_negative_ts make_zero option. For example, to cut a video and avoid negative timestamps, you can use the following command:
ffmpeg -i input.mp4 -ss 120 -t 60 -c copy -avoid_negative_ts make_zero output.mp4In this article, we have discussed how to cut a video using FFmpeg without re-encoding. We have also covered the use of subtitles and the -avoid_negative_ts make_zero option for dealing with timing issues. With these techniques, you can quickly and easily cut videos without sacrificing quality or wasting time on re-encoding.