This batch script enhances the resolution of videos using GLSL shaders like Anime4K, leveraging the power of ffmpeg for processing. Once set up, the script can be called in several ways, however you'd like.
This script provides a purely Windows-based alternative for the core upscaling logic of Anime4K-GUI, allowing for batch processing and customization via script editing.
Run install-registry.bat, edit config.json, and right-click files in File Explorer.
- Video upscaling using configurable GLSL shaders (e.g., Anime4K, FSRCNNX).
- Batch processing of multiple video files or folders (optionally recursively).
- Easy right-click context menu integration.
- Command-line interface with options for customization.
- Drag-and-drop support for files and folders.
- Support for various video encoders: H.264, H.265, AV1 (CPU and GPU).
- Hardware acceleration via NVIDIA NVENC (CUDA) and AMD AMF (OpenCL).
- Preserves all audio and subtitle streams (requires MKV output for subtitles).
- Supports MKV, MP4, and AVI container formats for input/output.
- Automatic detection of
ffmpeg/ffprobevia system PATH (can be disabled). - Optional subtitle extraction using
extract-subs.bat. - Optional default subtitle track prioritization using
set-subs-priority.bat. - Optional default audio track prioritization using
set-audio-priority.bat. - Optional audio transcoding using
transcode-audio.bat. - Optional video remuxing using
remux.bat. - Advanced episode file renaming using
Rename-MediaFiles.ps1. - Test for GPU codec support using
Test-FFmpegGpuCodecs.ps1. There is a simple batch script for this, too:test-ffmpeg-gpu-codecs.bat.
- Operating System: Windows 10+
- ffmpeg.exe and ffprobe.exe: Required for video processing and analysis. Must be in the system PATH, the working directory, the installation folder, or specified within the script (
scripts/glsl-transcode.bat).--enable-vulkan --enable-libplaceboshould already be enabled in the build, but you can perform a quick test using theTest-FFmpegGpuCodecs.ps1script. - Vulkan: Required for GLSL shader application.
- GLSL Shaders: Standard Anime4K upscaling/sharpening shader files (
.glsl) are provided in this repository.
Supported ffmpeg and ffprobe binaries can be found in Releases.
First, download the latest Anime4K-Batch.zip (or clone the repository).
There are four main ways to install and use the Anime4K-Batch.bat script:
1. Add to Context Menu (Recommended)
-
Standard: Admin rights required.
-
Execute
install_registry.bat. That's it! The script should now be available whenever you right-click on video files and folders. -
This will add two main context menu entries:
Anime4K-Batch: Executes scripts directly using the settings inconfig.json.Anime4K-Batch (Prompt): Opens a command prompt, allowing you to enter additional command-line arguments for that specific run.
-
If you wish to remove Anime4K-Batch from the context menu, execute
uninstall_registry.bat. -
(Optional) To disable the new Windows 11 context menu for easier access, run this in Command Prompt (
cmd.exe):REG ADD "HKCU\Software\Classes\CLSID{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /ve /f
-
(Optional) If you wish to add specific flags to the utility scripts (e.g., remux recursively using
remux.bat), edit the\commandlines before executinginstall_registry.bat. For example (take note of the-r):REG ADD "%ROOT_STORE%\Ani4K.Remux\command" /ve /d "\"%BASE_DIR%\scripts\remux.bat\" -r \"%%1\" & pause" /f
-
-
Basic: No admin rights required.
-
Open PowerShell and set this variable to your path to the script:
$path = "C:\path\to\Anime4K-Batch.bat"
-
Then execute this command:
New-Item -Path "Registry::HKEY_CURRENT_USER\Software\Classes\*\shell\Transcode with Anime4K\command" -Value "$path ""%1""" -Force; New-Item -Path "Registry::HKEY_CURRENT_USER\Software\Classes\directory\shell\Transcode content with Anime4K\command" -Value "$path ""%1""" -Force
-
The script should now be available whenever you right-click on video files and folders.
-
If you wish to remove Anime4K-Batch from the context menu, run the following command:
Remove-Item -Path "Registry::HKEY_CURRENT_USER\Software\Classes\*\shell\Transcode with Anime4K" -Force; Remove-Item -Path "Registry::HKEY_CURRENT_USER\Software\Classes\directory\shell\Transcode content with Anime4K" -Force
-
(Optional) To disable the new Windows 11 context menu for easier access:
New-Item -Path "Registry::HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" -Value "" -Force
-
2. Drag and Drop
- Select one or more video files or folders containing videos.
- Drag them directly onto the
Anime4K-Batch.batfile icon. Processing will start with the settings defined in your configuration.
3. Open with Anime4K-Batch.bat
- Right-click on a video file and select "Open with" from the context menu (not available for folders or multiple files).
- Select "Choose an app on your PC".
- Choose
Anime4K-Batch.batand click "Once". - The script will start with the settings defined in your configuration.
4. Command Line
-
Open Command Prompt (
cmd.exe) or PowerShell. -
Navigate to the script's directory or use its absolute path.
-
Execute the script with optional flags and options, followed by paths to video files and/or folders.
-
Arguments are passed to the underlying script(s) (
scripts/glsl-transcode.batand optionallyscripts/extract-subs.bat).C:\path\to\Anime4K-Batch.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...
Using these options/flags override settings defined inside the script(s) for that specific run. Place them before the file/folder paths.
Options & Flags:
-w <width>: Override target width.-h <height>: Override target height.-shader <file>: Override shader filename (relative to shader path).-shaderpath <path>: Override the base path for shaders.-codec-prof <type>: Override encoder profile (e.g., nvidia_h265, cpu_av1).-cqp <value>: Override the Constant Quantization Parameter (quality, 0-51).-container <type>: Override output container format (avi,mkv,mp4).-suffix <string>: Suffix to append after the base filename part (default:_upscaled).-sformat <string>: Alias of-formatoption forextract-subs.bat.-acodec <type>: Audio codec for transcoding (e.g.,aac,ac3,flac). If not specified, audio will be copied.-abitrate <value>: Audio bitrate for transcoding (e.g.,192k,256k). Only applies if-acodecis specified.-achannels <value>: Number of audio channels (e.g.,2for stereo,6for 5.1). Only applies if-acodecis specified.-alang <list>: Comma-separated audio language priority for-aprioritize(e.g., "jpn,eng").-atitle <list>: Comma-separated audio title priority for-aprioritize.-slang <list>: Comma-separated subtitle language priority for-sprioritize.-stitle <list>: Comma-separated subtitle title priority for-sprioritize.-r: (Flag) Process folders recursively.-f: (Flag) Force overwrite if an output file with the target name already exists.-delete: (Flag) Delete original file after successful transcode (USE WITH CAUTION!).-replace: (Flag) Replace original file with processed version (USE WITH CAUTION!).-sprioritize: (Flag) Set default subtitle track on the input file usingset-subs-priority.batbefore transcoding.-extract-subs: (Flag) Extract subtitles usingextract-subs.batbefore transcoding.-aprioritize: (Flag) Set default audio track on the output file usingset-audio-priority.batafter transcoding.
These examples demonstrate various command-line possibilities. While some are based on the default settings, others showcase specific flags and options. Note that features like subtitle extraction and default audio setting require enabling them via flags (-extract-subs, -aprioritize, etc.) or modifying Anime4K-Batch.bat (see Enabling Subtitle Extraction). Note that, without editing the script, Anime4K-Batch.bat acts as an alias for glsl-transcode.bat. Adjust paths and options as needed.
-
Upscale to 4K, set default subtitle to English "Full" track, extract it, then set default audio to Japanese "Commentary" track:
Anime4K-Batch.bat -w 3840 -h 2160 -sprioritize -slang "eng" -stitle "Full" -extract-subs -aprioritize -alang "jpn" -atitle "Commentary" "C:\path\to\video.mkv"
-
Upscale, extract subs without specifying language, and force overwrite:
Anime4K-Batch.bat -extract-subs -sformat "SOURCE.title" -f "C:\path\to\video.mkv"
-
Upscale to 4K with CQP 24 and transcode audio to AAC with default English priority:
Anime4K-Batch.bat -w 3840 -h 2160 -cqp 24 -aprioritize -alang "eng" -acodec aac "C:\path\to\video.mkv"
-
Transcode audio to AAC with a bitrate of 192k and 2 channels, while upscaling to 4K:
Anime4K-Batch.bat -w 3840 -h 2160 -acodec aac -abitrate 192k -achannels 2 "C:\path\to\video.mkv"
-
Use default settings from glsl-transcode.bat but process folders recursively and extract subs:
Anime4K-Batch.bat -r -extract-subs "C:\path\to\folder" "C:\path\to\another\video.mp4"
-
Upscale recursively, extract subtitles, set default audio, and delete original files after successful transcode (USE WITH CAUTION!):
Anime4K-Batch.bat -r -extract-subs -aprioritize -delete "C:\path\to\folder"
Note: Running the script twice in the same directory should double the worker threads/cores, without any conflict or additional overhead. From my experience (NVIDIA V100), GPU usage isn't maxed unless two processes are running at the same time.
Using this method, Anime4K_ModeA_A-fast.glsl (Fast) performs at more than double the speed of Anime4K_ModeA_A.glsl (HQ), whereas trying to run two HQ transcoding processes tends to cause a bottleneck with Graphics performance, due to the nature of GLSL shaders.
Upscaled video files are saved in the same directory as their corresponding input files. The filename will be the original name plus the configured OUTPUT_SUFFIX (default: _upscaled) in glsl-transcode.bat. Extracted subtitles (if enabled) are also saved in the same directory, named according to the -format option in extract-subs.bat.
The primary method for configuring Anime4K-Batch is by editing the config.json file, located in the root directory alongside Anime4K-Batch.bat. This file allows you to set persistent default values for nearly all script options, making it the recommended way to customize behavior.
Settings in config.json are automatically loaded by the scripts. For temporary overrides for a specific run, or for scripting particular behaviors, command-line flags can be used.
1. Using config.json (Recommended)
Edit the config.json file using any text editor. This file uses a simple JSON format to define various settings. Changes saved to config.json will apply to subsequent runs of Anime4K-Batch.bat and its associated scripts (like glsl-transcode.bat, extract-subs.bat, etc.), provided they support reading this configuration file.
Example config.json structure:
{
// --- Input/Output ---
"Suffix": "_upscaled", // Suffix to append to output filenames.
"Container": "mkv", // Output container format (e.g., 'mkv', 'mp4').
"Force": false, // Force overwrite existing output files.
"Recurse": false, // Process folders recursively.
// --- Transcoding Settings ---
"TargetResolutionW": 3840, // Target output width.
"TargetResolutionH": 2160, // Target output height.
"ShaderFile": "Anime4K_ModeA_A-fast.glsl", // Shader filename located in ShaderBasePath.
"EncoderProfile": "nvidia_h265", // Encoder profile (e.g., cpu_h264, nvidia_h265).
"CQP": 24, // Constant Quantization Parameter (quality).
// ... and many more settings.
// For a full list and detailed descriptions, please refer to the actual 'config.json' file.
}Ensure your config.json is valid JSON (single-line comments are permitted).
2. Command-Line Flags (Respective values override config.json)
You can override settings from config.json (and any internal script defaults) by providing command-line flags when executing Anime4K-Batch.bat. These flags apply only to that specific run and do not modify config.json.
This is useful for:
- Testing different settings without changing your defaults.
- Scripting specific one-off tasks.
For a comprehensive list of available command-line options and flags, their functions, and examples, please refer to the Command Line Options & Flags section under "Installation & Usage".
Example:
If config.json sets TargetResolutionW to 1920, but you want to upscale a specific batch to 3840, you can run:
Anime4K-Batch.bat -w 3840 "path\to\your\videos"Additionally, you can modify the main Anime4K-Batch.bat script itself to include default flags in its execution line for glsl-transcode.bat or other sub-scripts. This is an older method but still functional. Flags set this way will also override config.json settings.
Example (editing Anime4K-Batch.bat):
:: Original line might be:
:: call "%~dp0\scripts\glsl-transcode.bat" %* ^
:: Modified to always
:: 1. Recurse and
:: 2. Force overwrite:
call "%~dp0\scripts\glsl-transcode.bat" -r -f %* ^However, managing defaults through config.json is generally cleaner.
| NVIDIA (NVENC) | AMD (AMF) | Intel (QSV) | CPU (x264/x265/SVT-AV1) | |
|---|---|---|---|---|
| H.264 | ✅ | ✅ | ✅ | ✅ |
| H.265 | ✅ | ✅ | ✅ | ✅ |
| AV1 | ✅ | ✅ |
Note on Hardware Acceleration:
- VAAPI / Vulkan: These methods should be compatible with all GPUs.
- NVIDIA/AMD AV1: Supported only on RTX 4000+ and RX 7000+ series respectively.
- Intel QSV / VAAPI / Vulkan: These methods are currently untested but are expected to work on compatible hardware.
- You can verify your specific hardware and
ffmpegbuild compatibility by running theTest-FFmpegGpuCodecs.ps1utility.
Subtitle handling is managed by two separate flags that perform actions in a specific order:
-
-sprioritize(Optional):- This flag triggers
set-subs-priority.ps1to modify the input file in-place. - It reorders the internal subtitle tracks based on language and title, marking the best match as default. This is useful for ensuring players select the correct subtitle track automatically.
- (optional) Use
-slangand-stitleto specify priorities.
- This flag triggers
-
-extract-subs(Optional):- This flag triggers
extract-subs.batto save subtitle tracks as external.srt,.ass, etc., files. - This is highly recommended if your output container is
mp4, which has poor subtitle support. - If you also ran
-sprioritize, the extracted files will reflect the new, correct track order. - (optional) Use
-sformatto control the output filename pattern.
- This flag triggers
Similar to subtitle extraction, setting the default audio track priority using set-audio-priority.bat is primarily controlled via flags passed to glsl-transcode.bat (either directly or via Anime4K-Batch.bat).
- Use the
-aprioritizeFlag (Optional):- (optional) Use
-slangand-stitleto specify priorities.
- (optional) Use
Join-Shaders.ps1
This PowerShell script (Join-Shaders.ps1) allows you to combine multiple GLSL shaders into a single file compatible with ffmpeg's glsl filter (and other applications like MPV). This is useful if you want to chain multiple shader effects for the ShaderFile setting in the config.
MPV Shaderlist Format: ~~/shader1.glsl;~~/shader2.glsl;~~/shader3.glsl
Standalone Usage / Command Line Options:
# Combine several Anime4K shaders from MPV's config folder into one file
C:\path\to\Join-Shaders.ps1 -BaseDir "$env:AppData\mpv\" -FileListString "~~/shaders/Anime4K_Clamp_Highlights.glsl;~~/shaders/Anime4K_Restore_CNN_M.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_M.glsl;~~/shaders/Anime4K_AutoDownscalePre_x2.glsl;~~/shaders/Anime4K_AutoDownscalePre_x4.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_S.glsl" -OutputFile ".\shaders\Anime4K_ComplexChain.glsl"You could then use the flag -shader Anime4K_ComplexChain.glsl or set "ShaderFile": "Anime4K_ModeA_A-fast.glsl" in config.json.
This is purely a PowerShell script and is not wrapped by a .bat file.
extract-subs.bat
This batch script (extract-subs.bat) extracts subtitle tracks from video files using ffprobe and ffmpeg. It's designed to be run before glsl-transcode.bat if you want to preserve subtitles, especially when changing container formats (e.g., MKV to MP4).
See Enabling Subtitle Extraction (applies to both Anime4K-Batch.bat and glsl-transcode.bat).
Standalone Usage / Command Line Options:
You can also run extract-subs.bat directly.
C:\path\to\extract-subs.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...-format <string>: Output filename format (default:SOURCE.lang.title.dispo, following Jellyfin's naming convention). Placeholders:SOURCE: Original video filename (without extension).lang: Subtitle language code (e.g.,eng,jpn).title: Subtitle track title, if available.dispo: Subtitle track disposition, if available (currently supports 'default' and 'forced').
-suffix <string>: Suffix to append after the base filename part (default:_upscaled).- Note: When running
extract-subs.batstandalone (not viaAnime4K-Batch.bat), if you don't want any suffix added, use-suffix "".
- Note: When running
-r: (Flag) Process folders recursively.-f: (Flag) Force overwrite existing subtitle files.
remux.bat
This batch script (remux.bat) remuxes video files into a different container format (e.g., MKV to MP4) while copying compatible streams (video, audio, subtitles, attachments, data) based on the target container's capabilities. It does not re-encode the video or audio, making it an extremely fast operation.
Standalone Usage / Command Line Options:
C:\path\to\remux.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...-container <string>: Output container extension (default:mp4).-r: (Flag) Process folders recursively.-f: (Flag) Force overwrite existing output files.
transcode-audio.bat
This batch script (transcode-audio.bat) transcodes audio streams within video files to a specified codec and bitrate, while copying the video stream. This is useful for standardizing audio formats or reducing file size.
Standalone Usage / Command Line Options:
C:\path\to\transcode-audio.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...-codec <string>: Target audio codec (default:aac).-bitrate <string>: Target audio bitrate (default:192k).-delete: (Flag) Delete original file after successful processing (mutually exclusive with-replace).-replace: (Flag) Replace original file (mutually exclusive with-delete).-r: (Flag) Process folders recursively.
set-audio-priority.bat
This batch script (set-audio-priority.bat) sets the default track based on language priority using ffprobe and ffmpeg. It remuxes the file, placing the highest priority audio track first and marking it as default. This is useful for ensuring media players select the desired language automatically.
It can be triggered automatically during transcode by using the -aprioritize flag in glsl-transcode.bat. The language priority can be specified using the -alang flag and the title priority using the -atitle flag in glsl-transcode.bat.
Standalone Usage / Command Line Options:
C:\path\to\set-audio-priority.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...-lang "<list>": Comma-separated language priority (default:"jpn,chi,kor,eng"). Must be quoted if it contains commas.-title "<list>": Comma-separated title priority (e.g.,"Commentary,Surround"). Must be quoted if it contains commas.-suffix <string>: Suffix for the output filename (default:_areordered). Only used if-replaceis not active.-r: (Flag) Process folders recursively.-f: (Flag) Force overwrite existing output files.-delete: (Flag) Delete original file after successful processing (mutually exclusive with-replace).-replace: (Flag) Replace original file with the processed version (enabled by default, mutually exclusive with-delete).
set-subs-priority.bat
This batch script (set-subs-priority.bat) sets the default subtitle track based on language and title priority. It remuxes the file, placing the highest priority subtitle track first and marking it as default. This is useful for ensuring media players select the desired language automatically.
It can be triggered automatically during transcode by using the -sprioritize flag in glsl-transcode.bat. The language priority can be specified using the -slang flag and the title priority using the -stitle flag in glsl-transcode.bat.
Standalone Usage / Command Line Options:
C:\path\to\set-subs-priority.bat [options] [flags] "path\to\folder" "path\to\video.mkv" ...-lang "<list>": Comma-separated language priority (default:"eng,jpn"). Must be quoted if it contains commas.-title "<list>": Comma-separated title priority (e.g.,"Full,Dialogue,Signs"). Must be quoted if it contains commas.-suffix <string>: Suffix for the output filename (default:_sreordered). Only used if-replaceis not active.-r: (Flag) Process folders recursively.-f: (Flag) Force overwrite existing output files.-delete: (Flag) Delete original file after successful processing (mutually exclusive with-replace).-replace: (Flag) Replace original file with the processed version (enabled by default, mutually exclusive with-delete).
Rename-MediaFiles.ps1
This PowerShell script (Rename-MediaFiles.ps1) renames media files into a standard TV series format (SxxExx), which is useful for media servers like Plex or Jellyfin. It intelligently finds episode numbers (including decimals for specials) in existing filenames and reformats them.
The script can automatically detect the season number from the parent folder name (e.g., My Show Season 1) and the starting episode number from the files themselves (e.g., for absolute-ordered seasons that start at episode 25). These can also be manually overridden.
Standalone Usage / Command Line Options:
# Preview a rename for files in 'D:\TV Shows\My Series', auto-detecting the season and first episode.
C:\path\to\Rename-MediaFiles.ps1 -Path "D:\TV Shows\My Series" -WhatIf
# Rename files in current directory, auto-detecting the season and first episode.
C:\path\to\Rename-MediaFiles.ps1
# Rename files for Season 2, where the first episode is 25.
C:\path\to\Rename-MediaFiles.ps1 -SeasonNumber 2 -FirstEpisode 25 -Path "D:\TV Shows\My Series"-SeasonNumber <number>: (Optional) The season number to use. If not provided, it's auto-detected from the parent folder name (Season XorS_X_).-Path <path>: (Optional) The directory containing the files to rename. Defaults to the current directory.-Regex <pattern>(Optional): Provide a custom regex to find the episode number. The episode number must be the first capture group and the rest of the filename must be the second.-Extensions <exts>(Optional): Comma-separated list of file extensions to process.-FirstEpisode <number>: (Optional) Sets the starting episode number for absolute numbering. Overrides auto-detection.-UseTitle: (Flag) Use the video's title metadata instead of its filename to find the episode number. Requiresffprobe.-OrderByAlphabet: (Flag) Ignore episode detection and rename files sequentially based on alphabetical order.-NoDetectFirstEpisode: (Flag) Disables auto-detection of the first episode, assuming the first episode is1.-CombineData: (Flag) Retrieves data from both filename and title metadata. The priority of source/episode depends on the-UseTitleflag.-EditTitle: (Flag) Edits the file's title metadata instead of the filename.-WhatIf: (Flag) Preview changes without actually renaming files. Always use this first!
This is purely a PowerShell script and is not wrapped by a .bat file.
Test-FFmpegGpuCodecs.ps1
This PowerShell script (Test-FFmpegGpuCodecs.ps1) discovers, tests, and categorizes available FFmpeg GPU-accelerated video encoders. It automates checking your ffmpeg build and hardware for compatibility with various codecs (NVENC, AMF, QSV, etc.). This is useful for verifying that your setup can take advantage of hardware acceleration.
Standalone Usage:
C:\path\to\Test-FFmpegGpuCodecs.ps1The script will output a report of successful and failed codecs.
This is purely a PowerShell script and is not wrapped by a .bat file.
- Subtitles: If input files contain subtitle streams, you have a few options:
- Use
mkvas theContainerinconfig.jsonto preserve them within the video container. - Enable subtitle extraction to save them as separate files using
extract-subs.bat(see Controlling Subtitles). This is recommended if outputting to e.g.mp4oravi, which have poor internal subtitle support.
- Use
- HDR: While the script attempts basic detection, proper HDR preservation is best handled by AV1 encoders (
cpu_av1,nvidia_av1,amd_av1). Using other encoders with HDR input may result in non-HDR output. - Error Handling: Basic checks are included, but complex
ffmpegerrors might require manual inspection of the command output.
- Based on the core
ffmpeglogic in Anime4K-GUI. - Utilizes Anime4K GLSL shaders (or other compatible shaders provided by the user).
- Relies heavily on the FFmpeg project.
- Google for Gemini, which was helpful in creating this README :D
- Assets: "Transcode" from icon-icons, "Extract" from Veryicon, "Remux" from The Noun Project


