Skip to content

Instantly share code, notes, and snippets.

@meoow
Last active January 5, 2023 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoow/5d91bdc4e7b69dc991cab421a248551a to your computer and use it in GitHub Desktop.
Save meoow/5d91bdc4e7b69dc991cab421a248551a to your computer and use it in GitHub Desktop.
Extract all subtitles using powershell, ffprobe.exe and ffmpeg.exe
powershell -noprofile -command "& {Param([string]$f);[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;[Console]::WindowHeight=5;[Console]::BufferHeight=10;[Console]::WindowWidth=40;[Console]::BufferWidth=40;$fpath = Get-ChildItem $f;$subtitles=(ffprobe.exe -v 0 -show_streams -of json -i $fpath | ConvertFrom-Json).streams | Where-Object codec_type -eq """"subtitle""""; if ( $subtitles.GetType().BaseType.ToString() -eq """"System.Object"""") { if($subtitles.codec_name -eq """"ass"""") { $ext=""""ass"""" } else { $ext=""""srt"""" }; $stfile = """"{0}\{1}.{2}"""" -f $fpath.DirectoryName,$fpath.BaseName,$ext; Write-Output (""""{0}.{1}"""" -f $fpath.BaseName,$ext); ffmpeg.exe -v error -i $fpath -map 0:$($subtitles.index.ToString()) -y $stfile; } elseif ($subtitles.GetType().BaseType.ToString() -eq """"System.Array"""") { foreach ($subtitle in $subtitles) { if($subtitle.codec_name -eq """"ass""""){ $ext=""""ass"""" } else { $ext=""""srt"""" }; $name = $subtitle.tags.title; if($name -eq $null -or $name -eq ''){ $name=$subtitle.index.ToString() } $stfile=""""{0}\{1}[{2}].{3}"""" -f $fpath.DirectoryName,$fpath.BaseName,$name,$ext; Write-Output (""""{0}[{1}].{2}"""" -f $fpath.BaseName,$name,$ext); ffmpeg.exe -v error -i $fpath -map 0:$($subtitle.index.ToString()) -y $stfile }}}" -args -f """inputfile"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment