A simple Bun script to compress MP4 video files using ffmpeg.
- Compresses all
.mp4
files found in theinput
directory. - Outputs compressed files to the
output
directory. - Uses
fluent-ffmpeg
for interacting with ffmpeg. - Provides a progress bar using
cli-progress
. - Configurable ffmpeg settings (codec, quality, preset, etc.).
- Clone this repository or download the script.
- Navigate to the project directory in your terminal.
- Install the dependencies:
bun install
You can configure the compression settings directly within the index.ts
file:
inputDir
: Directory to read input MP4 files from (default:./input
).outputDir
: Directory to save compressed MP4 files to (default:./output
).video_codec
: Video codec (default:libx264
).audio_codec
: Audio codec (default:aac
).quality
: Constant Rate Factor (CRF) for video quality (default:23
). Lower values mean higher quality and larger file size.tune
: Tune setting forlibx264
(default:animation
). Other options includefilm
,grain
,stillimage
,fastdecode
,zerolatency
.preset
: Encoding speed preset (default:veryslow
). Faster presets result in lower quality/larger file size for the same CRF. Options range fromultrafast
toveryslow
.profile
: H.264 profile (default:high
).audioBitrate
: Audio bitrate (default:192k
).
- Create an
input
directory in the project root (if it doesn't exist). - Place the MP4 files you want to compress into the
input
directory. - Run the script:
bun run index.ts
- The script will process each
.mp4
file and save the compressed version in theoutput
directory (which will be created if it doesn't exist). A progress bar will be displayed for each file.
- fluent-ffmpeg: A Node.js wrapper for ffmpeg.
- cli-progress: Displays progress bars in the terminal.
This project is licensed under the MIT License. See the LICENSE file for details.