Skip to content

Instantly share code, notes, and snippets.

@gotdibbs
Last active March 8, 2021 23:59
Show Gist options
  • Save gotdibbs/7a937b6af9e7341a73f3d294b44da129 to your computer and use it in GitHub Desktop.
Save gotdibbs/7a937b6af9e7341a73f3d294b44da129 to your computer and use it in GitHub Desktop.
Convert mp4 to h.265
# Assumes all videos are in a folder called "video" sitting alongside ffmpeg
# Note conversion is likely lossy, but not noticeable in my experience and the >50% space savings were worth it to me personally
# See more detailed notes below for tuning and options
$videosToConvert = Get-ChildItem -Filter '*.mp4'
foreach ($video in $videosToConvert) {
$destination = Join-Path 'output' $video.Name
If ((Test-Path -Path $destination -PathType Leaf) -ne $true) {
Write-Host "Processing '$($video.Name)'"
# Choosing a different 'preset' can save you lots of time for little cost in quality
# See also: https://streaminglearningcenter.com/blogs/cut-clients-encoding-costs-75-30-minute-phone-call.html
.\bin\ffmpeg.exe -i $video -y -c:v libx265 -preset slower -c:a copy $destination -map_metadata 0
# Additional options:
# -x265-params lossless=1 (combine with `-preset veryslow` to get as close to lossless as you can, as I understand it)
# -hwaccel cuda (try gfx acceleration)
# -vf "transpose=1" (rotate 90 degress, for old phone videos, etc.)
}
else {
Write-Host "Skipping '$($video.Name)'"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment