powershell :外部プログラムを実行するサンプル
外部プログラムをpowershellから実行するには、Start-Processコマンドレットを使用する。
サンプル
ffmpegで動画を圧縮する。
面倒なのでffmpegのパスを通すことはせず、set-Location (cd)で直実行としている。
$path ="D:\Downloads\ffmpeg-2022-08-25-git-9bf9d42d01-full_build\bin\" $program = "ffmpeg.exe" $option = "-b:v 1500k -bufsize 1500k -maxrate 2000k" cd $path $a = Get-ChildItem -Filter *.mp4 $a | %{ $file = $_.Name; $file_o = $_.BaseName + "-compress" + $_.Extension; $file $file_o Start-Process -FilePath $program -ArgumentList ("-i " + $file + " " + $option + " " + $file_o) -Wait -WindowStyle Hidden } # ffmpegの使い方など #https://jp.videoproc.com/edit-convert/ffmpeg-compress-video.htm #https://blog.nijibox.jp/article/mov-optimize/
ポイントは以下。
Start-Process -FilePath $program -ArgumentList ("-i " + $file + " " + $option + " " + $file_o) -Wait -WindowStyle Hidden
-Wait :プログラムが終了するのを待つ。(直列処理にした方が良い)
-WindowStyle Hidden :起動されるプログラムを表示しない。