Script to repackage recordings for Plex commercial skipping

I don’t think MCEBUDDY is available on the Mac sadly

I'm a total novice when it comes to shell scripts and the like.

My set up is as follows:

Mac mini running Channels and Plex. Files are saved on my synology NAS connected via ethernet.

I have two sets of folders. One where Plex was saving when I was using the built in DVR, another where I have Channels DVR set up to save. Plex currently looks in both sets of folders for the TV and Move libraries.

Ideally, I would like a transcoding / com skip process to take place, whereby files are processed during the middle of the night and moved over to a new, 'processed' folder and the old file moved to an archive that is not associated with Plex. I could then periodically check that the transcoding and com skip has taken place successfully and delete the archive files.

Do you think your script will work for this set up?

1 Like

@carterbunch are you still utilizing this bash script? I'm having trouble getting this to work. I also may not completely understand how you have it setup and how you are using it.

What I want to be able to do is take the Channels DVR recorded video and EDL generated file and add chapters to a MKV file that Plex sees. That way when a commercial break comes up I can simply skip to the next chapter and it brings me to the end of the commercial break and when the show resumed.

Am I understanding that is what this script is supposed to do?

I setup Hazel to watch a directory and run the shell script. I already have ffmpeg installed view homebrew (I altered the scripts path). Installed mediainfo. When I drop the video file and EDL in the folder Hazel is watching and watch the Hazel log, it recognizes the edl file as a match and doesn't do anything. It says done processing the folder.

I realize now in your script that you are using the .ffmeta file since that is what ffmpeg needs.

How are you doing this now? I believe the EDL creation setup is different than it was in 2019? The EDL file is created right next to the video file. But then what are you doing with that EDL file with your script? The FFMPEG command can't do anything with that, it can only use the ffmeta file, correct? As @carterbunch script shows he is doing it that way. However, the ffmeta file is buried inside logs and in a sub-folder with an incrementing number. Not sure how I could match up the correct video file to the correct ffmeta file.

Sorry for the late response. But I am not using this script any longer. I found this and have been using it. It does WAY more!

@carterbunch What OS/version and hardware are you running this on? I can't get it installed. I've installed all the prerequisites, but it still says "Some pre-requisites not installed." I can run "bash install.sh force" and it appears to complete installation. However, it never creates /Users/home/.channels-transcoder/ directory, so when you run the command it fails.

MacOS 12 on an intel Mac-mini.

I got it installed correctly it seems, with help from https://github.com/karllmitchell/Channels-DVR-to-Plex/issues/3

However, it doesn't seem to be able to find the recordings.

peter@Peters-MacBook-Pro channels-transcoder % channels-transcoder.sh
Working directory: /tmp/transcode.rmMdTaXz
Channels DVR API Interface Found
No new shows to transcode

Channels DVR and storage is local. Prefs defaults.

Basically the same way but with a bash script on an Unraid server. It uses the FFMPEG binary that's packaged with Channels and the EDL file/MPG file to create a MKV file with channel markers in it, then places it back in the folder. I have other things running that moves them to my Media folder after that's done that sorts them into the correct file structure.

@timstephens24 Sounds exactly what I'm looking for. Would you be willing to share it?

Yeah let me make sure the one I put up on GitHub a long long time ago still works and then I’ll post the link here. Hopefully by tomorrow afternoon. My normal scripts aren’t good for public consumption :joy:

There you go. The 'ChannelsEDL.sh' when run, for example, `bash ChannelsEDL.sh /opt/ChannelsDVR' will pull the edl file for your files. For AddChapters.sh, you need to change the variables at the top. Just remember it is 'destructive' in that it converts all the .mpg's to .mkv with chapter markers and then moves that .mkv over the .mpg. Please use at your own risk (probably make a fake Channels folder structure somewhere, and run it pointed to that). I haven't updated it in a few years, so again, at your own risk.

I only use the AddChapters.sh and have Channels add the edl file. That way if there's no edl file it doesn't do anything on multiple runs. The other file is really just a run it once and never again bash script I made, or run it multiple times if you want to keep your .mpg files and not convert them while using something like Kodi for playback.

2 Likes

Perfect! I actually saw this project in my searching. I think I first saw that it moved the edl file next to the recording file and figured it was just old since that function is built-in as an option with Channels DVR now. So guess I never actually dug into the script!

So this is pretty sweet, the only thing I'd love to figure out is how to not create chapters for the commercials and just have the chapters for the show chapters.

Some backstory if you are interested... My PMS is on Windows. I'm recording with the HDHomeRun DVR software and using MCEBuddy with comskip to cut the commercials and transcode down to a smaller filesize. Whatever MCEBuddy is doing is amazing (besides that it's a one-stop solution that has worked awesome for years), but it actually creates chapters that include the commercial breaks. So it allows me to skip to the next chapter when a commercial break comes and the next chapter is when the show came back. So MCEBuddy with comskip is creating chapters for the show+commercial, show+commercial, etc. So far I haven't found a simple single script way to do this.

The reason I'm on the search for a replacement workflow is because I've wanted to move my PMS over to a new Mac mini M1 (my main machine is a MacBook Pro) I actually first spent a week testing out Unraid as a replacement for Windows on my PC. I decided it just wasn't for me and I'd rather just either stick with Windows or go to Mac.

As for the transcoding piece, I'll most likely go with Don Melton's script.

1 Like

Maybe has to do with the default behavior. It does not process previously recorded stuff unless you specify.

I have a cron job that kicks off the script 10 and 40 mins past the hour to immediately start processing newly recorded shows.

Cut from readme of the project.

Set up, first run and the transcode database

On this first run (or install script), the code will initialise a database that lists previously transcoded recordings. Note that it will by default not transcode any previously recorded shows unless you respond to the DAYS prompt when asked (install script). You can reset this database using the command-line with these options:

channels-transcoder.sh CLEAR_DB=1 DAYS=N

where N is the number of days backlog you want clearing (so e.g. DAYS=7). This will reset the database and mark all previously recorded shows (before N days ago) as having already been transcoded. This may take a long time, depending on your system and how much stuff you have. DO NOT run transcode-plex.sh again until this is complete. The install script will handle most of this for you.

Subsequent runs

From now on, channels-transcoder.sh should work fine if run on a repeated cycle, e.g. every 24 hours. If an existing instance of it running is found, or if Channels DVR is recording or comskipping, it will wait up to a user-defined amount of time (default=82800 seconds or 23 hours) before executing. If more than one existing instance is found, channels-transcoder.sh will exit immediately. Note that HandBrakeCLI h.264 encoding is well optimized for multiple CPUs/threads, and so most of the time there is little benefit to running it multiple times.

I tried commenting out these lines to not create chapters for the commercials and it appears to work some times but not every show. I'm still doing some testing.

    # echo [CHAPTER] >> "${META_FILE}"
    # echo TIMEBASE=1/1000 >> "${META_FILE}"
    # echo START="${end}" >> "${META_FILE}"
    # echo END="${startnext}" >> "${META_FILE}"
    # echo "title=Commercial $i" >> "${META_FILE}"

This appears to be working perfectly! The commercial chapters are not created.

I had to first override comskip.ini with the default version from kaashoek. This is what I was using in MCEBuddy. I tested many recordings the past two days and the chapter cut times are almost identical.

This is exceptional @timstephens24 How do I send you beer (or equivalent) money?

1 Like

Just someone getting something out of it is good for me. Glad it helped.

1 Like

@timstephens24 lol, I’ve been doing lots of tests for my workflow and my drive was filling up even after deleting the files. Turns out I forgot you setup a backup .trash folder. :slight_smile: I’ll have to decide if I really need that or automate deleting old files.

1 Like

Ah I think I forgot about that too when I recommended running it on backup files. My bad haha.