Skip to content

Instantly share code, notes, and snippets.

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 telfaria/d6ff8496f3a1aacd50d7902d3f7f576b to your computer and use it in GitHub Desktop.
Save telfaria/d6ff8496f3a1aacd50d7902d3f7f576b to your computer and use it in GitHub Desktop.
カーナビ用(320x240/MPRG4/AAC-LC/1Mbps)に動画を一括変換するPowerShellスクリプト
# カーナビ用に変更するには以下の設定にする
# 320x240(16:9/4:3, MPEG-4, AAC-LC, 1000kbps)
#サポートしているffmpegは
# ffmpeg version 6.0-essentials_build-www.gyan.dev
#です
if($Args.Length -ne 1){
Write-Output "Argument Error";
exit(1);
}
#入力フォルダを引数として取得
$InputDir = $Args[0];
#出力先フォルダ(最終的には$ImputDirとJoin-Pathします)
$target_dir = "/CarNavi/"
#対象となるMP4ファイルの拡張子
$MP4_Extension = "*.m4v"
#FFMPEGのパスを指定
$ffmpeg = "C:\ffmpeg-6.0\bin\ffmpeg.exe";
#FFMPEGのグローバルオプション
$ffmpeg_global_option="-y -v verbose"
#FFMPEGのエンコードオプション
$ffmpeg_Option = "-vcodec mpeg4 -b 1M -s 320x240" ;
#DEBUG
Write-Output "FFMPEG is $ffmpeg";
Write-Output "Input is $InputDir"
#存在確認 引数がフォルダかどうか判定
if($InputDir.psiscontainer -eq $false) {
Write-Output("$InputDir はフォルダではありません")
exit(1);
}
#入力フォルダのファイル一覧を取得(ファイル名のみ)
$files = Get-ChildItem -LiteralPath $InputDir -Filter $MP4_Extension -Force
#対象ファイルが存在しなかったら終了
if ($files.count -eq 0) {
exit(1);
}
#出力フォルダの設定
$outDir = Join-Path $InputDir $target_dir
#出力フォルダが無かったら作成
if((Test-Path ($outdir)) -eq $false){
new-item -ItemType directory -Force -path $outdir
}
#ForEachでぶん回す
foreach($file in $files) {
Write-Output "Found '$file'"
$InFileName = join-path $InputDir $file
$OutFileName = Join-Path $outDir $file
#FFMPEGに送るオプション文字列を作成する
$ffoption = "$ffmpeg_global_option -i ""$InFileName"" $ffmpeg_Option ""$OutFileName"""
#DEBUG
#Write-Output("Command: $ffmpeg $ffoption")
#FFMPEGの実行
start-process -filepath $ffmpeg -ArgumentList $ffoption -Wait
}
Write-Output("Operation Completed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment