You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

EyeTV with Commercial Skipping HD DVR Server

I use EyeTV HD and Turbo.264 HD to record and transcode h.264 shows for playback on a Mac, Apple TV, iPad, iPhone. I also use a self-modified version of etvcomskip to detect and mark commercials, which are then automatically skipped at playback. This makes tv viewing a lot more pleasurable and efficient, and is especially helpful controlling advertiser access to children. In case this is useful to others, I've outlined the steps here:


  1. Eric Kaashoek's website Comskip and download his HD-capable Comskip software. "Commercial" commercial-skippingcompanies (ReplayTV, TiVo, Dish, etc.) are quickly sued out of existence or into submission, even if they simply provide a basic "30-second skip" feature. Comskip is open source beerware that you can download, install, and use yourself, and you can't sue anyone for publishing source code. And rather than providing a simple 30-second skip feature, it detects, marks, and provides that capability for automatic commercial skipping.
  2. Comskip a Windows executable, so you'll need WINE (WINdows Emulator) on OS X to run it. First, download and install Xcode (free from the Apple App store), then download and install and install Macports, then in Terminal, run "sudo port selfupdate; sudo port install wine-devel". Finally, make sure that /Applications/Utilities/X11.app is added to your list of applications to run at login (WINE uses X11 to display Windows windows). Yes, this is windows emulation, but on a half-decent box you'll see that commercial skipping runs at around twice real-time for h.264 HD recordings.
  3. Download and install etvcomskip (and PyeTV if you want EyeTV to work with Front Row). The 2010 version of etvcomskip doesn't work with Comskip's latest HD capabilities, and the latest Comskip mpeg libraries do not allow live tv processing, so install these files to get everything working. Once you done this, you'll have a commercial-skipping HD DVR box on your Mac that can stream to Apple TV, iOS, or export to iTunes.

Comskip software

This lives in the directory /Library/Application Support/ETVcomskip.


Edit the file ./comskip/comskip.ini to use these HD-tuned settings, tailored for US cable:


detect_method=127;1=black frame, 2=logo, 4=scene change, 8=fuzzy logic, 16=closed captions, 32=aspect ration, 64=silence, 128=cutscenes, 255=all
max_avg_brightness=21;maximum average brightness for a dim frame to be considered black (scale 0 to 255) 0 means autosetting
non_uniformity=50; Set to 0 to disable cutpoints based on uniform frames
max_volume=20; any frame with sound volume larger than this will not be regarded as black frame
logo_at_bottom=1; Set to 1 to search only for logo at the lower half of the video, do not combine with subtitle setting
intelligent_brightness=1; Set to 1 to use a USA specific algorithm to tune some of the settings, not adviced outside the USA

volume_slip=150

output_dvrmstb=0; Set to 1 if you're running DVRMS-Toolbox
live_tv=0; set to 1 if you use parallelprocessing and need the output while recording
live_tv_retries=4; change to 16 when using live_tv in BTV, used for mpeg PS and TS


Edit the file ./MarkCommercials.app/Contents/Resources/MarkCommercials.py to use WINE to run comskip.exe nicely. Grep for these changes:


EyeTV.launch()


msg = 'Error: unable to communicate with %s\n' % options.app


#cmd = '"/Library/Application Support/ETVComskip/Wine.app/Contents/Resources/bin/wine" "/Library/Application Support/ETVComskip/comskip/comskip.exe" --ini="/Library/Application Support/ETVComskip/comskip/comskip.ini" "%s"' % MpgFile

# MacPorts 64-bit wine

#cmd = '"/Applications/Wine.app/Contents/Resources/bin/wine" "/Library/Application Support/ETVComskip/comskip/comskip.exe" --ini="/Library/Application Support/ETVComskip/comskip/comskip.ini" "%s"' % MpgFile

cmd = '"/opt/local/bin/wine" "/Library/Application Support/ETVComskip/comskip/comskip.exe" --ini="/Library/Application Support/ETVComskip/comskip/comskip.ini" "%s"' % MpgFile


# nice the wine command

cmd = "/usr/bin/nice -n 14 " + cmd


EyeTV software

EyeTV uses the triggered AppleScripts RecordingStarted and RecordingDone in the directory /Library/Application\ Support/EyeTV/Scripts/TriggeredScripts. Open these using the AppleScript Editor and use these scripts instead. You will probably have to Save As... on your desktop, then copy the updated script back into the correct directory to avoid permissions issues.


RecordingStarted.scpt


on RecordingStarted(recordingID)

delay 10

-- comskip81 uses ffmpeg and does not support live tv; put this in RecordingDone.scpt

-- set cmd to "export DISPLAY=:0.0; /usr/bin/nice -n 5 '/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --log " & recordingID & " &> /dev/null &"

-- display dialog cmd

-- set cmd to "env > /tmp/etv_test.log &"

-- do shell script cmd


--disable this if you do not want a logfile written

write_to_file((short date string of (current date) & " " & time string of (current date)) & "Recording Started run for ID: " & recordingID & (ASCII character 13), (path to "logs" as string) & "EyeTV scripts.log", true)

end RecordingStarted


on write_to_file(this_data, target_file, append_data)

--from http://www.apple.com/applescript/sbrt/sbrt-09.html

try

set the target_file to the target_file as string

set the open_target_file to open for access file target_file with write permission

if append_data is false then set eof of the open_target_file to 0

write this_data to the open_target_file starting at eof

close access the open_target_file

return true

on error

try

close access file target_file

end try

return false

end try

end write_to_file

RecordingDone.scpt


-- Run the python MarkCommercials script for the given recording

-- this must be run with the RecordingStarted script

-- it will check if there were multiple PIDs for the recording and runs MarkCommercials for each pid

-- requires updated MarkCommercials which allows specifying the pid

-- by Ben Blake, September 2009


-- modified for latest Comskip, which cannot be run until after recording is finished; waits for Turbo.264 HD to stop running as well

-- S.T.Smith


global LogMsg


on RecordingDone(recordingID)


set ProcessName to "Elgato H.264 Decoder"

set DelayTime to 60

set MaxDelays to 4 * 60 -- four hours


-- delay until the process slows down or stops running

repeat MaxDelays times

delay DelayTime -- delay at least once to give it a chance to start

set pcpu to CPUPercentage(ProcessName)

if pcpu is equal to "" or pcpu < 2.0 then exit repeat -- break out of delay loop if it's not running

end repeat


delay 10

-- comskip81 uses ffmpeg and does not support live tv; take this from RecordingStarted.scpt

set cmd to "export DISPLAY=:0.0; /usr/bin/nice -n 5 '/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --log " & recordingID & " &> /dev/null &"

-- display dialog cmd

-- set cmd to "env > /tmp/etv_test.log &"

do shell script cmd


set LogMsg to ""

CheckMultiplePIDs(recordingID)


--disable this if you do not want a logfile written

if (count of LogMsg) > 0 then

write_to_file((short date string of (current date) & " " & time string of (current date)) & LogMsg & (ASCII character 13), (path to "logs" as string) & "EyeTV scripts.log", true)

end if

end RecordingDone


-- testing code: this will not be called when triggered from EyeTV, but only when the script is run as a stand-alone script

on run

tell application "EyeTV.app"

set rec to «class Unqu» of item 1 of every «class cRec»


my RecordingDone(rec)

end tell

end run


-- compute the percentage CPU used by ProcessName

on CPUPercentage(ProcessName)

set ProcessPS to do shell script ("ps -axwwc | grep '" & ProcessName & "' | grep -v grep || true")

if ProcessPS is not equal to "" then

set ProcessID to word 1 of ProcessPS

set ProcessPS to do shell script ("ps -xwwco pid,ppid,%cpu -p " & ProcessID & " | tail -1")

set ProcessCPU to word 3 of ProcessPS

return ProcessCPU as number

else

return ""

end if

end CPUPercentage


on CheckMultiplePIDs(recordingID)

--check if there are multiple Video PIDs in the file


tell application "EyeTV.app"

set input_text to my read_from_file((path to "logs" as string) & "ETVComskip" & ":" & recordingID & "_comskip.log")

if (count of (input_text as string)) > 0 then

set logdata to every paragraph of input_text

set logdata_lastrow to (item ((count of logdata) - 1) of logdata) as string


if (items 1 thru 19 of logdata_lastrow) as string = "Video PID not found" then

--multiple Video PIDs, rerun MarkCommercials until successful


set recrdingIDInteger to recordingID as integer

set rec to «class cRec» id recrdingIDInteger

set LogMsg to "RecordingDone found multiple PIDs for recording ID: " & recordingID & ", Channel " & («class Chnm» of rec) & " - " & («class Titl» of rec)


set PIDs to (items 44 thru ((count of logdata_lastrow) - 2) of logdata_lastrow) as string

set delims to AppleScript's text item delimiters

set AppleScript's text item delimiters to ", "

set PID_List to {}

set PID_List to every word of PIDs

set AppleScript's text item delimiters to delims


repeat with pid in PID_List

my launchComSkip(recordingID, pid)

repeat while (my mcIsRunning())

delay 5

end repeat

end repeat


end if

end if

end tell

end CheckMultiplePIDs


on read_from_file(target_file)

--return the contents of the given file

set fileRef to (open for access (target_file))

set txt to (read fileRef for (get eof fileRef) as «class utf8»)

close access fileRef

return txt

end read_from_file


on write_to_file(this_data, target_file, append_data)

--from http://www.apple.com/applescript/sbrt/sbrt-09.html

try

set the target_file to the target_file as string

set the open_target_file to open for access file target_file with write permission

if append_data is false then set eof of the open_target_file to 0

write this_data to the open_target_file starting at eof

close access the open_target_file

return true

on error

try

close access file target_file

end try

return false

end try

end write_to_file


on launchComSkip(recID, pid)

if pid = "" then

set cmd to "export DISPLAY=:0.0; /usr/bin/nice -n 5 '/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --force --log " & recID & " &> /dev/null &"

else

set cmd to "export DISPLAY=:0.0; /usr/bin/nice -n 5 '/Library/Application Support/ETVComskip/MarkCommercials.app/Contents/MacOS/MarkCommercials' --force --log " & recID & " --pid=" & pid & " &> /dev/null &"

end if


do shell script cmd

end launchComSkip


on mcIsRunning()

set processPaths to do shell script "ps -xww | awk -F/ 'NF >2' | awk -F/ '{print $NF}' | awk -F '-' '{print $1}' "

return (processPaths contains "MarkCommercials")

end mcIsRunning

<Links Edited By Host>

Mac mini Server (Mid 2010), Mac OS X (10.7.4), Lion Server, EyeTV HD, Turbo.264 HD

Posted on Jun 4, 2012 7:57 AM

Reply
144 replies

Apr 18, 2013 12:38 PM in response to CTYankee

I looked up the logs in Console, this is what I found:

...

Thu Apr 18 09:29:11 2013 - Path to recording is /Volumes/Media/EyeTV Archive/Throwdown With Bobby Flay - BBQ Chicken.eyetvsched/00000000172056cc.eyetvr

Thu Apr 18 09:29:11 2013 - Changing directory to /Volumes/Media/EyeTV Archive/Throwdown With Bobby Flay - BBQ Chicken.eyetvsched

Thu Apr 18 09:29:11 2013 - Running: "/Library/Application Support/ETVComskip/Wine.app/Contents/Resources/bin/wine" "/Library/Application Support/ETVComskip/comskip/comskip.exe" --ini="/Library/Application Support/ETVComskip/comskip/comskip.ini" "00000000172056cc.mpg" > /Users/home/Library/Logs/ETVComskip/387995340_comskip.log 2>&1

Thu Apr 18 09:29:11 2013 - Return code is: 512, 0x200

Thu Apr 18 09:29:11 2013 - Error code is: 2, 0x2

Thu Apr 18 09:29:11 2013 - Unable to open mpeg2 file return from "comskip": 2

Thu Apr 18 09:29:11 2013 - Exiting

Apr 18, 2013 12:58 PM in response to CTYankee

I had posted an edit, but I got that lovely "down for support" sticky note error. argh


I got past the error comskip was throwing, I made my comskip folder available to the user (home). It was set to not allow access. Now I get this error (does not work):


Thu Apr 18 12:49:28 2013 - Return code is: 26368, 0x6700

Thu Apr 18 12:49:28 2013 - Error code is: 103, 0x67

Thu Apr 18 12:49:28 2013 - Error: unknown error code from comskip: 103, assuming it worked.

Thu Apr 18 12:49:28 2013 - Plist file contents: []

Thu Apr 18 12:49:28 2013 - Setting markers on recording

Thu Apr 18 12:49:28 2013 - Adding marker: []

Thu Apr 18 12:49:28 2013 - Exiting

Jul 30, 2013 2:47 PM in response to essandess

I am still willing to pay (paypal or iTunes gifts) to get this working correctly on my i5 2011 mini. I just upgraded to 10.8.4 and now comskipper is marking the commercials even. So my manual process isn't working either! Yes, I'm sure I have the ability to fight through this with all of your amazing work and documentation, but I'd much rather have somebody else do it (like plumbing, I COULD, but somebody else will do it WAY faster).


If anybody is interested, please respond to this and I'll figure out a way for us to get in touch (without posting our contact info on here).


Thanks!

Sep 13, 2013 4:50 PM in response to essandess

To essandess or anyone else who's familiar with the ETVcomskip python script:


Nice work. I too have a very modded, often updated ETVcomskip/recordingdone combination on my own system.


However, lately I've noticed a flakiness in both comskipping the .mpg files from EyeTV, and also setting the markers in EyeTV.


I'm trying to debug where this issue lies (I'm leaning toward an issue with the wrapper EyeTV is putting around its .mpg files, and at the moment Erik Kaashoek of comskip fame seems to concur).


I've been trying to duplicate the python script functionality in Applescript. However, I'm not a python guy, and I can't seem to figure out how python takes the comskip output file and then sets the EyeTV markers. I don't see any obvious code in the python script that makes that happen (is there a linked library somewhere I'm not finding?) Basically I just want to take the output of WINE + COMSKIP (run by Applescript) and set the EyeTV markers without using the python script (because I don't know python and can't single step it to see what's going on). I can't see any reason why the python script is necessary, and why the entire operation couldn't be performed by Applescript. Yes? No?


Can anyone enlighten me on this?

Sep 13, 2013 8:48 PM in response to chicodaman

Comskip creates a .edl (edit decision list) text file in the .eyetv directory of your recording. EyeTV is aware of the presence of .edl files, and skips over the edited content either in playback or exports. Exported .m4v files will not have the deleted content defined by the .edl file. Comskip does not alter the .mpg recording or .m4v exports created by EyeTV. The altered scripts I wrote change the exported .m4v files using the mp4chaps command.

Sep 14, 2013 12:17 AM in response to essandess

Thank you for the response.


Yes, I'm familiar with comskip's .edl file. I understand your script and workflow. Nicely done. My workflow is a bit different than yours. For years I've been comskipping the .mpg file in the EyeTV package via ETVcomskip's markcommercials.py script (called by my highly modified RecordingDone applescript). My RecordingDone script then uses HandbrakeCLI to compress the .mpg file into a .mkv file, instead of having it done by EyeTV, because I find Handbrake's file size to be smaller and the quality better than the EyeTV transcoder. Then the script moves the .edl and .mkv over to my XBMC media folder. I watch my media with XBMC instead of EyeTV or iTunes. XBMC automatically performs the skipping function, much as EyeTV or VLC does. I don't remove the commercials from the transcoded file, I just match it with the .edl file for automated skipping by XBMC.


Anyway, over the past months I've noticed more and more EyeTV recordings that comskip won't handle, and also that the markcommercials python script is often failing to properly mark EyeTV recordings. I don't know whether it's due to different compressions being used on the cable system, or something that started with a recent EyeTV upgrade. I finally contacted Erik Kaashoek, comskip's author. He examined a file, and seems to think EyeTV might be putting a faulty wrapper on some recordings. I've been writing some test scripts to dig deeper and try to understand what's failing.


Sorry this story is getting so long...long story short:


I would like to know how markcommercials.py takes comskip's .edl file and converts the contents to EyeTV's marker format, and writes it to the EyeTV record to create the markers in the EyeTV recording. I can't see how that's done in the markcommercials.py script (I know Applescript but not Python). I think I see the function call that does it:


# get the plist file (that's the comskip .edl file)for this recording, and make a markers array for it

Plist = GetPlistFile(etvr_path, run_comskip)

# Did we get a plist file?

if Plist is not None:

# Yes, convert it.

markers = GetMarkersArray(Plist)

# and finally, set them

WriteToLog('Setting markers on recording\n')

markers_string = str(markers)

WriteToLog('Adding marker: %s\n' % (markers_string))

recording.markers.set(markers)


...but I can't see the process of how the script does its thing. Can you explain to me where the calculation and marker setting occurs? In the EyeTV record the markers are listed by location and duration (in seconds), whereas in the comskip .edl file they are listed as cutpoints (in frames). So where is that calculation being done?


Thanks for any assistance....

Sep 14, 2013 12:32 PM in response to chicodaman

The modified MarkCommercials.py converts from .edl files to the format expected by mp4chaps in the subroutine edl2mp4chaps. The exact same thing is accomplished in the Applescript RecordingDone.scpt using a perl here document. I originally coded using perl because it's the natural choice for this sort of text parsing and translation, then modified the code for the Python script.

Sep 14, 2013 7:52 PM in response to essandess

The modified MarkCommercials.py converts from .edl files to the format expected by mp4chaps in the subroutine edl2mp4chaps.


Ok, I see that. (Gradually getting to understand Python this weekend...;)

The exact same thing is accomplished in the Applescript RecordingDone.scpt using a perl here document.


I don't see that.


I see seven routines in the Applescript RecordingDone.scpt:


on RecordingDone(recordingID)

on run

on CheckMultiplePIDs(recordingID)

on read_from_file(target_file)

on write_to_file(this_data, target_file, append_data)

on launchComSkip(recID, pid)

on mcIsRunning()

Nowhere can I see any reference to the .edl file created by comskip, or any calculations to make it match the format required by EyeTV when setting EyeTV markers.


Did you perhaps mean the original .py script instead of the original Applescript?

Sep 15, 2013 10:58 AM in response to essandess

I meant to write ExportDone.scpt. After an export is finished, the .edl chapter information is added to all exported instances, if the .edl file exists.


Ah, yes, I see now. Thanks for clarifying. I understand what you're doing.


My problem is that at times the python write of the markers to the EyeTV file is failing (recording.markers.set(markers)). It used to work fine, but lately not so much. As a python novice, I've been confused by the python syntax, but it appears to me that this script uses "py-appscript" to communicate with EyeTV. Unfortunately, py-appscript is no longer supported:


http://appscript.sourceforge.net/py-appscript/index.html Please note that appscript is no longer developed or supported, and its use is not recommended for new projects.


I've been trying various python debuggers (e.g.pudb) to step through the python code to see what's failing, but none of them have been able to import the appscript/aem module without error:


try:

import aem

from appscript import * FAILS ImportError: No module named aem


So without being able to step through the python code to see what's happening, I'm not sure whether this is my problem, or it's something with my system's python installation, or something altogether different.


Luckily, it's easy to set EyeTV's markers from Applescript ("set markers of theRecording to markerList"), so I'm just going to replace the full markCommercials.py script with an Applescript that does the same things. The markCommercials.py script has served me well over the past five years but it may be time to move ahead to something that won't break as EyeTV and various system components are upgraded.


Anyway, thanks for your time and assistance.

Oct 29, 2013 3:11 AM in response to Brandonshire

Brandonshire wrote:


Is there any word on whether upgrading to Mavericks causes any problem with comskip or the EyeTV scripts?

I upgraded to Mavericks and this comskip setup works fine. But as well as upgrading Xcode with the App Store, you must rebuild your MacPorts binaries for the new OS. The crucial port mp4v2 hasn't been upgraded to 10.9 yet, so you must keep these Mountain Lion binaries and their libraries. After moving the old ML MacPorts to the directory /opt/local-mountain_lion, I just "installed" these with symbolic links:


$ sudo ln -s /opt/local-mountain_lion/bin/mp4chaps /opt/local/bin/mp4chaps

$ sudo ln -s /opt/local-mountain_lion/lib/libmp4v2.1.dylib /opt/local/lib/libmp4v2.1.dylib

etc.


Here's the notes on how to migrate MacPorts to a major new OS version:


# References

# https://trac.macports.org/wiki/Migration

# https://www.macports.org/guide/#installing.macports.subversion

# http://apple.stackexchange.com/questions/106189/missing-usr-bin-gnutar-on-maveri cks-macports


xcode-select --install


port -qv installed > myports.txt

sudo port -f uninstall installed and not mp4v2

sudo port clean all

sudo mv /opt/local /opt/local-mountain_lion


sudo mkdir -p /opt/local

cd /opt/local

sudo svn checkout https://svn.macports.org/repository/macports/trunk

cd /opt/local/base

sudo ./configure --enable-readline

sudo make

sudo make install

sudo make distclean

sudo port selfupdate


# ports to install

sudo port -p install wine-devel winetricks mp4v2

Oct 29, 2013 6:20 AM in response to essandess

Thanks for the info! I'm glad it's at least possible. Some of this is a bit beyond my current knowledge but I guess setting this whole thing up has been a bit of a learning experience anyway.


I'll see where things stand in a few weeks when I get back from a big trip and have time to sit down and try to get make sure I have all of this set up correctly.

EyeTV with Commercial Skipping HD DVR Server

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.