Fix some stuff, better output, counting, and already converted visualisation

This commit is contained in:
Michael Reber 2020-03-25 12:06:48 +01:00
parent 3a33e96bb7
commit f66feb4451

View File

@ -4,7 +4,7 @@
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# Edit the $videoPath variable to point to your video-files folder: # Edit the $videoPath variable to point to your video-files folder:
$videoPath = 'M:\2_serien\_main.series\Luther\' $videoPath = 'M:\1_movies\kids.movies\'
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
@ -21,8 +21,9 @@ if(!(Test-Path $NVEncoder -PathType leaf))
} }
# Get video list from provided path: # Get video list from provided path:
$videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.avi', '*.mp4', '*.mkv') $videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.mp4', '*.mkv') #('*.avi', '*.mp4', '*.mkv') - avi current doesn't work.
$videoID = 0 $videoID = 1
$convertedVideos = 0
$notConvertedVideos = 0 $notConvertedVideos = 0
$failedVideos = 0 $failedVideos = 0
$count = $videos.Count $count = $videos.Count
@ -33,6 +34,9 @@ if($videos.Count -lt 1)
} }
Write-Host "Found $count videos. - starting converter.." -ForegroundColor Cyan Write-Host "Found $count videos. - starting converter.." -ForegroundColor Cyan
Write-Host
Write-Host
Write-Host "------------------------------------------------------------------------------------------------"
foreach($video in $videos) foreach($video in $videos)
{ {
@ -55,11 +59,11 @@ foreach($video in $videos)
} else { } else {
$outputFile = $videoPath + $video.Insert(($video.Length - 4), '-HEVC') $outputFile = $videoPath + $video.Insert(($video.Length - 4), '-HEVC')
} }
Write-Host Write-Host "Analyzing video ($videoID of $count), starting convertion of number: $convertedVideos please wait.." -ForegroundColor Magenta
Write-Host "Converting video ($videoID of $count), please wait.." -ForegroundColor Magenta
Write-Host "$video `nto:`n$outputFile" -ForegroundColor White Write-Host "$video `nto:`n$outputFile" -ForegroundColor White
Write-Host Write-Host
# If the Subtitles should also copied, add "--sub-copy 1,2" behind the --audio-copy argument.
$arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --profile $profile --output `"$outputFile`"" $arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --profile $profile --output `"$outputFile`""
Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized
@ -105,42 +109,49 @@ foreach($video in $videos)
{ {
# Delete old video File! # Delete old video File!
Write-Host "Conversion Successful! - Deleting old file.." Write-Host "Conversion Successful! - Deleting old file.."
Write-Host
Write-Host "------------------------------------------------------------------------------------------------"
Remove-Item -Path $inputFile Remove-Item -Path $inputFile
$convertedVideos = $convertedVideos + 1
} else } else
{ {
# Delete corrupt File! # Delete corrupt File!
Write-Host "Conversion Failded! - Deleting new converted file.." Write-Host "Conversion Failded! - Deleting new converted file.." -ForegroundColor Red
Write-Host
Write-Host "------------------------------------------------------------------------------------------------"
Remove-Item -Path $outputFile Remove-Item -Path $outputFile
$failedVideos = $failedVideos + 1 $failedVideos = $failedVideos + 1
$notConvertedVideos = $notConvertedVideos + 1 $notConvertedVideos = $notConvertedVideos + 1
$videoID = $videoID - 1
} }
} }
# Increments video counter:
$videoID = $videoID + 1
Start-Sleep -Seconds 4 Start-Sleep -Seconds 4
} else } else
{ {
# Alert if video doesn't need conversion:
Write-Host "Analyzing video ($videoID of $count) - skip" -ForegroundColor Magenta
Write-Host "$video is already in correct format!" -ForegroundColor Green
Write-Host
Write-Host "------------------------------------------------------------------------------------------------"
# Increments not converted video counter: # Increments not converted video counter:
$notConvertedVideos = $notConvertedVideos + 1 $notConvertedVideos = $notConvertedVideos + 1
Start-Sleep -Seconds 4 Start-Sleep -Seconds 4
} }
# Increments video counter:
$videoID = $videoID + 1
} }
# If confersion is done: # If confersion is done:
if($notConvertedVideos -eq 0) if($notConvertedVideos -eq 0)
{ {
Write-Host "Finished converted $videoID out of $count videos." -ForegroundColor Green Write-Host "Finished converted $convertedVideos out of $count videos." -ForegroundColor Green
} else } else
{ {
if($failedVideos -eq 0) if($failedVideos -eq 0)
{ {
Write-Host "Finished converted $videoID out of $count videos. - $notConvertedVideos where not converted because of already correct codec!" -ForegroundColor Green Write-Host "Finished converted $convertedVideos out of $count videos. - $notConvertedVideos where not converted because of already correct codec!" -ForegroundColor Green
} else } else
{ {
Write-Host "Finished converted $videoID out of $count videos. - $notConvertedVideos where not converted because error or already correct codec!!" -ForegroundColor Green Write-Host "Finished converted $convertedVideos out of $count videos. - $notConvertedVideos where not converted because error or already correct codec!!" -ForegroundColor Green
Write-Host "$failedVideos have failed!" -ForegroundColor Red Write-Host "$failedVideos have failed!" -ForegroundColor Red
} }