Tuesday, February 11, 2020

Windows FFMPEG Script to transcode video files from H.264/MPEG-4 to H.265/HEVC, using NVENC hardware acceleration on NVIDIA GPU


I  recently put some effort into converting all my H.264 video files into H.265 format, and this is the best setting I found. On a RTX 2070 Super, I get about 250+ fps, on average; a feature length film in 1080p takes about 6 minutes to convert.

@echo off
for %%a in ("*.mkv") do ffmpeg.exe -vsync 0 -hwaccel cuda -i "%%a" -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 21 -c:s copy -acodec copy "D:\tmp\H.265\%%~na.mkv"
for %%a in ("*.m4v") do ffmpeg.exe -vsync 0 -hwaccel cuda -i "%%a" -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 21 -c:s copy -acodec copy "D:\tmp\H.265\%%~na.mp4"
for %%a in ("*.mp4") do ffmpeg.exe -vsync 0 -hwaccel cuda -i "%%a" -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 21 -c:s copy -acodec copy "D:\tmp\H.265\%%~na.mp4"
for %%a in ("*.avi") do ffmpeg.exe -vsync 0 -hwaccel cuda -i "%%a" -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 21 -c:s copy -acodec copy "D:\tmp\H.265\%%~na.mp4"

The key is using the "-hwaccel cuda" option, which keeps the output of NVDEC decoder output on the GPU's framebuffer for NVENC encoder to work on. This way your CPU utilization is kept low and keep GPU's encoder at 100%.

No comments:

Post a Comment