Created
January 22, 2024 13:17
-
-
Save elderica/2eccdef330f62afcf4c8b01a97adeeb8 to your computer and use it in GitHub Desktop.
FFmpegを使ってRemuxする
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
function Run-Remux { | |
<# | |
.SYNOPSIS | |
FFmpegを呼んでRemux処理を行う | |
.PARAMETER VideoFile | |
MP4などのオリジナルの動画ファイルへのフルパス | |
.PARAMETER SubtitleFile | |
コンテナに入れたい字幕ファイルへのフルパス | |
.PARAMETER OutFile | |
出力先の動画ファイルへのフルパス | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
$VideoFile, | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
$SubtitleFile, | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
$OutFile | |
) | |
# https://dev.classmethod.jp/articles/add-audio-and-subtitle-to-video-with-ffmpeg/ | |
ffmpeg -i $VideoFile -i $SubtitleFile ` | |
-map 0:v -map 0:a -map 1 ` | |
-metadata:s:s:0 language=jpn ` | |
-c:v copy -c:a copy -c:s srt ` | |
$OutFile | |
} | |
function Generate-Parameter { | |
<# | |
.SYNOPSIS | |
Run-Remuxに渡すパラメータを生成する | |
.PARAMETER SourceVideoFileInfo | |
Get-ChildItemなどから得たファイル情報 | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
[System.IO.FileInfo]$SourceVideoFileInfo | |
) | |
$srtfilename = $SourceVideoFileInfo.BaseName + ".srt" | |
$mkvfilename = $SourceVideoFileInfo.BaseName + ".mkv" | |
[PSCustomObject]@{ | |
VideoFile = $SourceVideoFileInfo.FullName | |
SubtitleFile = Join-Path $SourceVideoFileInfo.DirectoryName $srtfilename | |
OutFile = Join-Path $SourceVideoFileInfo.DirectoryName $mkvfilename | |
} | Write-Output | |
} | |
$Path = "." | |
$Filter = "*.mp4" | |
# ファイル一覧を取ってくる | |
Get-ChildItem -Recurse -Path $Path -Filter $Filter | ` | |
# 字幕ファイルと出力先のパスを持ったパラメータを生成する | |
ForEach-Object { $_ | Generate-Parameter } | ` | |
# ユーザに変換したいファイルを選択させる | |
Out-GridView -PassThru | ` | |
# Remuxを実行する | |
ForEach-Object { $_ | Run-Remux } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment