video-in-place-hevc-converter/convert_Videos.ps1

82 lines
2.5 KiB
PowerShell
Raw Normal View History

# Converts videos to HEVC for given path:
2020-03-05 20:48:33 +01:00
# Ref: https://trac.ffmpeg.org/wiki/Encode/H.265
# https://github.com/rigaya/NVEnc/releases
$videoPath = 'M:\1_movies\kids.movies\Alvin und die Chipmunks (1-3)\'
2020-03-05 20:48:33 +01:00
# HEVC : main, main10, main444
$profile = 'main10'
2020-03-05 20:48:33 +01:00
$NVEncoder = "$PSScriptRoot\encoder\NVEncC64.exe"
2020-03-05 20:48:33 +01:00
$arguments = ''
if(!(Test-Path $NVEncoder -PathType leaf))
2020-03-05 20:48:33 +01:00
{
Write-Host "NVEncC64.exe not found, please check path in `"$NVEncoder`"." -ForegroundColor Yellow
2020-03-05 20:48:33 +01:00
exit
}
2020-03-05 20:48:33 +01:00
# Gets Video List File Contents
$videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.avi', '*.mp4', '*.mkv')
2020-03-05 20:48:33 +01:00
$videoID = 1
$count = $videos.Count
if($videos.Count -lt 1)
{
Write-Host "No videos found in: $PSScriptRoot\video_file_list.txt" -ForegroundColor Red
exit
}
Write-Host "Converting $count videos.." -ForegroundColor Cyan
foreach($video in $videos)
{
# Converts video using NVEncC64
2020-03-05 20:48:33 +01:00
$video = $video.Replace("`"", "")
$inputFile = $videoPath + $video
$outputFile = $videoPath + $video.Insert(($video.Length - 4), '(HEVC)')
2020-03-05 20:48:33 +01:00
Write-Host
Write-Host "Converting video ($videoID of $count), please wait.." -ForegroundColor Magenta
Write-Host "$video `nto:`n$outputFile" -ForegroundColor White
Write-Host
$arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --profile $profile --output `"$outputFile`""
Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized
$processName = 'NVEncC64'
2020-03-05 20:48:33 +01:00
Start-Sleep -Seconds 8
# Sets to use 3 cores (always set to one less core that your CPU has)
# 2 Cores = 3, 3 Cores = 7, 4 cores = 15, 5 cores = 31, 6 cores = 63
# Code to calculate for your CPU:
# $noOfCores = Get-WmiObject Win32_Processor | Measure-Object NumberOfLogicalProcessors -Sum
# $noOfCores.Sum = $noOfCores.Sum - 1
# [math]::Pow(2,$($noOfCores).Sum) - 1
#
$process = Get-Process $processName; $process.ProcessorAffinity=7
Start-Sleep -Seconds 8
# Sets priorty to High
# Values: High, AboveNormal, Normal, BelowNormal, Low
$process = Get-Process -Id $process.Id
$process.PriorityClass = 'High'
# Waits for process to complete
$processID = (Get-Process $processName).id
Wait-Process -Id $processID
if(Test-Path $outputFile)
{
Write-Host "CONVERSION WORKED! FILE: `"$outputFile`" FOUND" -ForegroundColor Yellow
# TODO delete old and Move file name!
}
2020-03-05 20:48:33 +01:00
# Increments video counter
$videoID = $videoID + 1
Start-Sleep -Seconds 4
}
Write-Host "Finished converted $count videos." -ForegroundColor Green
2020-03-05 20:48:33 +01:00
exit