Skip to content

Instantly share code, notes, and snippets.

@OhkuboSGMS
Last active September 18, 2020 06:22
Show Gist options
  • Select an option

  • Save OhkuboSGMS/8813ac43ccc1e8c0e8b43c6d2151d5cf to your computer and use it in GitHub Desktop.

Select an option

Save OhkuboSGMS/8813ac43ccc1e8c0e8b43c6d2151d5cf to your computer and use it in GitHub Desktop.
ffmpeg resize with cuvid (gpu encode) power shell
Param($searchPath)
if (!$searchPath) {
Write-Warning "Pass Search Directory Path"
exit
}
Get-ChildItem $searchPath
if (![bool] (Get-Command ffmpeg -ErrorAction SilentlyContinue)) {
Write-Output "Not Install ffmpeg"
exit
}
$Resize = "1280:720"
$MP4 = Get-ChildItem -Recurse ($searchPath + "\*.mp4") | Where-Object { $_.BaseName -notlike "*-Resize" } | Select-Object
foreach ($f in $MP4) {
$basename = $f.BaseName
$fullname = $f.FullName
$ext = $f.Extension
$directoryPath = $f.Directory.FullName
$input = $fullname
$output = $directoryPath + "/" + $basename + "-Resize" + $ext
Write-Output ("Input:" + $input )
Write-Output ("Output:" + $output)
ffmpeg -y -hwaccel cuvid -i $f -c:v hevc_nvenc -vf scale_cuda=$Resize -f mp4 $output
}
@OhkuboSGMS
Copy link
Author

OhkuboSGMS commented Sep 17, 2020

@OhkuboSGMS
Copy link
Author

C#と大体同じ感じで書けていいですね
ls(Get-ChildItem)でオブジェクトが返ってくるので修正しやすい,Select,WhereとかはLINQ指向で慣れれば大体使えそう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment