Comskip Support Forum

Comskip is a free commercial detector, browse the forum for more information
It is currently Sat Aug 19, 2017 5:34 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Oct 26, 2011 1:43 pm 
Offline

Joined: Wed Oct 19, 2011 5:37 am
Posts: 22
Hi erik,

I have an idea for using the Now and Next information included in a transport stream to punish blocks before and after the show.

To cater for tv networks that don't run on time i record an extra 10 minutes at the start and an extra 20 minutes at the end of a show. When running these files through comskip I get some non-commercial blocks before and after the show that I was recording. I've looked at the delete_show_before_first_commercial and delete_show_after_last_commercial options, but given the tv network's bad timing I can't use these reliably. This is where the Now and Next information would come in handy.

I've looked at the EIT (table_id 0x4E) packets in the TS and the information does update almost exactly at the start of each show. The way this could be used is by first detecting the details (maybe the table's version_number?) near the middle of the file, and then during processing punishing any blocks that have different details.

It would also be good if the distance into the file to search for the show's details is configurable. Depending on how much pre and post buffer you have in your recordings will depend on what percentage in you want to look. 40% would probably be a good default.


I am considering creating a simple app which quickly scans the file for the show start and end to create a ProjectX cut list so that comskip only has to deal with the show itself, but if you like this idea and want to include it in comskip soon then I won't bother.
Out of interest, what language is comskip written in? I'm happy to share with you any code I come up with. I'm currently tossing up between C++ and c#.

cheers,
Nate


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 26, 2011 6:18 pm 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3059
Comskip is written in plain C
And yes I would like to receive some code.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 06, 2011 6:53 am 
Offline

Joined: Wed Oct 19, 2011 5:37 am
Posts: 22
Okay, I've written a program to generate a ProjectX .Xcl file from a transport stream file.

The source code is in svn at
http://nate.deepcreek.org.au/svn/tools/TSNowAndNext/trunk

For anyone who wants a compiled version
http://nate.dynalias.net/download/NowAndNext/NowAndNext.zip
The zip includes a bat file (NowAndNext.bat) which runs my program and then loads the file in ProjectX with the .Xcl file.
You'll need to edit NowAndNext.bat near the top of the file to specify the location of your ProjectX install, ProjectX ini file, and the ProjectX output location.
When you run the program you should see something like this
Code:
...
opening Z:\TV\`Movies\(2011-10-29 20-35) Timeline - TEN Digital.ts

First PCR 14:42:33.575139
File Length    7023375272
Sample         2458591808  35.01% name=Timeline
Show Start      383355688   5.46% name=Night At The Museum: Battle Of The Smith
Show End       5920582386  84.30% name=Alien Siege
writing Z:\TV\`Movies\(2011-10-29 20-35) Timeline - TEN Digital.ts.Xcl
...


erik,
Feel free to use any of the code in comskip. I've written it in c++, but tried to avoid most c++ specific code so you shouldn't have too much trouble incorperating it. I assume you've already got your own code for parsing transport streams so you probably don't need that part of my program, except if you haven't parsed EIT tables then you could use ParseEITTable and ParseEITEvents in transport_packet.cpp

Here's a few details of what I've done. The main work is done in the ProcessNowAndNext method in main.cpp. First up the PAT and PMTs are read to determine the service_id (aka program_number) to use. You must already do this in comskip so we can skip down to around line 232.
Here I read the next EIT packet belonging to the stream_id starting from testPositionFileOffset, which is a percentage of the way through the file. The percentage is defined at the start of the method and is currently set to 35%. From this packet I grab event_id_of_show.

Next I do a binary search for the last EIT packet before the test point that has a different event_id. From this I store the file position of this packet in fileOffsetStart. In the same way I then do a binary search for the first packet after the show with a different event_id and store that position in fileOffsetEnd.

Using fileOffsetStart and fileOffsetEnd I write the .Xcl and we're done.

I've tested this on a dozen files so far and all have worked really well. There was one where the start offset was a few seconds into the show so I'm thinking of adding the ability to specify a number of seconds padding to the start and end positions just in case the event_id change is a little off.

If you have any questions just ask. I'm happy to help.

cheers,
Nate


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 06, 2011 10:53 pm 
Offline
Site Admin

Joined: Sun Aug 21, 2005 3:49 pm
Posts: 3059
Nate,

Thanks for the code.
I did build and test and all works well.
Will put adding this on the to-do list

Erik.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 10, 2011 5:02 am 
Offline

Joined: Wed Oct 19, 2011 5:37 am
Posts: 22
Hi erik,

I've updated a few things in my code. The changes you'll be interested in are in revision 10.

And for anyone else who wants to download a compiled version I've added it to my website
http://nate.dynalias.net/dev/tsnowandnext.rails

changes:
  • Fixed exceptions when short_event_descriptor is not present
  • Changed to use the event_id from the event with running_status==4 instead of section_number==0.
    This change was recommended by someone over on the dvbowners forums.
    http://forums.dvbowners.com/index.php?showtopic=12208
  • Added Version information
  • Added a build script which automatically updates the version number based on the subversion revision


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 21, 2012 11:11 pm 
Offline

Joined: Wed Oct 19, 2011 5:37 am
Posts: 22
In case anyone is using this, I've made some more minor fixes.

New Version 1.1.0.19
http://nate.dynalias.net/dev/tsnowandnext.rails

Changes:
  • Fixed problem parsing EIT event when the events section is longer than 255 bytes.
  • Added a message when printing events to warn about long gaps without Now EIT packets.
  • Added -percentage command line option for specifying where in the file the show is.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group