Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Name: Convert Videos using FFMpeg or Handbrake CLI
- # Version: 1.0A
- # Date Last Modified: 30 July 2017
- # Author: hl2guide
- # SOURCES: http://www.waynezim.com/2014/06/use-powershell-to-batch-convert-videos-using-handbrake/
- # Outputs an optimized x264 encoded MP4 video
- # 1) Source Folder:
- $folder = 'C:\Temp'
- # 2) Source File Extension:
- $sourceFileExtension = 'wmv'
- # 3) Tool ('handbrake' or 'ffmpeg'):
- $tool = 'ffmpeg'
- # Folder for tools (ffmpeg and handbrake) [ffmpeg.exe and HandBrakeCLI.exe]
- $toolFolder = 'Y:\Batch Scripts\Commands'
- # Gets list of files
- $filelist = Get-ChildItem $folder -filter *.$sourceFileExtension -recurse
- # Counts the number of files
- $num = $filelist | measure
- $filecount = $num.count
- # Sets tool EXE
- if($tool -eq 'handbrake')
- {
- $process = $toolFolder+'\HandBrakeCLI.exe'
- }
- elseif($tool -eq 'ffmpeg')
- {
- $process = $toolFolder+'\ffmpeg.exe'
- }
- else
- {
- Write-Host 'Tool to use is not set, exiting.'
- exit
- }
- # Loops through file list
- $i = 0;
- ForEach ($file in $filelist)
- {
- $i++;
- $oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension
- $newfile = $file.DirectoryName + "\" + $file.BaseName + '.mp4'
- # Calculates Progress
- $progress = ($i / $filecount) * 100
- $progress = [Math]::Round($progress,2)
- # Shows Status
- Clear-Host
- Write-Host '-------------------------------------------------------------------------------' -ForegroundColor White
- Write-Host "Handbrake Batch Encoding ($tool)" -ForegroundColor Cyan
- Write-Host "Processing - $oldfile" -ForegroundColor Yellow
- Write-Host "Destination - $newfile" -ForegroundColor Green
- Write-Host "File $i of $filecount - $progress%" -ForegroundColor Magenta
- Write-Host '-------------------------------------------------------------------------------' -ForegroundColor White
- # Checks tool
- if($tool -eq 'handbrake')
- {
- # Arguments:
- $arguments='--encoder x264 --encoder-preset slow --optimize -B 190'
- # Perform Video Conversion using Handbrake CLI
- # Write-Host "-i `"$oldfile`" `"$newfile`" $arguments"
- Start-Process $process -ArgumentList "-i `"$oldfile`" -o `"$newfile`" -f mp4 $arguments --verbose=0" -Wait -NoNewWindow
- }
- elseif($tool -eq 'ffmpeg')
- {
- # Arguments:
- $arguments='-c:v libx264 -c:a copy -preset slow -crf 22 -hide_banner'
- # Perform Video Conversion using FFMpeg CLI
- # Write-Host "-i `"$oldfile`" `"$newfile`" $arguments"
- Start-Process $process -ArgumentList "-i `"$oldfile`" `"$newfile`" $arguments" -Wait -NoNewWindow
- }
- }
- # Shows final messages
- Write-Host "$filecount videos converted from .$sourceFileExtension to .mp4." -ForegroundColor Green
- Write-Host "Folder: $folder"
- Write-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement