My TS fix/clean and advert ( comskip ) removal script (1 Viewer)

prupert

Portal Member
March 9, 2008
40
2
First off, I am by no means a script genius, it took me ages to get this far and people with more knowledge than me will no doubt find loads of faults in what I have written. Anyway, since I couldn't find anything on the forums related to this and I had to go to so many places to find all this info, I thought I would share it, hope this is the right place.

I have provided all the respective .exes in the accompanying zip file. Hope this is ok, anybody who maintains these exes and dont want them zipped here, please contact me via PM and I will remove them.

To use, extract the zip to some where. Enable the comskip plugin in TVServer, in the configuration of the plugin choose the pp1.bat file as the file to run and make sure you choose to run it after the recording ENDS.

You'll no doubt have to edit it a bit, but I have tried to indicate what you should edit.

More details will be found on my website, putting the no back in technology | pruperting, I'll add the direct link in a bit and it will include the script I run on my Ubuntu server (where the cleaned file is moved to) to convert the file to something smaller.

Here is the bat code:

Code:
@ECHO off
Rem pp1.bat
Rem v0.1 09.07.09
Rem more details found on www.prupert.co.uk
Rem my first attempt at a batch file to be called by the comskip plugin in TVServer
Rem 
Rem it cleans a TS file with mpeg2repair, then it runs comskip on it (the .ini has UK TV settings), then it cuts the TS file with mencoder based on the comskip's edl file, then it transfers it to my network folder and cleans up the crud
Rem %1 is the fully qualified name of the recorded mpeg file.
Rem I start VLC here since it is one of the processes that I have set the Powerscheduler to prevent system standby, thus it ensures the system does not shutdown whilst the bat file is running
START "" "C:\Program Files\VideoLAN\VLC\vlc.exe"
 
Rem this is because where I eventually move the cleaned file to, is on a USB hardrive on another computer, and this helps spin up the drive, you can delte this
%SystemRoot%\explorer.exe "Z:\"

ECHO ************************** >> "%~dpn1.PostLog.txt"
ECHO Post Processing started on %date% %time% >> "%~dpn1.PostLog.txt"
ECHO Post Processing started on %date% %time%
Rem Sadly, I just couldnt get ProjectX to work properly, I have left this in for intersts sake
Rem ECHO ProjectX cleanup started on %date% %time% >> "%~dpn1.PostLog.txt"
Rem ECHO ProjectX cleanup started on %date% %time%
Rem Echo %TIME% -    Demultiplexing %~nx1

Rem echo "# Project-X INI" > "%TEMP%\X.ini"
Rem the original command that I found to actually get ProjectX to do something
Rem start "Demultiplexing %~1" /WAIT /LOW /MIN "C:\scripts\comskip\projectX\ProjectX.jar" -name "%~n1" -out "%~dp1" "%~1" -ini "%TEMP%\X.ini" -demux

Rem start "Demultiplexing %~1" /WAIT /LOW /MIN "C:\scripts\comskip\projectX\ProjectX.jar" -out "%TEMP%\rec2mpg" "%~1" -ini "%TEMP%\X.ini" -tots
Rem so instead I am using mpeg2repair, but since it has no CLI, I have to use mpeg2repairHelper
ECHO Starting mpeg2repair %date% %time% >> "%~dpn1.PostLog.txt"
mpeg2repairHelper.exe %1 %1-fixed.ts
ECHO mpeg2repair finished on %date% %time% >> "%~dpn1.PostLog.txt"
ECHO.
ECHO Commercial Detection...
ECHO Comskip started on %date% %time% >> "%~dpn1.PostLog.txt"

comskip %1-fixed.ts >>"%~dpn1.PostLog.txt"

ECHO Comskip finished on %date% %time% >> "%~dpn1.PostLog.txt"
REM **  Check for completion of ComSkip again...
REM **  If there's no txt file, ComSkip didn't run, don't continue...
IF EXIST "%1-fixed.edl" GOTO ComClean
ECHO ComSkip did not run right, PostProcess.bat will end now...
ECHO Comskip failed on %date% %time%. Ending PostProcessing.bat >> "%~dpn1.PostLog.txt"
GOTO EOF

:ComClean
ECHO %date% %time% >> "Z:\new_files.log"
ECHO Commercial removal...
ECHO ComClean started on %date% %time% >> "%~dpn1.PostLog.txt"
mencoder "%1-fixed.ts" -edl "%1-fixed.edl" -alang eng,nar -noskip -vf harddup -oac copy -ovc copy -of mpeg -o "%~dpn1_clean.ts"
REM mencoder "%~dpn1.ts" -edl "%~dpn1.edl" -alang eng -noskip -vf harddup -oac copy -ovc copy -of mpeg -o "%~dpn1_clean.ts"
ECHO ComClean finished on %date% %time% >> "%~dpn1.PostLog.txt"

Rem this is another call to keep the USB drive that the file is moved to going,you can delete this
ECHO New file %~n1_clean.ts being moved to Server >> "Z:\new_files.log"
REM **  Check for completion of ComClean...
REM **  If there's no original MPG file, comclean didn't run, don't continue...
IF EXIST "%~dpn1_clean.ts" GOTO Move
ECHO ComClean did not run right, PostProcess.bat will end now...
ECHO ComClean failed on %date% %time%. Ending PostProcessing.bat >> "%~dpn1.PostLog.txt"
GOTO EOF

:Move
ECHO Tidying up...
ECHO Tidying started on %date% %time% >> "%~dpn1.PostLog.txt"

Rem this is another call to keep the USB drive that the file is moved to going,you can delete this
%SystemRoot%\explorer.exe "Z:\"
REM **  if there isn't an '_clean.ts', comclean didn't run and so tidying should cease
IF not EXIST "%~dpn1_clean.ts" GOTO EOF

ECHO Moving Clean TS to Server directory on %date% %time% >> "%~dpn1.PostLog.txt"
IF EXIST "%~dpn1_clean.ts" del "%1"

REM you should change the location where you want the cleaned file to be moved, but keep this part: %~n1_clean.ts
move "%~dpn1_clean.ts" "Z:\%~n1_clean.ts"

ECHO Clean TS moved to Server directory on %date% %time% >> "%~dpn1.PostLog.txt"
Rem more logging and USB drive stuff
ECHO %~n1_clean.ts moved to Server on %date% %time% >> "Z:\new_files.log"
del "%1-fixed.txt"
del "%1-fixed.edl"
del "%1-fixed.ts"
del "%1-fixed.ts.txt"

:EOF
Rem this kills the vlc.exe, thus allowing the server to shutdown via the powersheduler plugin
TASKKILL /IM vlc.exe
 

Attachments

  • comskip.zip
    30.6 KB

ToyRotar

Portal Member
March 24, 2008
8
1
Home Country
Hi Prupert,
Great work in sharing all of this, putting all the pieces together.

I had got as far as getting the comskip to work, but couldn't find & get a copy of mencoder to work.

I'll give this a go & let you know if I have any success.
Best Regards,
David.
 

prupert

Portal Member
March 9, 2008
40
2
No problems, glad it helped someone.

I kinda cheated with the mencode, as I used the version supplied with MCEBuddy 1.08:
MCEBuddy 1.0.8 - MCEBuddy

MCEBuddy kinda does what my script does in a more fancy way, though I found it didn't always do what I wanted and anyway I wanted to learn how to script ;). Anyway, back on topic, the mencoder.exe provided within the zip file above works fine with my script. The same version of mencoder is also included in the zip file I attached.

A word of caution. I now have removed the mencoder part from my script, as I found more often that not, it ended up casuing audio/video sync issues (so the sound is out of sync with the video), I tried countless ways to fix it, using projectX and various tschecking programs, but I never could fix the problem. I think if I used a program called VideoRedo, it would cut the file and also fix video sync issues, and it can be run by a batch file, but the program is about £40 or so.

So, in the end, I ended up just using the .edl files with VLC so I just skip the advert when it starts using a remote. The solution isn't quite as elegant, but it means I never have any audio/video scripts. This is just something to bear in mind. I found that MCEBuddy didn't seem to introduce the same sync issues that I had when using mencoder in my script, so I guess there is a setting that MCEBuddy was using to fix this that I was not aware of.

Anyway, hope all this is usefull. In summary, the mencoder you need is in the attached zip file in the fist post ;)
 

James_3

Portal Member
February 25, 2007
11
0
Home Country
England England
Hi, I did something simelar myself and just came across this.

Just thought i'd add something i used.
I used a batch file named comskip
Called it from my current one using
start /b /wait c:\batch\comskip "%~dpn1.txt"

"2ND FILE"
"C:\comskip\comskip" %1
exit

This way you can review the adverts that it has detected and set start and endpoints.
I found using projectX made the av sync perfect with mencoder.

My full file is as follows

@echo "Folder Path" %~p1
@echo "File Name no ext" %~n1
@echo "Full Path of new file" "%~dpn1.mpg"

Rem DEMUX TS FILE
start /wait java -jar "c:\projectx\projectx.jar" %1
REM REMUX mp2 and m2v Files
"c:\codecs\ffmpeg" -i "%~dpn1.mp2" -i "%~dpn1.m2v" -vcodec copy -acodec copy "%~dpn1-ads.mpg"
REM Delete DEMUX FILES
del "%~dpn1.mp2"
del "%~dpn1.m2v"
del "%~dpn1-02.mp2"
REM RUN COMSKIP
"c:\comskip\comskip" "%~dpn1.ts"
REM CHECK FOR COMMERCIALS
start /b /wait c:\comskip.bat "%~dpn1.txt"
REM REMOVE COMMERCIALS
"c:\codecs\mencoder" "%~dpn1-ads.mpg" -of mpeg -ovc copy -oac copy -o "%~dpn1_clean.mpg" -edl "%~dpn1.edl"
REM Rename Output and del com mpg
del "%~dpn1-ads.mpg"
move "%~dpn1_clean.mpg" "%~dpn1.mpg"

pause

NOTE: you must press w to save the ads you have chosen and you must press ESC to exit the preview window
 

prupert

Portal Member
March 9, 2008
40
2
So you successfully got ProjectX to work?

I ran in to loads of problems with it, mainly it not starting from the command line and then it choosing the wrong audio track and renaming the audio track to German!

I guess muxing the two streams sorts that problem out.

Looks like a good scripts.

I have now moved over to MythTV as I found out my HTPC came with an illegal version of Windows MCE and I didn't wanna fork out £100 for a licence. I know just use my Ubuntu box to sort out the .mpg files the mythbox produces. I run comskip via Wine and then use ffmpeg to convert them into mp4 files that the PS3 flikes (seesh was that a pain to find a command that the PS3 liked!!).

Although MediaPortal looks way nicer in use, the MythWeb features of mythTV just blows it out of the water. Such a same that the MP Web Interface project stalled...
 

James_3

Portal Member
February 25, 2007
11
0
Home Country
England England
Project X works fine for me every time from the command line.
the audio track has the same name with .mp2 extension on mine. Sometimes there can be several audio streams in a ts and each one will get a different name but the main one seems to keep the same file name
 

Users who are viewing this thread

Top Bottom