Last active
October 23, 2023 16:27
-
-
Save Hashbrown777/a9e3053f6f9f70fab4f656a3f79a1839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Param($file) | |
| $file = Get-Item $file | |
| mkvinfo $file.FullName ` | |
| | &{ | |
| Begin { | |
| $current = $NULL | |
| } | |
| Process { | |
| if (!$current) { | |
| } | |
| elseif ($_ -match '^\| \+ ([^:]+): (.*)$') { | |
| switch -Exact ($Matches[1]) { | |
| 'Language (IETF BCP 47)' { | |
| $current['language'] = $Matches[2] | |
| } | |
| 'Name' { | |
| $current['name'] = $Matches[2] | |
| } | |
| 'Track type' { | |
| $current['type'] = $Matches[2] | |
| } | |
| 'Track number' { | |
| $current['track'] = ($Matches[2] -replace '[^0-9].*','') - 1 | |
| } | |
| 'Codec ID' { | |
| $current['extension'] = switch -Exact ($Matches[2] -replace '[^A-Z0-9_].*', '') { | |
| 'A_AAC' { '.aac' } | |
| 'V_MPEG4' { '.m4v' } | |
| 'S_TEXT' { '.srt' } | |
| } | |
| } | |
| } | |
| } | |
| else { | |
| $current['filename'] += '_' + ($current['track'] + 1) | |
| if ($current['name']) { | |
| $current['filename'] += '_' + $current['name'] | |
| } | |
| if ($current['type'] -in 'audio','subtitles') { | |
| $current['filename'] += (" ($($current['language']))","_$($current['language'])")[!$current['name']] | |
| } | |
| $current['filename'] += $current['extension'] | |
| $current | |
| $current = $NULL | |
| } | |
| if ($_ -match '^\| \+ Track') { | |
| $current = @{ | |
| filename = $file.BaseName | |
| } | |
| } | |
| } | |
| } ` | |
| | &{ | |
| Begin { | |
| $commands = $file.FullName,'tracks' | |
| } | |
| Process { | |
| $commands += $_['track'],$_['filename'] -join ':' | |
| } | |
| End { | |
| mkvextract @commands | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gi *.srt ` | |
| | %{ | |
| $item = $_ | |
| &{ | |
| 'WEBVTT' | |
| "Language: $($item.BaseName -replace '^.*_','' -replace '^.* *\((.*)\)$','$1')" | |
| '' | |
| gc $item | |
| } ` | |
| | %{ | |
| if ($_ -match '^((^|:)\d{2}){2,3},\d{3}(( --> |:)\d{2}){2,3},\d{3}(\s|$)') { | |
| ([Regex]',').Replace($_, '.', 2) | |
| } | |
| else { | |
| $_ | |
| } | |
| "`r`n" | |
| } ` | |
| | Out-File -NoNewline -LiteralPath ($_.BaseName + '.vtt') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ffmpeg \ | |
| -i "$1.mp4" \ | |
| -c:v libx264 \ | |
| -crf 23 \ | |
| -c:a aac \ | |
| -movflags faststart \ | |
| -maxrate 2M \ | |
| -bufsize 2M \ | |
| "$dest/$1.mp4" | |
| curl \ | |
| --form subrip_file=@"$1.srt" \ | |
| -o "$dest/$1.vtt" \ | |
| 'https://atelier.u-sub.net/srt2vtt/' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gi *.srt | %{ curl --form "subrip_file=@$($_.Name)" -o ($_.Name -replace 'srt$','vtt') 'https://atelier.u-sub.net/srt2vtt/' }MP4Box -add x_1.m4v -new x.mp4; MP4Box -add x_2.acc x.mp4