Last active
March 10, 2021 12:14
-
-
Save simics-ja/509ff2c7dcc7dc1af900eb9c87685783 to your computer and use it in GitHub Desktop.
[TOPAZ Video Enhance AI スクリプト] 処理が途中で止まっても自動で再開するスクリプト #PowerShell
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
# TOPAZ Video Enhance AI Document | |
# https://help.topazlabs.com/hc/en-us/articles/360046455552-Command-Line-Interface-Documentation | |
$INPUT_VIDEO = "input.mp4" | |
$OUTPUT = "output.mp4" | |
New-Item -Name "images" -ItemType "directory" | |
# オリジナル動画のフレームレートの取得(小数点第三位以下切り捨て) | |
(ffprobe -loglevel quiet -show_streams -print_format json "input.mp4" | ConvertFrom-Json).streams[0].r_frame_rate -match "(.*)\/(.*)" | |
$FRAME_RATE = [Math]::Truncate(([double]$Matches[1] / [double]$Matches[2]) * 100)/100 | |
$frameSize = [Int32](ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 $INPUT_VIDEO) | |
$beginFrame = [Int32]((Get-ChildItem images).Count) | |
while ($frameSize -gt $beginFrame) { | |
Write-Host "${beginFrame}/${frameSize}" | |
# "C:\Program Files\Topaz Labs LLC\Topaz Video Enhance AI" を PATH に追加しておくこと | |
veai.exe -i $INPUT_VIDEO -o .\images\ -f jpg -b $beginFrame -d 1920:1080 -m alq-10 -c 0 | |
$frameSize = [Int32](ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 $INPUT_VIDEO) | |
$beginFrame = [Int32]((Get-ChildItem images).Count) | |
} | |
if ($frameSize -ge $beginFrame) { | |
$TMP_VIDEO = "tmp_video.mp4" | |
$TMP_AUDIO = "audio.aac" | |
# images/*.jpgから無音声の動画を作成 | |
ffmpeg -r $FRAME_RATE -i "images\%06d.jpg" -vcodec h264_nvenc $TMP_VIDEO | |
# 入力動画から音声のみ抽出 | |
ffmpeg -i $INPUT_VIDEO -vn -acodec copy $TMP_AUDIO | |
# 無音声動画と音声を結合 | |
ffmpeg -i $TMP_VIDEO -i $TMP_AUDIO -c:v copy -c:a copy $OUTPUT | |
# 処理終了後シャットダウンしない場合はコメントアウト | |
Stop-Computer -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment