This JavaScript utility leverages fluent-ffmpeg
to compress video files. It allows for customizable settings like quality, CRF (Constant Rate Factor), and encoding speed.
Before running the script, ensure you have Node.js installed. Then, install fluent-ffmpeg
:
npm install fluent-ffmpeg
To use this script, run it via Node.js, passing the required arguments:
node compressVideo.js <input-file> <quality> <crf> <speed>
<input-file>
: Path to the video file to be compressed.<quality>
: The height in pixels for the output video (e.g., 480 for 480p).<crf>
: Constant Rate Factor for quality control (0-51; 0 is lossless, 23 is default).<speed>
: Preset for encoding speed (values like ultrafast, superfast, etc.).
node compressVideo.js video.mp4 720 23 fast
This command will compress video.mp4
to 720p with a CRF of 23 and a fast encoding speed.
compressVideo
: Main function to compress the video.showHelp
: Displays usage instructions.
The script includes error handling, displaying relevant messages in case of issues during the compression process.
Feel free to fork this repository and submit pull requests for improvements.