Last active
February 24, 2024 22:16
-
-
Save thornbill/eb97761472cd0285106a98c101eff962 to your computer and use it in GitHub Desktop.
DVR post processing script for Jellyfin
This file contains 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 | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
# set -o xtrace | |
PWD="$(pwd)" | |
die () { | |
echo >&2 "$@" | |
cd "${PWD}" | |
exit 1 | |
} | |
# Colors | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
__path="${1:-}" | |
# verify a path was provided | |
[ -n "$__path" ] || die "path is required" | |
# verify the path exists | |
[ -f "$__path" ] || die "path ($__path) is not a file" | |
__dir="$(dirname "${__path}")" | |
__file="$(basename "${__path}")" | |
__base="$(basename "${__path}" ".ts")" | |
# Debbuging path variables | |
# printf "${GREEN}path:${NC} ${__path}\ndir: ${__dir}\nbase: ${__base}\n" | |
# Try to find local version of ffmpeg, defaults to the path used in docker if not found | |
__ffmpeg="$(which ffmpeg || echo '/usr/lib/jellyfin-ffmpeg/ffmpeg')" | |
# Change to the directory containing the recording | |
cd "${__dir}" | |
# Extract closed captions to external SRT file | |
printf "[post-process.sh] %bExtracting subtitles...%b\n" "$GREEN" "$NC" | |
$__ffmpeg -f lavfi -i movie="${__file}[out+subcc]" -map 0:1 "${__base}.srt" | |
# Transcode to mp4, crf parameter can be adjusted to change output quality | |
printf "[post-process.sh] %bTranscoding file..%b\n" "$GREEN" "$NC" | |
$__ffmpeg -i "${__file}" -vcodec libx264 -vf yadif=parity=auto -crf 20 -preset veryslow "${__base}.mp4" | |
# Remove the original recording file | |
printf "[post-process.sh] %bRemoving originial file...%b\n" "$GREEN" "$NC" | |
rm "${__file}" | |
# Return to the starting directory | |
cd "${PWD}" |
However, ffprobe
cannot be found @bwarden
could be totally missing something, but how do you have this set in DVR settings? I keep getting an exit code of 1 in JF logs: set up like
Post-processing application:
/bin/bash
Post-processor command line arguments:
/Scripts/livetv_postprocess.sh {path}
Your script is awesome! Could you help me with the encode syntax to enable intel quick sync? I am unfortunately running Jellyfin on a lower powered CPU and QSV helps a ton. Thanks!!
It’s something that I have considered, but I haven’t had a chance to try it yet.
Had a chance to try it out yet?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this awkward quoting process (inspiration from ffmpeg#5896) helped with normal escaping, plus the extra touches the filter parameter requires for single ticks (
'
) and colons (:
) in filenames for the subtitle extraction command:I'm also poking at muxing to mkv instead of mp4, and detecting whether the incoming TS needs transcoding at all, or just remuxing: