Skip to main content

A CLI tool to transcode 5.1 audio in video files to E-AC3.

Project description

Surround to E-AC3 Transcoder (eac3-transcode)

A command-line utility to intelligently find and convert 5.1 surround sound audio tracks in your video files (.mkv, .mp4) to the E-AC3 (Dolby Digital Plus) format, while preserving other streams.

This tool is perfect for users who want to standardize their media library's audio, ensuring compatibility and high quality for 5.1 channel audio tracks, particularly for English and Japanese languages.

Overview

eac3-transcode automates the often tedious process of inspecting video files, identifying specific audio tracks, and re-encoding them. It's designed to be smart about which tracks to process:

  • Scans Individual Files or Entire Directories: Process a single video or batch-process an entire folder (including subfolders).

  • Targets Specific Languages: Focuses on English (eng) and Japanese (jpn) audio streams.

  • Intelligent Transcoding:

    • Converts 5.1 channel audio streams (that aren't already ac3 or eac3) to eac3.
  • Smart Copying:

    • Copies English or Japanese audio streams that are already in ac3 or eac3 format.

    • Copies English or Japanese audio streams that are not 5.1 channels (e.g., stereo).

  • Stream Preservation:

    • Video streams are always copied without re-encoding (lossless).

    • Subtitle streams are always copied without re-encoding.

  • Efficient Processing:

    • Other language audio streams are dropped to save space and processing time.

    • Files are skipped entirely if no English or Japanese audio streams meet the criteria for transcoding or copying, preventing empty or unnecessary output files.

  • Flexible Output: Save processed files alongside originals or in a specified output directory, maintaining the source folder structure if applicable.

Prerequisites

Before you can use eac3-transcode, you must have FFmpeg installed on your system and accessible in your system's PATH. FFmpeg is used for both analyzing (ffprobe) and processing (ffmpeg) the video files.

  • Windows: Download from ffmpeg.org and add the bin directory to your system's PATH.

  • macOS: Install via Homebrew: brew install ffmpeg

  • Linux: Install using your distribution's package manager (e.g., sudo apt update && sudo apt install ffmpeg for Debian/Ubuntu).

You can verify your FFmpeg installation by opening a terminal or command prompt and typing ffmpeg -version and ffprobe -version.

Installation

Install eac3-transcode directly from PyPI using pip:

pip install surround-to-eac3 It's recommended to install it in a virtual environment.

Usage

The primary command is eac3-transcode.

Basic Examples:

  1. Process a single video file (output saved in the same directory):

eac3-transcode --input "/path/to/your/movie.mkv" Output will be /path/to/your/movie_eac3.mkv if processing occurs.

  1. Process all videos in a folder (output saved in the same directory as originals):

eac3-transcode --input "/path/to/your/video_folder/"

  1. Process videos and save them to a specific output directory:

eac3-transcode --input "/path/to/your/video_folder/" --outdir "/path/to/your/processed_videos/" If /path/to/your/video_folder/ contains subfolders, the structure will be replicated under /path/to/your/processed_videos/.

  1. Specify a different bitrate for transcoded E-AC3 audio:

eac3-transcode --input "video.mp4" --bitrate "640k"

Command-Line Options

Usage:

eac3-transcode [-h] -i INPUT_PATH [-o OUTPUT_DIRECTORY_BASE] [-br AUDIO_BITRATE]
An advanced video transcoder that processes files to use E-AC3 for specific audio tracks, filters by language, and can process entire folders.

Options:

  • -h, --help
    Show this help message and exit.

  • -i INPUT_PATH, --input INPUT_PATH
    (Required) Path to the input video file or folder.

  • -o OUTPUT_DIRECTORY_BASE, --outdir OUTPUT_DIRECTORY_BASE
    (Optional) Base directory to save processed files. If the input is a folder, the original source structure is replicated under this directory. If this option is not set, processed files will be saved alongside the original files.

  • -br AUDIO_BITRATE, --bitrate AUDIO_BITRATE
    (Optional) Sets the audio bitrate for the E-AC3 stream (e.g., '640k', '1536k'). Defaults to '1536k'.

How It Works

  1. File Discovery: The script scans the input path for .mkv and .mp4 files.

  2. Stream Analysis (using ffprobe): For each file:

    • It extracts information about all audio streams: codec, channels, and language tags.
  3. Decision Logic:

    • Language Filter: Only eng (English) and jpn (Japanese) audio streams are considered for keeping. Others are marked to be dropped.

    • Transcode Criteria: An eng or jpn stream is transcoded to E-AC3 if:

      • It has 6 audio channels (5.1 surround).

      • Its current codec is not ac3 or eac3.

    • Copy Criteria: An eng or jpn stream is copied directly if:

      • It's already ac3 or eac3.

      • It does not have 6 channels (e.g., it's stereo).

    • File Skipping: If no audio streams are marked for either 'transcode' or 'copy' (e.g., a file only contains French audio, or all English/Japanese audio is already in the desired format and channel layout for copying), the entire file is skipped to avoid creating redundant or empty output files.

  4. Processing (using ffmpeg):

    • A new FFmpeg command is constructed based on the decisions.

    • Video (-c:v copy) and subtitle (-c:s copy) streams are mapped and copied directly.

    • Selected audio streams are mapped and either transcoded to eac3 with the specified bitrate (and forced to 6 channels) or copied (-c:a copy).

    • Language metadata is set for transcoded audio streams.

    • The output file is named by appending _eac3 to the original filename (before the extension).

Troubleshooting

  • ffmpeg or ffprobe not found:

    • Ensure FFmpeg is installed correctly and its bin directory is in your system's PATH environment variable. See the Prerequisites section.
  • No files processed / "Skipping 'filename': No English/Japanese audio streams meet criteria...":

    • This is expected behavior if the files scanned do not contain any English or Japanese audio tracks that require transcoding to E-AC3 or qualify for copying based on the tool's logic. For example, if a file only has a stereo English AAC track, it will be copied (not transcoded to 5.1 E-AC3). If it only has a French 5.1 DTS track, it will be skipped.
  • Permission Errors:

    • Ensure you have write permissions for the output directory and read permissions for the input files/directory.
  • Unexpected FFmpeg errors:

    • The script prints FFmpeg's stderr output on failure, which can provide clues. Ensure your video files are not corrupted.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues page.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • This tool relies heavily on the fantastic FFmpeg project.

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

surround_to_eac3-0.1.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

surround_to_eac3-0.1.4-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file surround_to_eac3-0.1.4.tar.gz.

File metadata

  • Download URL: surround_to_eac3-0.1.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for surround_to_eac3-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c3f29e66fc0598d9cd4697789a5e785e98014ab974c0db3cac7499f83cc2534d
MD5 76b0af81be5f3cac476fa1290acc82ac
BLAKE2b-256 9800286247bc55ed1885d193ec83bc369643fce5d26c0fe2af8071ab2799298c

See more details on using hashes here.

File details

Details for the file surround_to_eac3-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for surround_to_eac3-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e6fcfe05e8f38c182677c10779cd4acb6081c373ce436f540e2136652beaab5c
MD5 1bdf3529f25a64432236532cb87654e6
BLAKE2b-256 1a7fe7d491587357d9e1c46ddb11bb2bf4befede3606b30a376d3014450471ec

See more details on using hashes here.

Supported by

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