-
-
Save thornbill/eb97761472cd0285106a98c101eff962 to your computer and use it in GitHub Desktop.
#!/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}" |
My script is totally different and probably not of use to you. The only reason I posted was to point out that changes suggested by @bwarden wouldn't work for some if ffprobe is not in the PATH.
I would suggest using the style of the original script by @thornbill and creating a variable at line 36, right after where __ffpmeg is defined. If the binary is in the same path as ffmpeg, you'd do this:
__ffprobe="$(which ffprobe || echo '/usr/lib/jellyfin-ffmpeg/ffprobe')"
This sets the variable ffprobe by first looking for the ffprobe binary in your path and if not there hard wires it to the quoted string after the echo.
Then, when you edit the script to call ffprobe, use $__ffprobe instead of just ffprobe
If you're curious as to why @bwardens code has + at the beginning of the line, he posted the output of a diff command. This says that his script has these additional lines to that of @thornbill and if you were to manually edit, you wouldn't put the + at the beginning of a line.
@edwhardo Thanks for the info. I'm only curious about resolving the failure of special characters '
;
:
, which seems to be the first code block here, and the second code block only seems related to detecting if transcoding is necessary.
If anyone has a version of this script which doesn't fail when '
, ;
, or :
are in the title, please send it my way!
If anyone has a version of this script which doesn't fail when
'
,;
, or:
are in the title, please send it my way!
I moved to using a python script to make it easier to do more things easier, it's definitely not optimized, but you could add an additional case to my code here:
https://github.com/AndrewBreyen/Jellyfin-TV-Post-Process/blob/6b29fa493e3c2c34387b2f7b5e9a74626846300e/macmini/record_post_process.py#L77
I found this when I had the same problem with a comma in the filename. I posted what worked for me in another github
Protektor-Desura/jellyfin-dvr-comskip#4
Also, wanghan0501 you need to define a variable for __ffprobe (just like __ffmpeg) because its not in the path