Skip to content

Instantly share code, notes, and snippets.

@dwin
Created January 6, 2019 08:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwin/8212afda3085ea5c30a6bd782e8c1b51 to your computer and use it in GitHub Desktop.
Save dwin/8212afda3085ea5c30a6bd782e8c1b51 to your computer and use it in GitHub Desktop.
Convert all Plex DVR recordings in directory to HEVC/x265
#!/bin/sh --
# Make executable and Run in directory containing files?
# Convert all '.ts' files in directory using ffmpeg using nvidia hardware hevc(x265) encoding, maintain orginal audio
# and extract subtitles/closed-caption as '.srt' to current directory.
# Start looping over files, tell what we do and log any output to screen and log.
for MPEG in *.ts; do echo "Starting ${MPEG}"
ffmpeg -i "${MPEG}" -c:a copy -c:v hevc_nvenc -b:v 3000k -minrate 1000k -maxrate 8000k -level 4.1 -tag:v hvc1 -preset slow -rc-lookahead 32 -movflags faststart "${MPEG%.ts}.mp4" 2>&1 | tee -a "conversion.log"
# If ffmpeg exited OK, then say it and move the original to the backup directory.
if [ $? -eq 0 ]; then
# Extract subtitles
ccextractor "${MPEG}"
echo "Completed ${MPEG%.ts}.mp4"
else
# If ffmpeg failed, then say so and exit loop.
echo "FAILED converting ${MPEG}, exiting."; exit 1;
fi
done # End of file loop
# Exit.
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment