Rebuild script with NVEnc for faster transcoding

windows-hevc-converter
Michael Reber 4 years ago
parent c95c1f38e0
commit 3d5061d936

@ -5,7 +5,7 @@ A PowerShell script to convert videos to the HEVC video format utilizing GPU har
The main benefit being that you can save disk space significantly (most of the time).
## Space Saving Examples 💡
## Space Saving Examples
- 2.5GB MP4 to 500MB HEVC MP4
- 3GB MP4 to 800MB HEVC MP4

@ -1,37 +1,26 @@
# Converts videos to HEVC for all paths in "video_file_list.txt"
# Note: To copy paths in Windows File Explorer
# Hold down the shift key and right click a selection of video files,
# click "Copy as Path" and paste into "video_file_list.txt" and save.
# Converts videos to HEVC for given path:
# 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)\'
# Start Edits (4 in total)
# Edit 1 of 4 - Set to the path of ffmepg.exe:
$ffmpegEXE = 'Z:\Commands\ffmpeg.exe'
# Edit 2 of 4 - Presets are ultrafast, superfast, veryfast,
# faster, fast, medium, slow, slower, or veryslow:
$preset = 'medium'
# Edit 3 of 4: Video List File:
$videosListFile = "$PSScriptRoot\video_file_list.txt"
# Edit 4 of 4:
# Default 'hevc_nvenc' is for recent nVidia GPU.
# Set it to 'hevc_vaapi' if you are using a recent AMD video card instead.
$hardwareEncoder = 'hevc_nvenc'
# End Edits
# DO NOT EDIT BELOW HERE ==================================================
# HEVC : main, main10, main444
$profile = 'main10'
$NVEncoder = "$PSScriptRoot\encoder\NVEncC64.exe"
$arguments = ''
if(!(Test-Path $ffmpegEXE -PathType leaf))
if(!(Test-Path $NVEncoder -PathType leaf))
{
Write-Host "ffmpeg.exe not found, please check path in `$ffmpegEXE." -ForegroundColor Yellow
Write-Host "NVEncC64.exe not found, please check path in `"$NVEncoder`"." -ForegroundColor Yellow
exit
}
# Gets Video List File Contents
$videos = Get-Content -Path $videosListFile
$videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.avi', '*.mp4', '*.mkv')
$videoID = 1
$count = $videos.Count
if($videos.Count -lt 1)
@ -44,31 +33,20 @@ Write-Host "Converting $count videos.." -ForegroundColor Cyan
foreach($video in $videos)
{
# Converts using ffmpeg
# Converts video using NVEncC64
$video = $video.Replace("`"", "")
$inputFile = $video
#$inputFolder = (Get-Item $inputFile).Directory.FullName
$outputFile = $video.Insert(($video.Length - 4), '(HEVC)')
#$outputFolder = $inputFolder
#$inputFile
#$outputFile
$inputFile = $videoPath + $video
$outputFile = $videoPath + $video.Insert(($video.Length - 4), '(HEVC)')
Write-Host
Write-Host "Converting video ($videoID of $count), please wait.." -ForegroundColor Magenta
Write-Host "$video `nto:`n$outputFile" -ForegroundColor White
Write-Host
#$outputFilePath = "$outputFolder\$outputFileName" testing: -threads 2
# hevc_nvenc
# libx265
$arguments = "-i `"$inputFile`" -hide_banner -y -xerror -threads 2 -c:a copy -c:s copy -c:v $hardwareEncoder " +
"-crf 28 -preset $preset `"$outputFile`""
#$arguments
#$outputFile
#exit
#$videoID
#Start-Process $ffmpegEXE -ArgumentList $arguments -WindowStyle Minimized -Wait
Start-Process $ffmpegEXE -ArgumentList $arguments -WindowStyle Minimized
$processName = 'ffmpeg'
$arguments = "--input `"$inputFile`" --codec hevc --audio-copy 1,2 --profile $profile --output `"$outputFile`""
Start-Process $NVEncoder -ArgumentList $arguments -WindowStyle Minimized
$processName = 'NVEncC64'
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
@ -87,12 +65,18 @@ foreach($video in $videos)
# 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!
}
# Increments video counter
$videoID = $videoID + 1
Start-Sleep -Seconds 4
}
Write-Host "Finished converting $count videos." -ForegroundColor Green
Write-Host "Finished converted $count videos." -ForegroundColor Green
exit

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save