Saturday, November 10, 2018

Trimming mp4 Files Without Re-encoding Using FFmpeg on Windows Subsystem for Linux

I recently used FFmpeg installed on the Windows Subsystem for Linux on my Windows 10 machine to trim the beginning and ending off of some mp4 video files without re-encoding the files. Being able to do this without re-encoding makes the process much quicker and does not result in image degradation.

Install the Windows Subsystem for Linux

If it is not already installed, you will need to install the Windows Subsystem for Linux. Instructions for doing this can be found at https://docs.microsoft.com/en-us/windows/wsl/install-win10. I have the Ubuntu distro installed (https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6).

Install FFmpeg

To install FFmpeg (https://ffmpeg.org/) on Ubuntu open the Ubuntu command line and enter the following:
sudo apt install ffmpeg

Trim the Beginning of a Video

The following command can be used to trim the first 30 seconds off the front of an mp4 file:
ffmpeg -ss 00:00:30 -i input.mp4 -c copy output.mp4

Trim the Ending of a Video

The following command can be used to trim an mp4 file at a specified position. In this example it copies the first thirty seconds of the input.mp4 file and copies it to the output.mp4 file.
ffmpeg -i input.mp4 -c copy -to 00:00:30 output.mp4
Another way to accomplish this is to specify a duration. In this example it copies the first fifteen seconds of the input.mp4 file and copies it to the output.mp4 file.
ffmpeg -i input.mp4 -c copy -t 00:00:15 output.mp4

Trim the Beginning and Ending of a Video

The following command can be used to trim the first 30 seconds off the front of an mp4 file and then copy the next three minutes and forty five seconds. The resulting file will be three minutes and forty five seconds long:
ffmpeg -ss 00:00:30 -i input.mp4 -c copy -t 00:03:45 output.mp4

No comments: