Skip to content

Instantly share code, notes, and snippets.

@riskeez
Created December 26, 2024 22:49
Show Gist options
  • Save riskeez/ed3020d2a6cff2294f034aa1b33bdf81 to your computer and use it in GitHub Desktop.
Save riskeez/ed3020d2a6cff2294f034aa1b33bdf81 to your computer and use it in GitHub Desktop.
Embed subtitles (e.g., .ass) into MKV files and force the display of the subtitles
# Define the path to mkvmerge.exe
$mkvmergePath = "C:\mkvmerge.exe"
$outputFolder = "Out"
# Create the output folder if it doesn't exist
if (-not (Test-Path -Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder
}
# Loop through all .mkv files in the current directory
Get-ChildItem -Path . -Filter *.mkv | ForEach-Object {
$inputFile = $_.FullName
$subtitleFile = ($_.BaseName + ".ass")
$outputFile = Join-Path -Path $outputFolder -ChildPath $_.Name
if (-not (Test-Path $subtitleFile)) {
Write-Warning "Subtitle file not found for $inputFile. Skipping..."
continue
}
# Run mkvmerge to embed subtitles
& $mkvmergePath `
--output $outputFile `
--forced-display-flag 2:yes `
$inputFile $subtitleFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment