How to Trim Video Using FFmpeg and Its Best Alternative
FFmpeg offers different commands to cut the beginning, middle part, or end of your video file. As a command-line utility, FFmpeg provides lots of filters to process media files. To cut a specific segment of the video, you will use the parameter -ss, which can be used in multiple ways to cut different parts from your video. Also, FFmpeg enables you to trim a video without re-encoding using the command -c:v copy -c:a copy. Let’s take a look at some examples of FFmpeg trim video.
Step 1. Download FFmpeg on your computer. Extract the executable files and put ffmpeg.exe in the same folder as the video file you want to cut.
Step 2. Type in CMD in the address bar to run the FFmpeg Command window.
Step 3. Put in the command line to trim video using FFmpeg.
Step 4. Press Enter to start the process and export the final file.
Cut Any Part from a Video
ffmpeg -i input.mp4 -ss 00:05:10 -t 00:10:00 -c:v copy -c:a copy output1.mp4
input.mp4 is the MP4 video you will trim in FFmpeg, -ss 00:05:10 is the start time, -t 00:10:00 is the part to be cut, and output1.mp4 is the output file. i.e. the output video will be from 00:05:10 to 00:15:10.
FFmpeg Cut Video from Time to Time
ffmpeg -i input.mp4 -ss 00:05:20 -to 00:20:10 -c:v copy -c:a copy output2.mp4
-ss 00:05:20 is the start time, and -to 00:20:10 is the end time. This will result in a 14 minutes and 50 seconds video.
Cut the End of a Video
To cut the end of a video, you will use -sseof, the seeking parameter that makes FFmpeg cut the last N seconds from your video file. It uses negative values to indicate the position related to the eof (end of file). For example,
ffmpeg -sseof -00:05:00 -i input.mp4 -c copy output3.mp4
will cut off the last 5 minutes of the input MP4 video.
Trim Video without Re-encoding
ffmpeg -i input.mp4 -ss 00:05:10 -t 00:10:00 -c:v copy -c:a copy output4.mp4
-c:v copy -c:a copy will copy the original audio and video data to make FFmpeg trim video without re-encoding.
Trim Video with Re-encoding in FFmpeg
ffmpeg -ss 00:05:10 -accurate_seek -i input.mp4 -t 00:10:00 -c:v libx264 -c:a aac output7.mp4
This command will export an MP4 file with H.264 video and AAC audio from FFmpeg. -accurate_seek can make a more accurate length for the output video.
Read more here: Source link
