How FFmpeg compression works
The application uses thefluent-ffmpeg library with ffmpeg-static to perform video compression. When you compress a video, FFmpeg re-encodes it with the following settings:
- Video bitrate: 1000k (1 Mbps)
- Output format: Same as input (typically MP4)
- File naming: Compressed files are prefixed with
compressed_
renderer.js
The
-b:v 1000k option sets the video bitrate to 1000 kilobits per second, which provides a good balance between file size and quality for most videos.File selection process
The compression workflow begins when you select a video file through the file input element.Select a video file
Click the file input button and choose a video file from your computer. The input accepts any video format supported by your browser.
index.html
Validate file selection
When you click the compress button, the app validates that a file has been selected:
renderer.js
Compression workflow
Once the file is loaded, the compression process follows these steps:Temporary file creation
Temporary file creation
The video file is temporarily saved to your system’s temp directory to allow FFmpeg to process it:This temporary file is automatically deleted after compression completes or if an error occurs.
renderer.js
FFmpeg processing
FFmpeg processing
FFmpeg reads the temporary file and applies the 1000k bitrate compression:The output options specify the video bitrate, which controls the compression level and resulting file size.
renderer.js
Event handling
Event handling
The compression process emits three types of events:
- progress: Updates the progress bar as compression advances
- end: Displays completion message and resets the progress bar
- error: Shows error message and performs cleanup
Output file naming
Compressed videos are saved to thevideooutputs directory with the compressed_ prefix:
renderer.js
- Original file
- Compressed file
Dependencies
The compression feature relies on two npm packages:package.json
- ffmpeg-static: Provides a static FFmpeg binary
- fluent-ffmpeg: Offers a fluent API for FFmpeg operations
The FFmpeg path is automatically configured using
ffmpeg-static at application startup:renderer.js