Compress raw video from action cameras from directory or path using ffmpeg, with a simple cli to automate the recurring commands.
Project description
Batch Video Compress cli
pip install batch-compress-video-cli
This is a cli tool that batch compress all videos in a folder and process in/move to a separate folder if needed. Save the need to craft ffmpeg
commands, perfect for compressing and storing unused action camera/drone videos.
Usage
Prerequisite: ffmpeg
must be installed and be in PATH
.
$ batch_compress_video
this will compress all .mp4
file in the current directory that does not have compressed
in its name. It does that with default values of crf=23, preset=slower
.
$ batch_compress_video -f $SOURCE_DIR -t $DEST_DIR -p $PROC_DIR -d
this will find all .mp4
file in $SOURCE_DIR
, individually move them to $PROC_DIR
, compress it there using the default values, and then move them to $DEST_DIR
. This is really helpful when the source and destination directories are HDD storage and conflict with read/write operation of ffmpeg
. The -d
flag signifies the original videos are to be deleted.
$ batch_compress_video --crf 25 --scale 0.5 --preset fast
This will compress video with a quality of crf=25
, reduce the width and height to 50%, and use fast
preset.
A full example (output when it is running):
$ batch_compress_video --source "/Volumes/SSDS1/footage/gopro/PADDLE_2022_12" --process-dir "." --destination "/Volumes/SSDS1/footage/gopro/PADDLE_2022_12" --crf 25 --preset "medium" --scale 0.4
will compress 18 videos, they are ['GX010142.MP4', 'GX010156.MP4', 'GX010157.MP4', 'GX010155.MP4', 'GX010141.MP4', 'GX010140.MP4', 'GX010154.MP4', 'GX010150.MP4', 'GX010144.MP4', 'GX010145.MP4', 'GX010147.MP4', 'GX010153.MP4', 'GX010152.MP4', 'GX010146.MP4', 'GX010148.MP4', 'GX010149.MP4', 'GX010159.MP4', 'GX010158.MP4']
======== PROCESSING VIDEO: GX010142.MP4 ========
SIZE: 267 MB; DURATION: 48.0s; FRAME_RATE: 30000/1001; RESOLUTION: 1920x1080
copying /Volumes/SSDS1/footage/gopro/PADDLE_2022_12/GX010142.MP4 to ./GX010142.MP4 for processing
compressing video ...
frame= 1438 fps=105 q=-1.0 Lsize= 4974kB time=00:00:47.95 bitrate= 849.6kbits/s speed=3.49x
copying ./GX010142_compressed.mp4 to destination /Volumes/SSDS1/footage/gopro/PADDLE_2022_12/GX010142_compressed.mp4
Video compressed to /Volumes/SSDS1/footage/gopro/PADDLE_2022_12/GX010142_compressed.mp4
SIZE: 5093 KB; DURATION: 48.0s; FRAME_RATE: 30000/1001; RESOLUTION: 768x432
======== PROCESSING VIDEO: GX010156.MP4 ========
SIZE: 351 MB; DURATION: 62.9s; FRAME_RATE: 30000/1001; RESOLUTION: 1920x1080
copying /Volumes/SSDS1/footage/gopro/PADDLE_2022_12/GX010156.MP4 to ./GX010156.MP4 for processing
compressing video ...
frame= 1728 fps=101 q=31.0 size= 4096kB time=00:00:57.87 bitrate= 579.8kbits/s speed=3.37x
The progress bar is displayed for each video as it is converting. After it is converted, the newly compressed video stats will be displayed. In this case, extreme compression (lossy, scaled down) resulted in video that are less than 2% the size of the original.
Maybe in 2040 GANs, powerful graphic cards and TB sized storage are cheap and plentiful, and we restore our videos to its full (and maybe some extra) glory.
Rationale
After racking up 100s of GBs of videos in a couple hours of GoPro and DJI videos, I realized that:
- I don't have enough space to store all of them.
- The videos are very poorly compressed, if at all. Compressing at a level without reducing quality will yield significantly smaller video. Compressing at higher level will yield very small video compared to original..
- I don't want to individually use FFMPEG cli commands to compress all of those videos, I want a simple command that can compress all of them.
- ffmpeg often break down on HDDs due to disk constraints.
This is a tool written to solve all of these problems.
Developing
pytest
and coverage
are used for testing. After cloning, you can invoke them with make test
.
CLI can be updated with make install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file batch-compress-video-cli-0.2.1.tar.gz
.
File metadata
- Download URL: batch-compress-video-cli-0.2.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 500a304b293c93a8e6cdf9ed977bc3dd3baef0b350fe33dc47715cc7d0b914e8 |
|
MD5 | 1d3d87278801c8ffbf51f334a1d65449 |
|
BLAKE2b-256 | 49b88e1b6b883769ec84bcc748c9c9e76fe604f1a5a278026040b89b0de4e6f9 |
File details
Details for the file batch_compress_video_cli-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: batch_compress_video_cli-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca54cdfecb8421cf6517e121c059092b4d35c36378f4c15fdc2f95da4e4ae37 |
|
MD5 | 75a43853d56ec6fec553ef8ed20cf701 |
|
BLAKE2b-256 | 4aa3ba29fb3df3d5f2da26cf1335ad785ef6a3608a51ea54dc2cd425cef82036 |