Skip to content

Instantly share code, notes, and snippets.

@lifeofguenter
Last active Nov 11, 2018
Embed
What would you like to do?
NZBGet Transcoders
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Transcode mkv to mp4 (Sony Bravia compatible).
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# Full path to ffmpeg executable
#
#
# Example: /usr/bin/ffmpeg
#
#
# If ffmpeg is in your PATH you may leave the path part and set only the executable name (e.g. "ffmpeg")
#FfmpegCmd=ffmpeg
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# TODO:
# http://nzbget.net/Extension_scripts#Testing_NZBGet_version
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# check for valid executable
command -v "$NZBPO_FFMPEGCMD" >/dev/null 2>&1 || { echo >&2 "[ERROR] ffmpeg not found."; exit $POSTPROCESS_ERROR; }
# change to working dir
cd "$NZBPP_DIRECTORY"
# get all avi files
RAN=0
for FILE in *.mkv *.MKV; do
if [[ ! -e "$FILE" ]]; then
continue
fi
BASENAME=$(basename "$FILE")
EXTENSION="${BASENAME##*.}"
FILENAME="${BASENAME%.*}"
RESULT=`$NZBPO_FFMPEGCMD -y -loglevel error -i "$BASENAME" -c:v copy -c:a libfaac -b:a 192k -ac 2 "$FILENAME.mp4" > /dev/null 2>/dev/stdout`
RC=$?
if [ "$RC" -ne "0" ]; then
echo "[ERROR] $NZBPP_NZBNAME ($BASENAME): $RESULT"
exit $POSTPROCESS_ERROR
else
RAN=1
rm "$FILE"
fi
done
if [ "$RAN" -ne "1"]; then
exit $POSTPROCESS_SKIP
else
exit $POSTPROCESS_SUCCESS
fi
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Transcode xvid to mp4 (Sony Bravia compatible).
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# Full path to ffmpeg executable
#
#
# Example: /usr/bin/ffmpeg
#
#
# If ffmpeg is in your PATH you may leave the path part and set only the executable name (e.g. "ffmpeg")
#FfmpegCmd=ffmpeg
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# TODO:
# http://nzbget.net/Extension_scripts#Testing_NZBGet_version
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# check for valid executable
command -v "$NZBPO_FFMPEGCMD" >/dev/null 2>&1 || { echo >&2 "[ERROR] ffmpeg not found."; exit $POSTPROCESS_ERROR; }
# change to working dir
cd "$NZBPP_DIRECTORY"
# get all avi files
RAN=0
for FILE in *.avi *.AVI; do
if [[ ! -e "$FILE" ]]; then
continue
fi
BASENAME=$(basename "$FILE")
EXTENSION="${BASENAME##*.}"
FILENAME="${BASENAME%.*}"
RESULT=`$NZBPO_FFMPEGCMD -y -loglevel error -i "$BASENAME" -c:v libx264 -crf 20 -pix_fmt yuv420p -profile:v high -level 4.0 -c:a libfaac -b:a 192k -ac 2 "$FILENAME.mp4" > /dev/null 2>/dev/stdout`
RC=$?
if [ "$RC" -ne "0" ]; then
echo "[ERROR] $NZBPP_NZBNAME ($BASENAME): $RESULT"
exit $POSTPROCESS_ERROR
else
RAN=1
rm "$FILE"
fi
done
if [ "$RAN" -ne "1"]; then
exit $POSTPROCESS_SKIP
else
exit $POSTPROCESS_SUCCESS
fi
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Move files if all daisy-chained PP prior succeeded.
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# The final directory for post-processed files
#FinalDestination=~/downloads/z
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# only move files if there was no error prior
if [ "$NZBPP_SCRIPTSTATUS" = "FAILURE" ]; then
exit $POSTPROCESS_SKIP
fi
# move complete folder
mv "$NZBPP_DIRECTORY" "$NZBPO_FINALDESTINATION"
exit $POSTPROCESS_SUCCESS
@Serhioromano
Copy link

Serhioromano commented Aug 22, 2016

DOes not work for me. I use Sonnar and NZBGet on QNAP NAS. I added mkv2mp4 and Z script and set them both into postProcess script as global as for category in the order I'd mentioned them. What could be wrong? Do I need restart NZBGet or reload is ok?

@rolandoldengarm
Copy link

rolandoldengarm commented Jan 23, 2017

@Serhioromano there is an error in the mkv2mp4 script

Replace:

if [ "$RAN" -ne "1"]; then

with

if [ "$RAN" -ne "1" ]; then

Note the extra white space.

I got this error:

mkv2mp4: /home/nzbget/downloads/scripts/mkv2mp4.sh: line 68: [: missing `]'

@sbcrumb
Copy link

sbcrumb commented Nov 11, 2018

I am using this to transcode audio only. How can I get it to not delete the file when it is done with the command? IE keep it a MKV

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