I want to share a bash script I wrote to repackage TV recordings for Plex so you can utilize the skip commercials on the Plex side. I have only tested this on Mac environment and it is very rough script with minimal error checking.
I also read, but can't find that Channels devs are working on post record webhook/trigger? This would be great to allow this to run after a recording has finished. Right now the script is run against the comskip directory and processes everything there. It tries to determine if a recording has already been processed and skips that one. If not create a mp4 container with chapter markers for recording and then replace the original recording in channels.
I have plex pointing to my recording directories, so after the replace plex 'just' picks up the updated file.
I am open to thoughts and suggestions.
#!/bin/bash
ROOT_DIR="/Volumes/ChannelsDVR/recordings/Logs/comskip/"
FFMPEG="/usr/local/bin/FFMPEG"
MEDIAINFO="/usr/local/bin/mediainfo"
MVCMD="/bin/mv"
LINKCMD="/usr/bin/readlink"
for i in `ls -d $ROOT_DIR*/`
do
echo "Processing Directory $i"
echo "Checking for Media Type"
OUTPUT=`$MEDIAINFO ${i}video.mpg | grep MPEG-TS`
if [ $? -eq 0 ]
then
echo "$? This needs to be processed."
sleep 1;
echo "Creating video file with commercial markers."
`$FFMPEG -v quiet -stats -i ${i}video.mpg -i ${i}video.ffmeta -c copy ${i}video.mp4`
if [ $? -eq 0 ]
then
echo "Moving Video File Into Place."
LINKEDFILE=`$LINKCMD ${i}video.mpg`
`$MVCMD -f ${i}video.mp4 "$LINKEDFILE"`
else
echo "Error Adding Channel Markers To Video File."
sleep 5;
continue;
fi
else
echo "$? This has already been processed."
sleep 1;
fi
done