Initial Commit
This commit is contained in:
121
README.md
Normal file
121
README.md
Normal file
@@ -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.
|
||||
|
||||
74
hanbrake-batch-converteer.sh
Executable file
74
hanbrake-batch-converteer.sh
Executable file
@@ -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"
|
||||
|
||||
114
profiles/BluRay H.265 HEVC.json
Executable file
114
profiles/BluRay H.265 HEVC.json
Executable file
@@ -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
|
||||
}
|
||||
114
profiles/DVD 720p H.265.json
Executable file
114
profiles/DVD 720p H.265.json
Executable file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user