Last active
March 13, 2026 13:20
-
-
Save glektarssza/1165dcd424ebb315213b3f1de143ba58 to your computer and use it in GitHub Desktop.
ffmpeg Hardware Transcoding 10-bit HEVC to 8-bit H.264 with NVIDIA CUDA
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
| #!/usr/bin/env bash | |
| declare -a CMD_LINE | |
| # We're running ffmpeg, of course | |
| CMD_LINE+=(ffmpeg) | |
| # Don't bother showing the ffmpeg banner, accept prompts by default | |
| CMD_LINE+=(-hide_banner -y) | |
| # Optionally limit CPU threads, really shouldn't be needed since everything is on the GPU | |
| #CMD_LINE+=(-threads 8) | |
| # Use CUDA hardware acceleration | |
| CMD_LINE+=(-hwaccel cuda -hwaccel_output_format cuda) | |
| # Offload video decoding to the GPU | |
| CMD_LINE+=(-c:v hevc_cuvid) | |
| # Input file from first argument | |
| CMD_LINE+=(-i "$1") | |
| # This matters! Don't autoscale or you get pixel format mis-matches! | |
| CMD_LINE+=(-noautoscale) | |
| # To perform on-GPU scaling, uncommont this line and specify your desired output resolution | |
| # instead of 1920x1080! | |
| #CMD_LINE+=(-filter_complex '[0:0]scale_cuda=1920:1080:format=yuv420p,hwdownload[out]' -map '[out]') | |
| # Copy auto as-is | |
| CMD_LINE+=(-map '0:a:0' -c:a copy) | |
| # Re-encode as H.264 in regular 8-bit pixel format | |
| CMD_LINE+=(-c:v h264_nvenc -pix_fmt yuv420p) | |
| # Optionally specify a bitrate and encoding profile here | |
| #CMD_LINE+=(-b:v 20M -profile main) | |
| # Fast start, lets uploading/encoding be faster for sites like YouTube | |
| CMD_LINE=+(-movflags +faststart) | |
| # Output format from second argument | |
| CMD_LINE+=("$2") | |
| exec "${CMD_LINE[*]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment