Created
July 2, 2023 12:14
-
-
Save LachlanArthur/8ce393d925e8210117c85f01e0e2a89d to your computer and use it in GitHub Desktop.
ffmpeg batch conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$indir = Resolve-Path 'in'; | |
$outdir = Resolve-Path 'out'; | |
$ffmpegBin = Get-Command -Name 'ffmpeg' -All -CommandType Application -ea Stop | |
$inputArgs = ( | |
# '-loglevel', 'debug', | |
# GPU decode | |
# '-c:v', 'h264_cuvid', | |
# '-c:v', 'mpeg4_cuvid' # (XVID) | |
# '-c:v', 'hevc_cuvid' | |
# '-init_hw_device', 'vulkan=vk:0', | |
# '-hwaccel', 'vulkan', | |
# '-hwaccel_output_format', 'cuda', | |
'-hwaccel', 'cuda', | |
'-hwaccel_output_format', 'cuda', | |
'' # Allow trailing commas above | |
) | |
$outputArgs = ( | |
# Trim intros | |
# '-ss', '00:00:10', | |
# Video Codec | |
# '-c:v', 'h264_nvenc', | |
'-c:v', 'hevc_nvenc', | |
# '-c:v', 'libaom-av1', | |
# Bitrate | |
# '-b:v', '1800k', # 1080p | |
# '-b:v', '800k', # 720p | |
# '-b:v', '300k', # 480p | |
# '-rc', 'vbr', | |
# Quality | |
# '-crf', 28, # H264 | |
'-cq', 34, # HEVC | |
'-preset', | |
# 'slow', # hq 2 passes | |
# 'medium', # hq 1 pass | |
# 'fast', # hp 1 pass | |
'p1', # fastest (lowest quality) | |
# 'p2', # faster (lower quality) | |
# 'p3', # fast (low quality) | |
# 'p4', # medium (default) | |
# 'p5', # slow (good quality) | |
# 'p6', # slower (better quality) | |
# 'p7', # slowest (best quality) | |
# Audio codec | |
# '-c:a', 'mp3', | |
'-c:a', 'copy', | |
# Downmix surround to stereo | |
# '-ac', '2', | |
# Subtitles | |
'-c:s', 'copy', | |
# Strip all metadata | |
# '-map_metadata', -1, | |
# 10-bit | |
# '-pix_fmt', 'p010le', | |
# Scaling | |
# '-vf', 'scale=-2:1080', | |
# '-vf', 'scale=-2:720', | |
# '-vf', 'scale=-2:400', | |
# Hardware scaling | |
# NOTE: Only supports 8-bit | |
'-vf', 'scale_cuda=w=1280:h=720:interp_algo=lanczos:force_original_aspect_ratio=1:force_divisible_by=2', | |
# Error Fixes: | |
# '-max_muxing_queue_size', 99999, # "Too many packets buffered for output stream 0:1." | |
# Fix broken stereo (only left channel exists) | |
# '-filter_complex', '[0:a] volume=2 [louder]; [louder] channelmap=channel_layout=mono:map=FL-FC [mono]', '-map', '0:v', '-map', '[mono]', | |
'' # Allow trailing commas above | |
) | |
Get-ChildItem $indir -File -Recurse | ForEach-Object { | |
$outsubdir = $_.Directory -replace [regex]::escape($indir), $outdir | |
md -Force $outsubdir; | |
& $ffmpegBin $inputArgs -i $_.FullName $outputArgs "$outsubdir\$($_.BaseName).mkv" | |
} | |
shutdown.exe /s /hybrid /t 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment