Replace with newest version from Github 2/2

This commit is contained in:
2026-04-13 13:06:40 +02:00
parent c15aed1b87
commit 1d7b8b22fd
2 changed files with 893 additions and 873 deletions

View File

@@ -6,11 +6,14 @@ This repository contains Python scripts for batch-processing MKV files to encode
## Scripts Overview ## Scripts Overview
* **`aom_opus_encoder.py`**: Uses the `aom` encoder (specifically designed for the `aom-psy101` fork) via `av1an`. It is tuned for high perceptual quality with specific psychovisual parameters and film grain synthesis. * **`aom_opus_encoder.py`**: Uses the `aom` encoder (specifically designed for the `aom-psy101` fork) via `av1an`. It is tuned for high perceptual quality with specific psychovisual parameters and film grain synthesis.
* **`svt_opus_encoder.py`**: Uses the `svt-av1` encoder (specifically designed for the `SVT-AV1-Essential` fork) via `av1an`. It provides a good balance between encoding speed and quality, and allows customization of speed, quality, and film-grain presets from the command line. * **`svt_opus_encoder.py`**: Uses the `svt-av1` encoder (specifically designed for the `SVT-AV1-Essential` fork) via `av1an`. It provides a good balance between encoding speed and quality, and allows customization of preset, crf, and film-grain from the command line.
* **`hdr_svt_opus_encoder.py`**: A specialized script for 4K HDR movies using the `SVT-AV1-Essential` encoder. It is designed for pre-processed CFR inputs, preserves original surround sound audio without downmixing, and retains HDR metadata.
## Encoding Parameters Documentation ## Encoding Parameters Documentation
For detailed information on the specific FFmpeg arguments, audio downmixing logic, VFR-to-CFR conversion processes, and the special SVT-AV1/AomEnc parameters used by these scripts, please refer to the [`parameters.md`](parameters.md) file. For detailed information on the specific FFmpeg arguments, audio downmixing logic, VFR-to-CFR conversion processes, and the special SVT-AV1/AomEnc parameters used by the standard scripts, please refer to the [`parameters.md`](parameters.md) file.
For the HDR-specific encoder parameters and settings used in `hdr_svt_opus_encoder.py`, please see [`parameters_hdr.md`](parameters_hdr.md).
## Prerequisites ## Prerequisites
@@ -48,33 +51,46 @@ Both scripts require several external tools to be installed and available in you
## Usage ## Usage
Place the script in the directory containing your `.mkv` files and execute it. It is highly recommended to place these scripts (or symbolic links to them) in a directory that is included in your system's `PATH` variable (e.g., `~/bin` on Linux/macOS, or a custom Scripts folder on Windows). This allows you to run the commands directly from any directory.
To use the scripts, open your terminal (bash, PowerShell, etc.), navigate to the folder containing your `.mkv` files, and simply type the name of the script.
### `aom_opus_encoder.py` ### `aom_opus_encoder.py`
```bash ```bash
python aom_opus_encoder.py [options] aom_opus_encoder.py [options]
``` ```
**Options:** **Options:**
* `--no-downmix`: Preserve original audio channel layout (do not downmix 5.1/7.1 to stereo). * `--no-downmix`: Preserve original audio channel layout (do not downmix 5.1/7.1 to stereo).
* `--autocrop`: Automatically detect and crop black bars from the video. * `--autocrop`: Automatically detect and crop black bars from the video.
* `--grain <int>`: Set the `photon-noise` value for grain synthesis (default: 8). * `--grain <int>`: Set the `photon-noise` value for grain synthesis (default: 8).
* `--crf <int>`: Set the constant quality level (`cq-level`) for video encoding (default: 28). * `--crf <int>`: Set the constant quality level (`cq-level`) for video encoding (default: 25).
### `svt_opus_encoder.py` ### `svt_opus_encoder.py`
```bash ```bash
python svt_opus_encoder.py [options] svt_opus_encoder.py [options]
``` ```
**Options:** **Options:**
* `--no-downmix`: Preserve original audio channel layout (do not downmix 5.1/7.1 to stereo). * `--no-downmix`: Preserve original audio channel layout (do not downmix 5.1/7.1 to stereo).
* `--autocrop`: Automatically detect and crop black bars from the video. * `--autocrop`: Automatically detect and crop black bars from the video.
* `--speed <str>`: Set the SVT-AV1 encoding speed preset (e.g., `slower`, `slow`, `medium`, `fast`, `faster`). Defaults to `slower`. * `--preset <int>`: Set the SVT-AV1 encoding speed preset (e.g., 0-13). Lower is slower and yields better compression. Defaults to 1.
* `--quality <str>`: Set the SVT-AV1 encoding quality preset (e.g., `lowest`, `low`, `medium`, `high`, `higher`). Defaults to `medium`. * `--crf <int>`: Set the SVT-AV1 Constant Rate Factor (CRF) for video quality (e.g., 0-63). Lower is better quality. Defaults to 30.
* `--grain <int>`: Set the `film-grain` value. Adjusts the film grain synthesis level. Defaults to 6. * `--grain <int>`: Set the `film-grain` value. Adjusts the film grain synthesis level. Defaults to 6.
### `hdr_svt_opus_encoder.py`
```bash
hdr_svt_opus_encoder.py [options]
```
**Options:**
* `--preset <int>`: Set the SVT-AV1 encoding speed preset (e.g., 0-13). Lower is slower and yields better compression. Defaults to 1.
* `--crf <int>`: Set the SVT-AV1 Constant Rate Factor (CRF) for video quality (e.g., 0-63). Lower is better quality. Defaults to 30.
* `--grain <int>`: Set the `film-grain` value. Adjusts the film grain synthesis level. Defaults to 12.
## Process Workflow ## Process Workflow
1. **Preparation**: Scans for `.mkv` files and checks for required tools. 1. **Preparation**: Scans for `.mkv` files and checks for required tools.

View File

@@ -1,4 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Note: This script is configured to use a custom version of SVT-AV1
# called "SVT-AV1-Essential" from https://github.com/nekotrix/SVT-AV1-Essential
import os import os
import sys import sys
import subprocess import subprocess
@@ -20,18 +24,18 @@ DIR_CONV_LOGS = Path("conv_logs") # Directory for conversion logs
REMUX_CODECS = {"aac", "opus"} # Using a set for efficient lookups REMUX_CODECS = {"aac", "opus"} # Using a set for efficient lookups
SVT_AV1_PARAMS = { SVT_AV1_PARAMS = {
"speed": "slower", # "slower", "slow", "medium", "fast", "faster" "preset": 2, # Speed preset. Lower is slower and yields better compression efficiency.
"quality": "medium", # "higher", "high", "medium", "low", "lower" "crf": 30, # Constant Rate Factor (CRF). Lower is better quality.
"film-grain": 6, "film-grain": 6, # Film grain synthesis level. Adds artificial grain to preserve detail and prevent banding.
"color-primaries": 1, "color-primaries": 1, # BT.709 color primaries (Standard SDR).
"transfer-characteristics": 1, "transfer-characteristics": 1, # BT.709 transfer characteristics (Standard SDR).
"matrix-coefficients": 1, "matrix-coefficients": 1, # BT.709 matrix coefficients (Standard SDR).
"scd": 0, # Scene change detection OFF for Av1an use "scd": 0, # Scene change detection OFF (av1an handles scene cuts).
"keyint": 0, # Keyframe interval, 0 disables automatic keyframes placement at a constant interval "keyint": 0, # Keyframe interval OFF (av1an inserts keyframes).
"lp": 2, # Level of parallelism "lp": 2, # Logical Processors to use per av1an worker.
"auto-tiling": 1, # Auto tiling ON "auto-tiling": 1, # Automatically determine the number of tiles based on resolution.
"tune": 1, # 0 = VQ, 1 = PSNR, 2 = SSIM "tune": 1, # 0 = VQ, 1 = PSNR, 2 = SSIM (SVT-AV1-Essential default recommended).
"progress": 2, # Detailed progress output "progress": 2, # Detailed progress output.
} }
def check_tools(): def check_tools():
@@ -470,14 +474,14 @@ def detect_autocrop_filter(input_file, significant_crop_threshold=5.0, min_crop=
return None return None
return _analyze_video_cropdetect(input_file, duration, width, height, max(1, os.cpu_count() // 2), significant_crop_threshold, min_crop, debug) return _analyze_video_cropdetect(input_file, duration, width, height, max(1, os.cpu_count() // 2), significant_crop_threshold, min_crop, debug)
def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None): def main(no_downmix=False, autocrop=False, preset=None, crf=None, grain=None):
check_tools() check_tools()
# Override default SVT-AV1 params if provided via command line # Override default SVT-AV1 params if provided via command line
if speed: if preset is not None:
SVT_AV1_PARAMS["speed"] = speed SVT_AV1_PARAMS["preset"] = preset
if quality: if crf is not None:
SVT_AV1_PARAMS["quality"] = quality SVT_AV1_PARAMS["crf"] = crf
if grain is not None: if grain is not None:
SVT_AV1_PARAMS["film-grain"] = grain SVT_AV1_PARAMS["film-grain"] = grain
@@ -766,8 +770,8 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Batch-process MKV files with resumable video encoding, audio downmixing, per-file logging, and optional autocrop.") parser = argparse.ArgumentParser(description="Batch-process MKV files with resumable video encoding, audio downmixing, per-file logging, and optional autocrop.")
parser.add_argument("--no-downmix", action="store_true", help="Preserve original audio channel layout.") parser.add_argument("--no-downmix", action="store_true", help="Preserve original audio channel layout.")
parser.add_argument("--autocrop", action="store_true", help="Automatically detect and crop black bars from video using cropdetect.") parser.add_argument("--autocrop", action="store_true", help="Automatically detect and crop black bars from video using cropdetect.")
parser.add_argument("--speed", type=str, help="Set the encoding speed. Possible values: slower, slow, medium, fast, faster.") parser.add_argument("--preset", type=int, help=f"Set the encoding preset. Lower is slower/better compression. (default: {SVT_AV1_PARAMS['preset']})")
parser.add_argument("--quality", type=str, help="Set the encoding quality. Possible values: lowest, low, medium, high, higher.") parser.add_argument("--crf", type=int, help=f"Set the Constant Rate Factor (CRF). Lower is better quality. (default: {SVT_AV1_PARAMS['crf']})")
parser.add_argument("--grain", type=int, help="Set the film-grain value (number). Adjusts the film grain synthesis level.") parser.add_argument("--grain", type=int, help=f"Set the film-grain value (number). Adjusts the film grain synthesis level. (default: {SVT_AV1_PARAMS['film-grain']})")
args = parser.parse_args() args = parser.parse_args()
main(no_downmix=args.no_downmix, autocrop=args.autocrop, speed=args.speed, quality=args.quality, grain=args.grain) main(no_downmix=args.no_downmix, autocrop=args.autocrop, preset=args.preset, crf=args.crf, grain=args.grain)