Skip to content

Instantly share code, notes, and snippets.

@br4instormer
Last active February 4, 2025 10:59
Show Gist options
  • Save br4instormer/031e362af3c7aa849848dc75a3ff77e9 to your computer and use it in GitHub Desktop.
Save br4instormer/031e362af3c7aa849848dc75a3ff77e9 to your computer and use it in GitHub Desktop.
convert ts video with h264 within docker container on nvidia GPU

How to convert ts video with h264 encoder within docker container on Nvidia GPU

Dependencies

Using

Download script

wget -O script.sh https://gist.githubusercontent.com/br4instormer/031e362af3c7aa849848dc75a3ff77e9/raw/script.sh

Pull Image

docker pull jrottenberg/ffmpeg:6-nvidia

Run convertion

script.sh "input.ts" "output.mp4"
#!/usr/bin/env bash
input=${1:?"Input file not provided"}
output_on_input=${input%.ts}.mp4
output=${2:-$output_on_input}
docker run --rm -i -u "$(id -u):$(id -g)" -v "$(pwd)":/video -w /video --runtime=nvidia --name=ffmpeg-nv --gpus=all \
jrottenberg/ffmpeg:6-nvidia \
-hwaccel_device 0 -hwaccel_output_format cuda -c:v h264_cuvid -y \
-i "$input" -fps_mode passthrough -c:v h264_nvenc -preset p3 "$output"
@br4instormer
Copy link
Author

br4instormer commented Feb 4, 2025

HEVC

docker run --rm -it --runtime nvidia -v "${PWD}:/app:rw" -w /app linuxserver/ffmpeg -y -fps_mode passthrough -hwaccel nvdec -i /app/video.ts -c:v hevc_nvenc -b:v 5M -maxrate:v 8M -profile:v main10 -cq 28 -qmin 21 -qmax 24 -rc vbr -tune hq -preset slow -pix_fmt p010le -rc-lookahead 75 -spatial-aq 1 -aq-strength 8 -temporal-aq 1 -c:a copy /app/output.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment