Skip to content

Instantly share code, notes, and snippets.

@gingerbeardman
Last active February 21, 2022 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingerbeardman/508fccef1827e717d6100b2ac6dcfc37 to your computer and use it in GitHub Desktop.
Save gingerbeardman/508fccef1827e717d6100b2ac6dcfc37 to your computer and use it in GitHub Desktop.
Synology DSM Task Scheduler custom script to remux any mkv files as mp4, moving old files to Recycle Bin
#!/usr/bin/env bash
# by Matt Sephton @gingerbeardman
# requires SynoCommunity ffmpeg to be installed
log="/volume1/video/Scripts/remux.log"
bin="/volume1/video/#recycle/"
work="/volume1/video/Scripts/"
export log
export bin
function output ()
{
echo "$1"
echo "$1" >> $log
}
export -f output
function outprint ()
{
printf "$1"
printf "$1" >> $log
}
export -f outprint
function notify () # Remux, status, path, info
{
#echo "Args are \"$@\""
synodsmnotify @administrators "$1 $2" "$3"
msg="$2 = $3"
output $msg
}
export -f notify
cd $work
total=$(find ../ -type f \( -iname \*.mkv -o -iname \*.avi \) -not -path "../#recycle*" | wc -l)
if [ $total -eq 0 ]; then
output "no files found"
exit
fi
notify Remux found "$total files"
function process_pass ()
{
notify Remux OK "$short ($runtime seconds)"
output "OK"
mv "$1" "$bin"
}
export -f process_pass
function process_fail ()
{
notify Remux FAIL "$short" ""
}
export -f process_fail
function process_file ()
{
fullname=$(basename "$1")
short="${fullname%.*}"
outprint "$short = "
start=`date +%s`
/usr/local/ffmpeg/bin/ffmpeg -y -i "$1" -c copy -movflags +faststart "${1%.*}.mp4" -hide_banner -loglevel error
end=`date +%s`
runtime=$((end-start))
status=$?
[ $status -eq 0 ] && process_pass "$1" || process_fail "$1"
}
export -f process_file
echo "" > $log
find ../ -type f \( -iname \*.mkv -o -iname \*.avi \) -not -path "../#recycle*" -print0 | xargs -0 -n1 bash -c 'process_file "$@"' _
wait
total=$(find ../ -type f \( -iname \*.mkv -o -iname \*.avi \) -not -path "../#recycle*" | wc -l)
notify Remux complete "$total files remaining"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment