Adding a logging mechanism

windows-hevc-converter
Michael Reber 4 years ago
parent f66feb4451
commit 92f7605c41

@ -4,8 +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:\1_movies\kids.movies\' $videoPath = 'M:\1_movies\_main.movies\'
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# HEVC profiles: main, main10, main444 # HEVC profiles: main, main10, main444
@ -14,6 +13,10 @@ $profile = 'main10'
$NVEncoder = "$PSScriptRoot\encoder\NVEncC64.exe" $NVEncoder = "$PSScriptRoot\encoder\NVEncC64.exe"
$fileTester = "$PSScriptRoot\mediainfo.exe" $fileTester = "$PSScriptRoot\mediainfo.exe"
#############################################################################################################
# Testing and conversion preparations #
#############################################################################################################
if(!(Test-Path $NVEncoder -PathType leaf)) if(!(Test-Path $NVEncoder -PathType leaf))
{ {
Write-Host "NVEncC64.exe not found, please check path in `"$NVEncoder`"." -ForegroundColor Yellow Write-Host "NVEncC64.exe not found, please check path in `"$NVEncoder`"." -ForegroundColor Yellow
@ -21,18 +24,39 @@ 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 ('*.mp4', '*.mkv') #('*.avi', '*.mp4', '*.mkv') - avi current doesn't work. $videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.mp4', '*.mkv') #('*.avi', '*.mp4', '*.mkv') - avi currently doesn't work.
# Instantiating used variables:
$videoID = 1 $videoID = 1
$convertedVideos = 0 $convertedVideos = 0
$notConvertedVideos = 0 $notConvertedVideos = 0
$failedVideos = 0 $failedVideos = 0
# Square brackets are used as wildcards in Powershell.
# To recognize this as normal text, the LogWite function uses the -LiteralPath parameter instead of the -Path parameter.
$logFolderName = $((Get-Date).tostring("dd-MM-yyyy") + ' - [run started at ' + (Get-Date).tostring("HH-mm") + ']')
$count = $videos.Count $count = $videos.Count
if($videos.Count -lt 1) if($videos.Count -lt 1)
{ {
Write-Host "No videos found in: $videoPath" -ForegroundColor Red Write-Host "No videos found in: $videoPath" -ForegroundColor Red
exit exit
} }
# Log write function:
Function LogWrite
{
Param ([string]$logstring)
Add-content -LiteralPath $Logfile -value $logstring
}
# Create new log directory:
New-Item -itemType Directory -Path $PSScriptRoot\logs\ -Name $logFolderName > $null
#############################################################################################################
# END - Testing and conversion preparations
#############################################################################################################
# Main conversion process #
#############################################################################################################
Write-Host "Found $count videos. - starting converter.." -ForegroundColor Cyan Write-Host "Found $count videos. - starting converter.." -ForegroundColor Cyan
Write-Host Write-Host
Write-Host Write-Host
@ -63,8 +87,8 @@ foreach($video in $videos)
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. # If the Subtitles should not be copied, delete the "--sub-copy 1,2" argument.
$arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --profile $profile --output `"$outputFile`"" $arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --sub-copy 1,2 --profile $profile --output `"$outputFile`""
Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized
@ -113,6 +137,8 @@ foreach($video in $videos)
Write-Host "------------------------------------------------------------------------------------------------" Write-Host "------------------------------------------------------------------------------------------------"
Remove-Item -Path $inputFile Remove-Item -Path $inputFile
$convertedVideos = $convertedVideos + 1 $convertedVideos = $convertedVideos + 1
$Logfile = "$PSScriptRoot\logs\$logFolderName\successfully_converted.log"
LogWrite "$outputFile"
} else } else
{ {
# Delete corrupt File! # Delete corrupt File!
@ -122,6 +148,8 @@ foreach($video in $videos)
Remove-Item -Path $outputFile Remove-Item -Path $outputFile
$failedVideos = $failedVideos + 1 $failedVideos = $failedVideos + 1
$notConvertedVideos = $notConvertedVideos + 1 $notConvertedVideos = $notConvertedVideos + 1
$Logfile = "$PSScriptRoot\logs\$logFolderName\error_during_conversion.log"
LogWrite "$inputFile"
} }
} }
Start-Sleep -Seconds 4 Start-Sleep -Seconds 4
@ -134,13 +162,22 @@ foreach($video in $videos)
Write-Host "------------------------------------------------------------------------------------------------" Write-Host "------------------------------------------------------------------------------------------------"
# Increments not converted video counter: # Increments not converted video counter:
$notConvertedVideos = $notConvertedVideos + 1 $notConvertedVideos = $notConvertedVideos + 1
$Logfile = "$PSScriptRoot\logs\$logFolderName\skipped_files.log"
LogWrite "$inputFile"
Start-Sleep -Seconds 4 Start-Sleep -Seconds 4
} }
# Increments video counter: # Increments video counter:
$videoID = $videoID + 1 $videoID = $videoID + 1
$outputFile = "" # Resets the variable to nothing, that in case of an error the old file is not affected.
} }
#############################################################################################################
# END - Main conversion process
# If confersion is done: #############################################################################################################
# Evaluation part of the conversion script #
#############################################################################################################
if($notConvertedVideos -eq 0) if($notConvertedVideos -eq 0)
{ {
Write-Host "Finished converted $convertedVideos out of $count videos." -ForegroundColor Green Write-Host "Finished converted $convertedVideos out of $count videos." -ForegroundColor Green
@ -157,4 +194,6 @@ if($notConvertedVideos -eq 0)
} }
} }
Read-Host -Prompt "Press Enter to exit" Read-Host -Prompt "Press Enter to exit"
#############################################################################################################
# END - conversion script

4
logs/.gitignore vendored

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
Loading…
Cancel
Save