Skip to content

Instantly share code, notes, and snippets.

@BluSyn
Last active February 6, 2024 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save BluSyn/f692bed924703b9cd136973079e1ad12 to your computer and use it in GitHub Desktop.
Save BluSyn/f692bed924703b9cd136973079e1ad12 to your computer and use it in GitHub Desktop.
Converts Dolby Vision Profile 5 encoded video files into format acceptable to Plex
#!/bin/bash
origfile="$(realpath "${1}")"
basefile="$(basename "${origfile}")"
basedir="$(dirname "${origfile}")"
ext="${basefile##*.}"
newfile="$(basename -s "${ext}" "${origfile}")nodv.${ext}"
echo "Transcoding File ${basefile} in ${basedir}..."
# Yanked from jellyfin Dolby Vision Profile 5 transcode example
# https://github.com/jellyfin/jellyfin/commit/3beda02d925c74c7a7083eaee733537f3396ec92
# https://github.com/jellyfin/jellyfin-ffmpeg/pull/151/files
docker run -v ${basedir}:/data:rw --runtime=nvidia --entrypoint /usr/lib/jellyfin-ffmpeg/ffmpeg jellyfin/jellyfin \
-init_hw_device cuda=cu:0 \
-filter_hw_device cu \
-hwaccel cuda \
-hwaccel_output_format cuda \
-threads 1 \
-autorotate 0 \
-i "/data/${basefile}" \
-movflags use_metadata_tags \
-map 0 \
-autoscale 0 \
-threads 0 \
-codec:v:0 h264_nvenc \
-preset p1 \
-b:v 21000000 \
-maxrate 21000000 \
-bufsize 81398350 \
-profile:v:0 high \
-g:v:0 72 \
-keyint_min:v:0 72 \
-vf setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc,tonemap_cuda=format=yuv420p:p=bt709:t=bt709:m=bt709:tonemap=bt2390:peak=100:desat=0 \
-c:a copy \
-c:s copy \
"/data/${newfile}"
# Original uses following HLS opts to stream:
# -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename /config/data/transcodes/d6759f55cefc6535dd57061a882e4c40%d.ts -hls_playlist_type vod -hls_list_size 0 -y /config/data/transcodes/d6759f55cefc6535dd57061a882e4c40.m3u8
# Original command in full
# /usr/lib/jellyfin-ffmpeg/ffmpeg -analyzeduration 200M -init_hw_device cuda=cu:0 -filter_hw_device cu -hwaccel cuda -hwaccel_output_format cuda -threads 1 -autorotate 0 -i file:input.mp4 -autoscale 0 -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_nvenc -preset p1 -b:v 40699175 -maxrate 40699175 -bufsize 81398350 -profile:v:0 high -g:v:0 72 -keyint_min:v:0 72 -vf setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc,tonemap_cuda=format=yuv420p:p=bt709:t=bt709:m=bt709:tonemap=bt2390:peak=100:desat=0 -codec:a:0 libfdk_aac -ac 2 -ab 384000 -af volume=2 -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename /config/data/transcodes/2fa35d2d8b2579778295f6a41fc5fe2d%d.ts -hls_playlist_type vod -hls_list_size 0 -y /config/data/transcodes/2fa35d2d8b2579778295f6a41fc5fe2d.m3u8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment