From 6a1ea2e9da886f8d3f51a4ff5458d40a961f4d3d Mon Sep 17 00:00:00 2001 From: Lucas Hahmann Date: Tue, 1 Jul 2025 09:46:35 +0000 Subject: [PATCH] Initial Commit --- README.md | 121 ++++++++++++++++++++++++++++++++ gitignore | 1 + hanbrake-batch-converteer.sh | 74 +++++++++++++++++++ profiles/BluRay H.265 HEVC.json | 114 ++++++++++++++++++++++++++++++ profiles/DVD 720p H.265.json | 114 ++++++++++++++++++++++++++++++ 5 files changed, 424 insertions(+) create mode 100644 README.md create mode 100644 gitignore create mode 100755 hanbrake-batch-converteer.sh create mode 100755 profiles/BluRay H.265 HEVC.json create mode 100755 profiles/DVD 720p H.265.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..1db41f0 --- /dev/null +++ b/README.md @@ -0,0 +1,121 @@ +# HandBrake Batch Converter Script + +This Bash script converts video files in bulk using **HandBrakeCLI** with predefined presets for Blu-ray and DVD sources. +It supports recursive folder scanning and preserves the folder structure in the output directory. + +--- + +## Features +- Converts all `.mkv` files from the source directory and its subfolders. +- Preserves the original folder structure in the destination directory. +- Select between **Blu-ray** and **DVD** presets. +- Skips already converted files to avoid duplication. +- Logs all conversion activity. + +--- + +## Requirements + +1. **Install HandBrakeCLI** + - **Ubuntu/Debian:** + ```bash + sudo apt update + sudo apt install handbrake-cli + ``` + - **Fedora:** + ```bash + sudo dnf install HandBrake-cli + ``` + - **macOS (Homebrew):** + ```bash + brew install handbrake + ``` + - **Windows:** Download from [HandBrake Downloads](https://handbrake.fr/downloads2.php) + +2. **Preset JSON files** in the `./profiles/` directory: + - `BluRay H.265 HEVC.json` + - `DVD 720p H.265.json` + +--- + +## Installation + +Clone the repository: + +```bash +git clone https://github.com/yourusername/handbrake-batch-converter.git +cd handbrake-batch-converter +chmod +x convert.sh +``` + +--- + +## Usage + +```bash +./convert.sh --source /path/to/source --destination /path/to/destination --mode [bluray|dvd] +``` + +### Example + +```bash +./convert.sh \ + --source "/media/movies_raw" \ + --destination "/media/movies_converted" \ + --mode bluray +``` + +This will: +1. Search `/media/movies_raw` for all `.mkv` files, including in subdirectories. +2. Re-create the same folder structure under `/media/movies_converted`. +3. Convert each file using the `BluRay H.265 HEVC` preset. +4. Skip files that already exist in the destination. + +--- + +## Modes + +| Mode | Preset File | Description | +|----------|-------------------------------------------|-----------------------------| +| bluray | `./profiles/BluRay H.265 HEVC.json` | For high-quality Blu-ray rips | +| dvd | `./profiles/DVD 720p H.265.json` | For standard DVD conversions | + +--- + +## Log File + +All conversion logs are saved to: +``` +./handbrake_convert.log +``` + +--- + +## Directory Structure Example + +**Source:** +``` +/source + ├── Movie1 + │ ├── video1.mkv + │ └── video2.mkv + └── Movie2 + └── video1.mkv +``` + +**Destination after conversion:** +``` +/destination + ├── Movie1 + │ ├── video1.mkv + │ └── video2.mkv + └── Movie2 + └── video1.mkv +``` + +--- + +## License + +This project is licensed under the MIT License. + diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..56b33f9 --- /dev/null +++ b/gitignore @@ -0,0 +1 @@ +handbrake_convert.log diff --git a/hanbrake-batch-converteer.sh b/hanbrake-batch-converteer.sh new file mode 100755 index 0000000..50a68be --- /dev/null +++ b/hanbrake-batch-converteer.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# === Default settings === +HANDBRAKE_CLI="/usr/bin/HandBrakeCLI" +LOG_FILE="./handbrake_convert.log" + +# === Read parameters === +while [[ $# -gt 0 ]]; do + case "$1" in + --source) + SOURCE_DIR="$2" + shift 2 + ;; + --destination) + DEST_DIR="$2" + shift 2 + ;; + --mode) + MODE="$2" + shift 2 + ;; + *) + echo "Unknown parameter: $1" + exit 1 + ;; + esac +done + +# === Check required parameters === +if [[ -z "$SOURCE_DIR" || -z "$DEST_DIR" || -z "$MODE" ]]; then + echo "Usage: $0 --source /path/to/source --destination /path/to/destination --mode [bluray|dvd]" + exit 1 +fi + +# === Set presets based on mode === +case "$MODE" in + bluray) + PRESET_FILE="./profiles/BluRay H.265 HEVC.json" + PRESET_NAME="BluRay H.265 HEVC" + ;; + dvd) + PRESET_FILE="./profiles/DVD 720p H.265.json" + PRESET_NAME="DVD 720p H.265" + ;; + *) + echo "Invalid mode: $MODE (allowed: bluray, dvd)" + exit 1 + ;; +esac + +# === Recursively find all MKV files === +find "$SOURCE_DIR" -type f -name "*.mkv" | while read -r input_file; do + # Get relative path + rel_path="${input_file#$SOURCE_DIR/}" + rel_dir="$(dirname "$rel_path")" + + # Create matching directory structure in destination + mkdir -p "$DEST_DIR/$rel_dir" + + base_name="$(basename "$input_file" .mkv)" + output_file="$DEST_DIR/$rel_dir/$base_name.mkv" + + # Convert if output does not exist + if [ ! -f "$output_file" ]; then + echo "$(date +"%Y-%m-%d %H:%M:%S") - Converting: $rel_path" >> "$LOG_FILE" + "$HANDBRAKE_CLI" -i "$input_file" -o "$output_file" \ + --preset-import-file "$PRESET_FILE" --preset "$PRESET_NAME" >> "$LOG_FILE" 2>&1 + else + echo "$(date +"%Y-%m-%d %H:%M:%S") - Skipped (already exists): $rel_path" >> "$LOG_FILE" + fi +done + +echo "$(date +"%Y-%m-%d %H:%M:%S") - Finished!" >> "$LOG_FILE" + diff --git a/profiles/BluRay H.265 HEVC.json b/profiles/BluRay H.265 HEVC.json new file mode 100755 index 0000000..450036a --- /dev/null +++ b/profiles/BluRay H.265 HEVC.json @@ -0,0 +1,114 @@ +{ + "PresetList": [ + { + "AlignAVStart": false, + "AudioCopyMask": [ + "copy:aac" + ], + "AudioEncoderFallback": "av_aac", + "AudioLanguageList": [ + "any" + ], + "AudioList": [ + { + "AudioBitrate": 448, + "AudioCompressionLevel": 0, + "AudioEncoder": "ac3", + "AudioMixdown": "5point1", + "AudioNormalizeMixLevel": false, + "AudioSamplerate": "48", + "AudioTrackQualityEnable": false, + "AudioTrackQuality": -1, + "AudioTrackGainSlider": 0, + "AudioTrackDRCSlider": 0 + } + ], + "AudioSecondaryEncoderMode": true, + "AudioTrackSelectionBehavior": "all", + "ChapterMarkers": true, + "ChildrenArray": [], + "Default": false, + "FileFormat": "av_mkv", + "Folder": false, + "FolderOpen": false, + "Optimize": false, + "Mp4iPodCompatible": false, + "PictureCropMode": 0, + "PictureBottomCrop": 0, + "PictureLeftCrop": 0, + "PictureRightCrop": 0, + "PictureTopCrop": 0, + "PictureDARWidth": 0, + "PictureDeblockPreset": "off", + "PictureDeblockTune": "medium", + "PictureDeblockCustom": "strength=strong:thresh=20:blocksize=8", + "PictureDeinterlaceFilter": "decomb", + "PictureCombDetectPreset": "default", + "PictureCombDetectCustom": "", + "PictureDeinterlacePreset": "default", + "PictureDeinterlaceCustom": "", + "PictureDenoiseCustom": "", + "PictureDenoiseFilter": "off", + "PictureSharpenCustom": "", + "PictureSharpenFilter": "off", + "PictureSharpenPreset": "medium", + "PictureSharpenTune": "none", + "PictureDetelecine": "off", + "PictureDetelecineCustom": "", + "PictureColorspacePreset": "off", + "PictureColorspaceCustom": "", + "PictureChromaSmoothPreset": "off", + "PictureChromaSmoothTune": "none", + "PictureChromaSmoothCustom": "", + "PictureItuPAR": false, + "PictureKeepRatio": true, + "PicturePAR": "auto", + "PicturePARWidth": 0, + "PicturePARHeight": 0, + "PictureWidth": 1920, + "PictureHeight": 1080, + "PictureUseMaximumSize": true, + "PictureAllowUpscaling": false, + "PictureForceHeight": 0, + "PictureForceWidth": 0, + "PicturePadMode": "none", + "PicturePadTop": 0, + "PicturePadBottom": 0, + "PicturePadLeft": 0, + "PicturePadRight": 0, + "PresetName": "BluRay H.265 HEVC", + "Type": 1, + "SubtitleAddCC": false, + "SubtitleAddForeignAudioSearch": true, + "SubtitleAddForeignAudioSubtitle": false, + "SubtitleBurnBehavior": "foreign", + "SubtitleBurnBDSub": false, + "SubtitleBurnDVDSub": false, + "SubtitleLanguageList": [ + "any" + ], + "SubtitleTrackSelectionBehavior": "all", + "VideoAvgBitrate": 0, + "VideoColorMatrixCode": 0, + "VideoEncoder": "x265_10bit", + "VideoFramerateMode": "cfr", + "VideoGrayScale": false, + "VideoScaler": "swscale", + "VideoPreset": "slow", + "VideoTune": "", + "VideoProfile": "main10", + "VideoLevel": "5.1", + "VideoOptionExtra": "strong-intra-smoothing=0:rect=0:aq-mode=1:rd=4:psy-rd=0.75:psy-rdoq=4.0:rdoq-level=1:rskip=2", + "VideoQualityType": 2, + "VideoQualitySlider": 24, + "VideoMultiPass": true, + "VideoTurboMultiPass": true, + "x264UseAdvancedOptions": false, + "PresetDisabled": false, + "MetadataPassthru": false + } + ], + "VersionMajor": 59, + "VersionMicro": 0, + "VersionMinor": 0 +} \ No newline at end of file diff --git a/profiles/DVD 720p H.265.json b/profiles/DVD 720p H.265.json new file mode 100755 index 0000000..269822e --- /dev/null +++ b/profiles/DVD 720p H.265.json @@ -0,0 +1,114 @@ +{ + "PresetList": [ + { + "AlignAVStart": false, + "AudioCopyMask": [ + "copy:aac" + ], + "AudioEncoderFallback": "av_aac", + "AudioLanguageList": [ + "any" + ], + "AudioList": [ + { + "AudioBitrate": 448, + "AudioCompressionLevel": 0, + "AudioEncoder": "ac3", + "AudioMixdown": "stereo", + "AudioNormalizeMixLevel": false, + "AudioSamplerate": "auto", + "AudioTrackQualityEnable": false, + "AudioTrackQuality": -1, + "AudioTrackGainSlider": 0, + "AudioTrackDRCSlider": 0 + } + ], + "AudioSecondaryEncoderMode": true, + "AudioTrackSelectionBehavior": "all", + "ChapterMarkers": true, + "ChildrenArray": [], + "Default": false, + "FileFormat": "av_mkv", + "Folder": false, + "FolderOpen": false, + "Optimize": false, + "Mp4iPodCompatible": false, + "PictureCropMode": 0, + "PictureBottomCrop": 0, + "PictureLeftCrop": 14, + "PictureRightCrop": 14, + "PictureTopCrop": 8, + "PictureDARWidth": 738, + "PictureDeblockPreset": "off", + "PictureDeblockTune": "medium", + "PictureDeblockCustom": "strength=strong:thresh=20:blocksize=8", + "PictureDeinterlaceFilter": "decomb", + "PictureCombDetectPreset": "default", + "PictureCombDetectCustom": "", + "PictureDeinterlacePreset": "default", + "PictureDeinterlaceCustom": "", + "PictureDenoiseCustom": "", + "PictureDenoiseFilter": "off", + "PictureSharpenCustom": "", + "PictureSharpenFilter": "off", + "PictureSharpenPreset": "medium", + "PictureSharpenTune": "none", + "PictureDetelecine": "off", + "PictureDetelecineCustom": "", + "PictureColorspacePreset": "off", + "PictureColorspaceCustom": "", + "PictureChromaSmoothPreset": "off", + "PictureChromaSmoothTune": "none", + "PictureChromaSmoothCustom": "", + "PictureItuPAR": false, + "PictureKeepRatio": true, + "PicturePAR": "auto", + "PicturePARWidth": 16, + "PicturePARHeight": 15, + "PictureWidth": 1280, + "PictureHeight": 720, + "PictureUseMaximumSize": true, + "PictureAllowUpscaling": false, + "PictureForceHeight": 0, + "PictureForceWidth": 0, + "PicturePadMode": "none", + "PicturePadTop": 0, + "PicturePadBottom": 0, + "PicturePadLeft": 0, + "PicturePadRight": 0, + "PresetName": "DVD 720p H.265", + "Type": 1, + "SubtitleAddCC": false, + "SubtitleAddForeignAudioSearch": true, + "SubtitleAddForeignAudioSubtitle": false, + "SubtitleBurnBehavior": "foreign", + "SubtitleBurnBDSub": false, + "SubtitleBurnDVDSub": false, + "SubtitleLanguageList": [ + "any" + ], + "SubtitleTrackSelectionBehavior": "all", + "VideoAvgBitrate": 0, + "VideoColorMatrixCode": 0, + "VideoEncoder": "x265_10bit", + "VideoFramerateMode": "cfr", + "VideoGrayScale": false, + "VideoScaler": "swscale", + "VideoPreset": "slow", + "VideoTune": "", + "VideoProfile": "auto", + "VideoLevel": "auto", + "VideoOptionExtra": "", + "VideoQualityType": 2, + "VideoQualitySlider": 22, + "VideoMultiPass": true, + "VideoTurboMultiPass": true, + "x264UseAdvancedOptions": false, + "PresetDisabled": false, + "MetadataPassthru": false + } + ], + "VersionMajor": 59, + "VersionMicro": 0, + "VersionMinor": 0 +} \ No newline at end of file