Linux commercial detection

I have tried different h264/mp4 and mpeg2/ts files and it seems to the the same thing. cuts off the back 3rd of the file and does not cut out the commercials correctly.

Any ideas on tuning comskip, enhancing detection methods, etc. on how to get this to work better?

thanks haeffnkr

Reviewing your earlier post, I’m not sure you got the Comskip source from the correct location. It seems like the correct location to get Comskip for linux is from https://github.com/erikkaashoek/Comskip while you got it from xilka.com.

I’d try building Comskip from the Github repo. They have some instructions on doing so on the Github page, but looks to be the familiar route in doing so.

For more help I’d suggest https://github.com/erikkaashoek/Comskip/issues or http://www.kaashoek.com/comskip/.

@haeffnkr said:
I have tried different h264/mp4 and mpeg2/ts files and it seems to the the same thing. cuts off the back 3rd of the file and does not cut out the commercials correctly.

Any ideas on tuning comskip, enhancing detection methods, etc. on how to get this to work better?

thanks haeffnkr

Tuning comskip is quite a chore in and of itself. The guide is below, however if you browse the comskip forums you may get lucky and find a tuned .ini for your provider.

If your in the US or Canada, I saw a SIGNIFICANT improvement just by changing the following:

Automated setting of certain parameters
For certain broadcast condition such as typical in the USA or Canada some tuning has been automated. To use this set

intelligent_brightness=1
max_volume=0

http://www.kaashoek.com/files/tuning.htm#_Toc121774672

I’m trying to get comchap to work. It’s set as my post-processing script. At the end of a recording it runs. I end up with several files in the .grab folder and the .edl file ends up in the end destination folder.

I did a test recording and here are the results.

root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83# ls -lah total 1.5G drwxr-xr-x 2 plex plex 4.0K Oct 18 19:31 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:19 .. -rw-r--r-- 1 plex plex 155 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.ffmeta -rw-r--r-- 1 plex plex 22K Oct 18 19:30 The Middle (2009) - S08E02 - A Tough Pill to Swallow.logo.txt -rw------- 1 plex plex 1.5G Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.mkv -rw-r--r-- 1 plex plex 90 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.txt root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83#

root@server:/plex/tvshows/The Middle (2009)/Season 8# ls -lah total 12K drwxr-xr-x 2 plex plex 4.0K Oct 18 19:32 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:31 .. -rw-r--r-- 1 plex plex 16 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.edl root@server:/plex/tvshows/The Middle (2009)/Season 8#

Thoughts?

@robertclemens said:
I’m trying to get comchap to work. It’s set as my post-processing script. At the end of a recording it runs. I end up with several files in the .grab folder and the .edl file ends up in the end destination folder.

I did a test recording and here are the results.

root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83# ls -lah total 1.5G drwxr-xr-x 2 plex plex 4.0K Oct 18 19:31 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:19 .. -rw-r--r-- 1 plex plex 155 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.ffmeta -rw-r--r-- 1 plex plex 22K Oct 18 19:30 The Middle (2009) - S08E02 - A Tough Pill to Swallow.logo.txt -rw------- 1 plex plex 1.5G Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.mkv -rw-r--r-- 1 plex plex 90 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.txt root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83#

root@server:/plex/tvshows/The Middle (2009)/Season 8# ls -lah total 12K drwxr-xr-x 2 plex plex 4.0K Oct 18 19:32 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:31 .. -rw-r--r-- 1 plex plex 16 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.edl root@server:/plex/tvshows/The Middle (2009)/Season 8#

Thoughts?

I found it’s important to delete those work files before the script exits. If I didn’t, I’d occasionally get one of the work files transferred instead of the video.

I’ll update the script that will be default cleanup the files (I know @Bollar has a fork that does so already). Also add command line arguments to keep the files if you desire for some reason.

@Bollar said:

@robertclemens said:
I’m trying to get comchap to work. It’s set as my post-processing script. At the end of a recording it runs. I end up with several files in the .grab folder and the .edl file ends up in the end destination folder.

I did a test recording and here are the results.

root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83# ls -lah total 1.5G drwxr-xr-x 2 plex plex 4.0K Oct 18 19:31 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:19 .. -rw-r--r-- 1 plex plex 155 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.ffmeta -rw-r--r-- 1 plex plex 22K Oct 18 19:30 The Middle (2009) - S08E02 - A Tough Pill to Swallow.logo.txt -rw------- 1 plex plex 1.5G Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.mkv -rw-r--r-- 1 plex plex 90 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.txt root@server:/plex/tvshows/.grab/c176418a91cb74333e607843caffaa99b1377f83#

root@server:/plex/tvshows/The Middle (2009)/Season 8# ls -lah total 12K drwxr-xr-x 2 plex plex 4.0K Oct 18 19:32 . drwxr-xr-x 3 plex plex 4.0K Oct 18 19:31 .. -rw-r--r-- 1 plex plex 16 Oct 18 19:31 The Middle (2009) - S08E02 - A Tough Pill to Swallow.edl root@server:/plex/tvshows/The Middle (2009)/Season 8#

Thoughts?

I found it’s important to delete those work files before the script exits. If I didn’t, I’d occasionally get one of the work files transferred instead of the video.

I figured the script would do the cleanup and the file would move to its eventual location by way of the post-processing variables passed to the script (assuming that is the case).

I moved a test video file to /tmp/test1.mkv. I ran the following. It ran test1.mkv against comchap and exported the result to test2.mkv. All of the work files are in place.
root@server:/tmp# comchap test1.mkv test2.mkv Comskip 0.81.089, made using ffmpeg Donator build The commandline used was: comskip --ini=/root/.comskip.ini test1.mkv Setting ini file to /root/.comskip.ini as per commandline Using /root/.comskip.ini for initiation values. 0:14:55 - 30382 frames in 108.69 sec(279.53 fps), 1.00 sec(266.00 fps), 105% 30471 frames decoded in 108.85 seconds (279.94 fps) Commercials were found. ffmpeg version 2.8.8-0ubuntu0.16.04.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609 configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/ include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger - -enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio -- enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --ena ble-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-l ibspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --ena ble-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enabl e-libx264 --enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 Input #0, matroska,webm, from 'test1.mkv': Metadata: ENCODER : Lavf56.40.101 Duration: 00:14:07.63, start: 0.000000, bitrate: 15051 kb/s Chapter #0:0: start 0.000000, end 193.000000 Chapter #0:1: start 193.000000, end 251.000000 Metadata: title : Commercial Chapter #0:2: start 251.000000, end 251.000000 Stream #0:0: Video: mpeg2video (Main), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, max. 20000 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 t bc (default) Metadata: DURATION : 00:14:07.628000000 Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default) Metadata: DURATION : 00:14:07.008000000 Input #1, ffmetadata, from 'test1.ffmeta': Duration: 00:10:00.00, start: 0.000000, bitrate: 0 kb/s Chapter #1:0: start 0.000000, end 193.000000 Chapter #1:1: start 193.000000, end 251.000000 Metadata: title : Commercial Chapter #1:2: start 251.000000, end 463.000000 Chapter #1:3: start 463.000000, end 600.000000 Metadata: title : Commercial Chapter #1:4: start 600.000000, end 600.000000 [matroska @ 0x13713e0] Codec for stream 0 does not use global headers but container format requires global headers [matroska @ 0x13713e0] Codec for stream 1 does not use global headers but container format requires global headers Output #0, matroska, to 'test2.mkv': Metadata: encoder : Lavf56.40.101 Chapter #0:0: start 0.000000, end 193.000000 Chapter #0:1: start 193.000000, end 251.000000 Metadata: title : Commercial Chapter #0:2: start 251.000000, end 251.000000 Stream #0:0: Video: mpeg2video (mpg2 / 0x3267706D), yuv420p, 1920x1080 [SAR (default) Metadata: DURATION : 00:14:07.628000000 Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 384 kb/ Metadata: DURATION : 00:14:07.008000000 Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame=21573 fps=17100 q=-1.0 Lsize= 1557341kB time=00:14:07.53 bitrate=15052.8k video:1517267kB audio:39703kB subtitle:0kB other streams:0kB global headers:0kB Saved to: test2.mkv root@server:/tmp#

All of the work files are still in the location. How is this working for others?
root@server:/tmp# ls -lah test* -rw-r--r-- 1 root root 32 Oct 18 20:15 test1.edl -rw-r--r-- 1 root root 266 Oct 18 20:15 test1.ffmeta -rw-r--r-- 1 root root 22K Oct 18 20:14 test1.logo.txt -rw------- 1 plex plex 1.5G Oct 18 19:31 test1.mkv -rw-r--r-- 1 root root 102 Oct 18 20:15 test1.txt -rw-r--r-- 1 root root 1.5G Oct 18 20:15 test2.mkv root@server:/tmp#

@bjs1400 said:
I’ll update the script that will be default cleanup the files (I know @Bollar has a fork that does so already). Also add command line arguments to keep the files if you desire for some reason.

Is there a reason the video files remain in the .grab temporary location instead of being moved to their final location? I’m assuming the work files will also keep an infinite list of .grab folders that never get deleted as well.

There’s another thread I started that asks that same question.

My initial testing showed that Plex moved all files in the temp directory in the grab directory to the final destination. Turns out that that’s not 100% true.

Anyway, I updated the script to delete the files. It’s quick and dirty at the moment, I intend to improve that in the future, but it works for now.

Give it a whirl.

@bjs1400 said:
There’s another thread I started that asks that same question.

My initial testing showed that Plex moved all files in the temp directory in the grab directory to the final destination. Turns out that that’s not 100% true.

Anyway, I updated the script to delete the files. It’s quick and dirty at the moment, I intend to improve that in the future, but it works for now.

Give it a whirl.

I only see comcut with the changes. Did you update comchap as well? Comchap is what I’m using.

So what are you doing to get these processed files into the Plex library folder? I don’t want to manually move those in.

@bjs1400 said:
I’ll update the script that will be default cleanup the files (I know @Bollar has a fork that does so already). Also add command line arguments to keep the files if you desire for some reason.

Just remember that my fork only runs on BSD due to different file locations and incompatibilities with commands like ā€œmktempā€. Linux users need to stay away from it.

I only updated comcut, I’ll update comchap too shortly.

I don’t know of any other way than to move the files manually. I suggested a way to trigger Plex to do what it does after recordings completed in a thread here:

@bjs1400 said:
I only updated comcut, I’ll update comchap too shortly.

I don’t know of any other way than to move the files manually. I suggested a way to trigger Plex to do what it does after recordings completed in a thread here:

https://forums.plex.tv/discussion/238187/recordings-still-left-in-grab-directory

Interesting. A final hook from the process would be nice.

Are you running into the only the .edl file moving to the correct location and everything else staying in the grab temp folder? I’m trying to wrap my head around this… ohhhh… I think Plex only wants one file total (IE: the recording). The .edl file is first in the list. Name the other files to anything that would be secondary in the list… The video file needs to be the first in the file listing. I bet that would do it for now but that’s also assuming you can have different names in the video file and the work files. Prefixing the work files with zzz for instance would put them below.

Or… maybe just having the work files gone before the script ends is enough. I see you made the changes. I’ll give it a run.

Good thoughts, but I don’t know what the right answer is. It seems to me that sometimes things work, sometimes they don’t.

Anyway comchap is now updated to delete the other files. If Plex is only moving single file, then it should mean that the recording is the only file in the grab directory.

git pull

@bjs1400 said:
Good thoughts, but I don’t know what the right answer is. It seems to me that sometimes things work, sometimes they don’t.

Anyway comchap is now updated to delete the other files. If Plex is only moving single file, then it should mean that the recording is the only file in the grab directory.

git pull

Yahtzee! First time I ran with the work files removed it went through. I have several other recordings going on to get more testing, but that seemed to do the trick. I didn’t have a single processed recording earlier auto move to my library. Boom!

edit: A second recording finished. Same result – the work files being gone allowed the file to be moved to my library and nothing left in the .grab temp folder (clarification: no .grab temp folder for the recording is left. it is removed as well). Nice!

Nice. Seems like you have done more testing than I have. Glad it’s working.

I added a simple sleep loop to my fork to keep multiple instances of the script from running at the same time. I had six instances running at once last night, and that ultimately caused Plex to crash because it didn’t have enough resources to transcode the program being watched.

I should set up as a branch and do a pull request, so you can just take what you want.

@Bollar said:
I added a simple sleep loop to my fork to keep multiple instances of the script from running at the same time. I had six instances running at once last night, and that ultimately caused Plex to crash because it didn’t have enough resources to transcode the program being watched.

I should set up as a branch and do a pull request, so you can just take what you want.

It would probably be handy to limit how many occurrences are allowed. I had 3 going at once with a transcode stream and it was okay but definitely taxing the system.

I peaked at @Bollar’s branch and saw what he did.

I don’t want to, by default, limit comcut/comchap to only do one operation at a time as I think these scripts should be useful as a standalone tool (without having anything to do with Plex) and not have any hard coded paths involved.

I will add a command line argument allowing to specify a lockfile. If a lockfile is specified then it will sit and wait until the file no longer exists. Then it will immediately create the lockfile, do it’s thing, then delete the lockfile when done.

Unfortunately this will mean that if you want to specify a lock file, then you wont be able to call comchap/comcut directly as a post-processing script. Instead you’ll have to write another script which will call comchap/comcut with the desired lockfile path and passing along the file to process.

Something like this will do:

#!/usr/bin/env bash

/path/to/comcut --lockfile=/tmp/comcut.lock "$1"

@bjs1400 said:
I peaked at @Bollar’s branch and saw what he did.

I don’t want to, by default, limit comcut/comchap to only do one operation at a time as I think these scripts should be useful as a standalone tool (without having anything to do with Plex) and not have any hard coded paths involved.

I will add a command line argument allowing to specify a lockfile. If a lockfile is specified then it will sit and wait until the file no longer exists. Then it will immediately create the lockfile, do it’s thing, then delete the lockfile when done.

Unfortunately this will mean that if you want to specify a lock file, then you wont be able to call comchap/comcut directly as a post-processing script. Instead you’ll have to write another script which will call comchap/comcut with the desired lockfile path and passing along the file to process.

Something like this will do:

#!/usr/bin/env bash

/path/to/comcut --lockfile=/tmp/comcut.lock "$1"

It’s good as an option. Especially if someone has a machine with less horsepower. A lot of this would matter on how long it takes the commercial processing to work. If a machine is able to get through a file in a few minutes, a single instance would probably be good-to-go. If not, it may be beneficial to get the ball rolling on multiple files. A little bit of a case study for the application of the feature.