Linux commercial detection

@jondhoughton Thank you. So sorry for my ignorance but how do you skip to the next chapter on client?

On apple TV slide down on touch pad they will show up. On mobile plex clients there is an icon.

Ok I was successfully able to install comskip and ffmpeg on my Ubuntu server in order to try some different scripts to tag or remove commercials.

I have tried the comchap script however do not see anyway to skip chapters on the android plex client. Is this supposed to work or can anybody point me in the right direction on how to skip to the next chapter on an android client.

I have also tested PlexComskip.py which I would use as a last resort as I don’t want to chance having commercials removed incorrectly, however so far it seems pretty darn accurate.

Thank you everybody for your assistance.

bjs1400 - thank you for the reply. 5 minutes isn’t bad at all, even if more or less based on my Linux servers speed. I know it is a i7 but older. I’ll have to give it a whirl later today. I did see a few other threads talking about actual removal of commercials but it seems they are more Windows focused or buy/donate to get the faster version (which isn’t bad I guess in the big picture).

Thank you again.

Sure thing, @saf1. Feel free to modify the script to do the removal. Earlier in this thread I posted a link to the script that inspired all this.

I decided to go a different direction (I’m too paranoid comskip would detect non-commercial content), but it wouldn’t be too bad to make it an option to delete the commercials. What it would need to do is use ffmpeg to make many small files, one for each (non-commercial) chapter. Then run ffmpeg again to concatenate those generated files together resulting in one video file. If copying the source codecs the performance shouldn’t be too terrible.

It’s entirely possible.

Now that Beta 3 added the ability to add to the script location in the WebUI is it as simple as just adding the following line there?

/path/to/comchap/comchap

I’ve added a new script to the github repo called comcut to be used for commercial removal.

It too should be able to be used directly as a post processing script for Plex to do commercial detection and removal.

comcut:

Interesting, I was going to run through this today but ran into a snag. Seems like ffmpeg is part of Ubuntu base now, or was has of 15.x. I see it in 16. I wonder how functional it is or if the compile version adds in the extra codecs.

On Arch Linux I think I just had to install an extra package or two to get the ffmpeg working for me properly (I don’t even remember which codecs I was missing). I’d assume there would be a comparable package for Ubuntu.

@saf1 said:
Interesting, I was going to run through this today but ran into a snag. Seems like ffmpeg is part of Ubuntu base now, or was has of 15.x. I see it in 16. I wonder how functional it is or if the compile version adds in the extra codecs.

I couldn’t get comskip to work on Ubuntu until I installed ffmpeg using the following: CompilationGuide/Ubuntu – FFmpeg

Tried both 14.04 and 16.04.

I’m getting an error when running comchap

Input #1, ffmetadata, from '/Volumes/Media/Recorded TV/Pitch (2016)/Season 1/Pitch (2016) - S01E01 - Pilot.ffmeta':
  Duration: 01:00:58.00, start: 0.000000, bitrate: 0 kb/s
    Chapter #1:0: start 0.000000, end 0.000000
    Chapter #1:1: start 0.000000, end 8.000000
    Metadata:
      title           : Commercial
    Chapter #1:2: start 8.000000, end 761.000000
    Chapter #1:3: start 761.000000, end 971.000000
    Metadata:
      title           : Commercial
    Chapter #1:4: start 971.000000, end 1349.000000
    Chapter #1:5: start 1349.000000, end 1606.000000
    Metadata:
      title           : Commercial
    Chapter #1:6: start 1606.000000, end 1994.000000
    Chapter #1:7: start 1994.000000, end 2205.000000
    Metadata:
      title           : Commercial
    Chapter #1:8: start 2205.000000, end 2718.000000
    Chapter #1:9: start 2718.000000, end 2960.000000
    Metadata:
      title           : Commercial
    Chapter #1:10: start 2960.000000, end 3617.000000
    Chapter #1:11: start 3617.000000, end 3658.000000
    Metadata:
      title           : Commercial
    Chapter #1:12: start 3658.000000, end 3658.000000
[NULL @ 0x7ff562867400] Unable to find a suitable output format for ''
: Invalid argument

This is on Mac OS X 10.11. I think it’s coming from ffmpeg but I’m not sure what is going wrong. Has anyone else run into this?

Does anyone have this setup working successfully? I have comcut and the script posted here to run it in /usr/local/bin. I have the post-processing script field set to "/usr/local/bin/runcomcut.sh “$1”. But every time a show is recorded I get a warning about there being a problem with post processing.

@refujee@gmail.com said:
Does anyone have this setup working successfully? I have comcut and the script posted here to run it in /usr/local/bin. I have the post-processing script field set to "/usr/local/bin/runcomcut.sh “$1”. But every time a show is recorded I get a warning about there being a problem with post processing.

remove the “$1”, it should just look like this: /usr/local/bin/runcomcut.sh in the post-processing field.

Thanks. Is there any need to add my Plex or DVR token to the script as shown in other threads?

@refujee@gmail.com said:
Thanks. Is there any need to add my Plex or DVR token to the script as shown in other threads?

No, that was only required to get your DVR ID and configure the script before it was exposed to the GUI.

Unfortunately I’m still having issues. For whatever reason the post processing script fails and the recording is deleted. Does anyone have this setup running successfully?

@bjs1400 said:
I’ve added a new script to the github repo called comcut to be used for commercial removal.

It too should be able to be used directly as a post processing script for Plex to do commercial detection and removal.

GitHub - BrettSheleski/comchap: Commercial detection script to add chapters into video file

comcut:
comchap/comcut at master · BrettSheleski/comchap · GitHub

Could you add the possibility to add the chapters after each commercial cut? It would be great to have that.
Your script is not re-encoding the file, right? It will have the same quality of the original, correct?

Great work man, thanks a lot for sharing.

@tvinhas said:
Could you add the possibility to add the chapters after each commercial cut? It would be great to have that.
I made an attempt to do exactly that with Comcut. What’s tricky is the timestamps read from the EDL file must be altered since it needs to compensate for the length of the commercials that get removed. The script attempts to do that by keeping a total time cut from the input file and subtracting that amount from the start and end times of each chapter.

@tvinhas said:
Your script is not re-encoding the file, right? It will have the same quality of the original, correct?
Correct. It tells ffmpeg to copy both the audio and video streams as-is. However, the second (optional) command line argument (telling where the resulting file should be written to) may specify a different file extension. This allows you to do things like convert mkv to mp4 (or vice versa). If the second argument is missing, it just overwrites the original file.

@tvinhas said:
Great work man, thanks a lot for sharing.
Thank you, and you’re welcome.

Admittedly, this script may be a bit buggy and could use some work. This is why I put it on Github. I may commit changes here and there in an attempt improve it. If anyone feels they could improve it, I welcome it. Same goes for the Comchap script.

Thanks for the script - it’s been helpful!

I am able to make it run on FreeBSD from the command line with just a few changes (mainly running bash, which isn’t the default and changing mktemp to something BSD understands).

The challenge I have is getting the script to run in Plex. as you can see from the log, Plex calls the script okay, but nothing actually happens. My guess is this is related to bash - I have changed the shell from tcsh to bash for the plex and root users, but that hasn’t helped. I wonder if Plex configures its own environment elsewhere?

Oct 13, 2016 07:15:04.650 [0x80d443c00] DEBUG - Job running: ‘/comskip/comcut.sh’ ‘/media/dvr/.grab/99321817f4f38d77822901b7e8f073954b59949c/AccuWeather (2007) - 2016-10-13 00_00_00 - Episode 10-13.ts’
Oct 13, 2016 07:15:04.716 [0x80d443c00] DEBUG - Jobs: ‘/comskip/comcut.sh’ exit code is 0
Oct 13, 2016 07:15:04.716 [0x80d443c00] DEBUG - MediaRecorder: Postprocessing script ‘/comskip/comcut.sh’ was successful in 0.1 seconds. Nicely done.
Oct 13, 2016 07:15:15.610 [0x80e337400] DEBUG - Job running: ‘/comskip/comcut.sh’ ‘/media/dvr/.grab/4dbf0bfd176d9306d7dc83175c52a38265c7db73/Music Playlist (2015) - 2016-10-13 00_00_00 - Episode 10-13.ts’
Oct 13, 2016 07:15:15.668 [0x80e337400] DEBUG - Jobs: ‘/comskip/comcut.sh’ exit code is 0
Oct 13, 2016 07:15:15.668 [0x80e337400] DEBUG - MediaRecorder: Postprocessing script ‘/comskip/comcut.sh’ was successful in 0.1 seconds. Nicely done.

Have you tried manually calling comcut with some test video file? What I did for testing was copy some video file from my library to some temp directory (not scanned by Plex) and run it through comcut.

eg:

/path/to/comcut /path/to/testfile.mkv

I’m assuming comcut is erroring out on you. Running it manually should clue you in on what it is.