Skip to content

globalwetlands/video-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Video Compressor

Video Compressor uses FishID's FFMPEG preferred command to reduce file size and optimize it for analysis workflows. This project provides both direct FFmpeg usage and a Docker container for easy deployment and sharing.

FFmpeg Command

ffmpeg -hide_banner -loglevel error -i INPUT.MP4 -r 24 -vf scale=1920:-2,setsar=1:1 -c:v libx264 -crf 25 -preset faster -an -movflags +faststart INPUT-TRANSCODED.mp4

This command does:

  • Changes frames rate to 24 FPS, assumes that frame rate is over 24 FPS, -r 24
  • Resize resolution to 1920 width keeping aspect ratio, -vf scale=1920:-2,setsar=1:1
  • Sets video codec to H.264 using the libx264 encoder, which is widely compatible and offers good compression -c:v libx264
  • Sets image quality, Constant Rate Factor (CRF), a quality setting used with libx264 to 25, -crf 25, crf ranges from 0 which is equivalent to lossless, 18–23 which visually is a very good quality, to 51 very bad quality
  • Controls encoding speed vs compression efficiency, -preset faster
  • Removes audio track, -an
  • Moves the MP4 metadata (moov atom) to the beginning of the file, which enables fast streaming / playback in browsers and on the web.

Docker Usage

Using Pre-built Images (Recommended)

The easiest way to use this tool is with our pre-built Docker images:

Option 1: GitHub Container Registry (Free)

docker pull ghcr.io/your-username/video-compressor:latest
docker run --rm \
  -v /path/to/your/videos:/app/input:ro \
  -v $(pwd)/output:/app/output \
  ghcr.io/your-username/video-compressor:latest

Option 2: Docker Hub

docker pull your-username/video-compressor:latest
docker run --rm \
  -v /path/to/your/videos:/app/input:ro \
  -v $(pwd)/output:/app/output \
  your-username/video-compressor:latest

Building Locally

If you prefer to build the image yourself:

  1. Build the Docker image:

    docker build -t video-compressor .
  2. Process all MP4 files in a directory (Batch Mode):

    # Create output directory
    mkdir -p output
    
    # Run batch processing
    docker run --rm \
      -v /path/to/your/videos:/app/input:ro \
      -v $(pwd)/output:/app/output \
      video-compressor
  3. Process a single file:

    docker run --rm \
      -v /path/to/your/videos:/app/videos \
      video-compressor \
      /app/videos/input.mp4 /app/videos/output-transcoded.mp4

Using Docker Compose

  1. Setup:

    # Create directories
    mkdir -p videos output
    
    # Copy your MP4 files to the videos directory
    cp /path/to/your/*.mp4 videos/
  2. Run batch processing:

    docker-compose up video-compressor
  3. Run single file processing:

    docker-compose --profile single run video-compressor-single input.mp4 output.mp4

Volume Mounting Options

  • Batch processing: Mount your video directory to /app/input (read-only) and output directory to /app/output
  • Single file processing: Mount your video directory to any path inside the container and specify full paths

Examples

Batch process all videos in /Users/john/videos:

docker run --rm \
  -v /Users/john/videos:/app/input:ro \
  -v $(pwd)/output:/app/output \
  video-compressor

Process specific file with custom output name:

docker run --rm \
  -v /Users/john/videos:/app/videos \
  video-compressor \
  /app/videos/my-video.mp4 /app/videos/compressed-video.mp4

Features

  • Batch Processing: Automatically processes all MP4 files in a directory
  • Single File Processing: Process individual files with custom output names
  • Docker Support: Easy deployment and sharing with collaborators
  • Automated Builds: GitHub Actions automatically builds and publishes Docker images
  • Multi-platform: Supports both Intel/AMD (x64) and ARM64 (Apple Silicon) architectures
  • Cross-platform: Works on any system with Docker installed
  • No Dependencies: All required tools (FFmpeg) are included in the Docker image

Automated Builds

This project uses GitHub Actions to automatically build and publish Docker images:

  • 🚀 Automatic: Images are built on every push to the main branch
  • 🏷️ Versioned: Tagged releases create versioned Docker images
  • 🔄 Multi-platform: Built for both x64 and ARM64 architectures
  • 📦 Multiple registries: Published to both GitHub Container Registry and Docker Hub

See SETUP.md for detailed instructions on configuring automated builds.

About

FishID's FFMPEG preferred video compression command

Resources

Stars

Watchers

Forks

Packages