{{Note box|I have a update to this script that works with 0.26, '''however it's pointless, because I can't get Comskip.exe to run under Wine in MythBuntu/Ubuntu 12.04'''. If anyone out there has Wine working, and wants to have a go at getting Comskip.exe going (from http://www.kaashoek.com/files/). Please get in touch, I could wrap this back up and get in working again.}}

Comskip.exe under wine on MythBuntu/MythTV for Linux

For some time now (in Australia), I've had patchy success with commercial flagging (I suspect the TV stations are actively working to hide the commercial transitions - but that's a different soap box).

With some experimentation, I managed to find that Comskip has a better hit rate and less false positives than the built in mythcommflag. Mainly because I was able to better tune the selectivity using the comskip.ini file (there's plenty of advice for tuning comskip on www.kaashoek.com).

Running Comskip under Wine (windows emulator) works fine, the biggest challenge was getting the commercial data back in to MythTV's database.

Note: This How-To uses my PHP script to parse the comskip output, and do the database work. I'd be happier if there was a nice API for accessing the database, or better still some way of running something like "mythcommflag --import-edl /path/to/edl".

As it stands, if the MythTV database schema changes, OR paths change, things will get out of whack. (See warning below)

I'm pretty sure I don't accidentally do a "drop database mythconvrg;" - but maybe I do, so use at your own risk! :)

This how-to is designed for advanced MythTV users, it's definitely beyond the scope of a standard installation. Only do this if you know what you're doing!

Note: It works fine on my install, but seriously, I highly recommend that unless you're comfortable with Linux/Databases/Scripting, don't do this. Backup your data before you start! I have had the misfortune of accidentally losing all my tv shows in the past, it's a horrible feeling to know that a 5 minute upgrade, resulted in days worth of pain trying to restore things.

Getting it going under MythBuntu / Linux Distros

I've chucked this into the Wiki because I found very little information, and no details about an APIs or interfaces for inserting commercial data in to the MythTV database. Perhaps others will inform me I've wasted my time, or that my scripts are ugly - don't care it works for me, and maybe it'll help someone :)

The basic process with comskip is as follows:
MythTV records a program. Instead of calling mythcommflag, it runs a shell script that:

Note: You should get Commercials were found, if not, make sure you have a file that contains commercials, OR you may need to tweak comskip.ini. If no commercials were found, then well there won't be any commercials to insert!

Then if you look at executions.log you'll see if it succeeded in sticking stuff in the database:
EXAMPLE:

The important thing to see is the "Event mark" lines after Checking marks - these are what has been read BACK from the mythconverg database.
Each mark is frame number, and a type, these are inserted directly in to the mythconverg database, existing COMM_START and COMM_END marks for the recording are deleted.

With any luck, you're still with me at this point.

Making MythTV use the script

In the MythTV Backend Setup, under "1. General", flip through until you get to "Job Queue (Global)":

Uncheck 'Start Auto-Commercial Flagging jobs when the recording starts' (Because this script only works "after the fact")

Set Commercial Flagger command:

/home/mythdesktopuser/comskip/mcomflag.sh %DIR% %FILE%

i.e. This is the path to mcomflag.sh, it's passed %DIR% and %FILE% which is the same thing we simulated in the step above: passed in a directory for the recordings, and a filename.mpg for a recording.

OR - You could also 'nice' it up so it doesn't suck too much resources:

Testing a real recording

Probably a good time to test a real recording. Record a short show that's likely to contain commercials, and see how you go.

After the commercial flagging has been run, you can tail /home/mythdesktopuser/comskip/executions.log - you should see the 'Event mark' lines.

A final word on auto vs manual skipping

As even comskip.exe isn't perfect I don't like to have autoskip turned on. I have Myth set to "notify but don't skip". Then I use my remote OR the 'Z' & 'Q' keys to jump between marks.

I find this to be the best method, sometimes Australian TV stations chuck two quick commercials together, and you end up 'out of sync', if you're automatically skipping commercials then you miss parts of your show. If you use the keys, it doesn't matter whether the START/END marks for the commercials are the right way around, 'Z' simply jumps to the next mark whether it's in or out!.

Also, while sometimes Comskip.exe doesn't pick up the commercial at the very start, but it does seem to be pretty good at picking up the transition back in to the TV show - which means a couple of skips forward, and you've back in to your show! Very handy! :)

I also like to have it set to notify me 5 seconds before a commercial, and come back 1 second before the end of a commercial.
These settings are in Myth's front end: Utilities/Setup -> Setup -> TV Settings -> Playback -> Commercial Skip (8/8)