Page 1 of 1

feature suggestion: Now and Next detection

Posted: Wed Oct 26, 2011 1:43 pm
by nate
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#.


Re: feature suggestion: Now and Next detection

Posted: Wed Oct 26, 2011 6:18 pm
by erik
Comskip is written in plain C
And yes I would like to receive some code.

Re: feature suggestion: Now and Next detection

Posted: Sun Nov 06, 2011 6:53 am
by nate
Okay, I've written a program to generate a ProjectX .Xcl file from a transport stream file.

The source code is in svn at ... Next/trunk

For anyone who wants a compiled version ...
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: Select all

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
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.


Re: feature suggestion: Now and Next detection

Posted: Sun Nov 06, 2011 10:53 pm
by erik

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


Re: feature suggestion: Now and Next detection

Posted: Thu Nov 10, 2011 5:02 am
by nate
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

  • 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.
  • Added Version information
  • Added a build script which automatically updates the version number based on the subversion revision

Re: feature suggestion: Now and Next detection

Posted: Sat Apr 21, 2012 11:11 pm
by nate
In case anyone is using this, I've made some more minor fixes.

New Version

  • 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.