Skip to main content

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:

  1. I don't have enough space to store all of them.
  2. 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..
  3. 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.
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batch-compress-video-cli-0.2.1.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

batch_compress_video_cli-0.2.1-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page