Introduction
This article explains how to compress MP4 video files using the x265 codec while preserving the original audio tracks. This technique is useful for those who want to reduce the file size of their videos without losing the audio data.
What is x265?
x265 is an open-source video compression standard that uses the High Efficiency Video Coding (HEVC) or H.265 codec. It is designed for use with HD and UHD videos, reducing file size while maintaining video quality. x265 is a royalty-free alternative to the proprietary H.265 codec.
Why Compress MP4 Videos?
Compressing MP4 videos can save storage space, reduce upload times, and speed up transfers over networks. It also helps conserve bandwidth and improve playback performance on devices with limited resources.
How to Compress MP4 Videos with x265
To compress MP4 videos using x265, you will need to install a compatible encoding tool, such as FFmpeg, HandBrake, or x265 itself. In this example, we will use FFmpeg.
Installing FFmpeg
FFmpeg is a free and open-source tool for handling multimedia files and streams. It is compatible with most operating systems and can be installed using package managers, installers, or by building it from source.
Encoding MP4 Videos with x265
Once FFmpeg is installed, open a terminal or command prompt and navigate to the directory containing the MP4 video file you want to compress. The basic syntax for encoding an MP4 video using x265 with FFmpeg is:
ffmpeg -i input.mp4 -c:v libx265 -crf -map 0:v:0 -map 0:a:0 output.mp4
Replace "input.mp4" with the name of the original MP4 video file and "output.mp4" with the desired name for the compressed video file. The "-crf" flag sets the Constant Rate Factor, with a lower value resulting in higher quality but larger file size (default: 28).
The "-map" flags are used to preserve the original audio track(s) from the input file. "-map 0:v:0" selects the first video stream from input.mp4, and "-map 0:a:0" selects the first audio stream. If there are multiple audio tracks in the original file, replace "0" with the appropriate track number for each "-map" flag.
- x265 is an open-source video codec that reduces file size while maintaining video quality.
- Compressing MP4 videos can save storage space, reduce upload times, and improve playback performance.
- To compress MP4 videos using x265, use FFmpeg, HandBrake, or x265 with the appropriate command-line flags.
References
-
x265: https://x265.org/
-
FFmpeg: https://ffmpeg.org/
-
HandBrake: https://handbrake.fr/