4K Video Down Res

I’ve noticed that all of the 4k videos I’ve taken on my phone or DSLR look super sharp on a 4k screen but don’t always play back the nicest on 1080p screens. So I’ve written a PowerShell script to help convert my videos from 4k to 1080p and 720p. This way I can just grab the appropriate file I need depending on where I’m going to play it back.

Hopefully someone will find this helpful. This seems to work well for me.

You’ll need Handbreak installed to do the conversions. PowerShell is just automating the commands needed to convert each video.

Update 1: The script can now detect if a video was already processed and skips it. This way you can just dump all videos (processed and unprocessed) into the same folder and just run it.

$videoSourcePath = "[my video path]"
gci $videoSourcePath | where {($_.Name -match ".MP4") -or ($_.Name -match ".MOV")} | foreach {
 if (($_.Name -match "-720p30.mp4") -or ($_.Name -match "-1080p30.mp4")) {
 write-host "Skipping already processed video $($_.Name)"
 } else {
 $dst1 = ($_[0].Fullname.Split(".")[0] + "-720p30.mp4")
 $dst2 = ($_[0].Fullname.Split(".")[0] + "-1080p30.mp4")
 write-host "Processing video $($_.Name) @ $(get-date)"
 if (-not (test-path $dst1) ) {
 $args1 = @()
 $args1 += "-i $($_[0].fullname)"
 $args1 += "-o $($dst1)"
 $args1 += '--preset="Fast 720p30"'
 start-process -FilePath "C:\Program Files\HandBrake\HandBrakeCLI.exe" -ArgumentList $args1 -wait
 remove-variable args1
 }
 if (-not (test-path $dst2) ) {
 $args1 = @()
 $args1 += "-i $($_[0].fullname)"
 $args1 += "-o $($dst2)"
 $args1 += '--preset="Fast 1080p30"'
 start-process -FilePath "C:\Program Files\HandBrake\HandBrakeCLI.exe" -ArgumentList $args1 -wait
 remove-variable args1
 }
 }
}

This entry was posted in IT, Josh Yuhasey and tagged . Bookmark the permalink.

Leave a Reply