INDEX  F.A.Q.  SEARCH  LATEST POSTS     Rules  Register  Profile  Private messages  Login


Search all forums or this forum: Advanced search
How to retrieve transport stream infos

Forum Index -> Video -> Programming Printer-friendly version
Reply to topic
Author Message
jeromedroz
Member


Joined: 07 Aug 2006
Location: Switzerland

Post Posted: Nov 09, 2006 01:38 Posts Comp View users profile Send private message Reply with quote

I'm looking for a command line tool or a Java API that allows me to retrieve informations from Transport Stream files, especially the aspect ratio. I have to deal with thousands of such files which match either the 4/3 or 16/9 aspect ratio and have a size of 720x576. I know that ffmpeg command line tool doesn't display this information; MPEG Streamclip does, but is not batchable; I've also digged into the ProjectX source code (written in Java) but so far without success. Does anybody have a clue about how I can achieve this?

borax
Member


Joined: 20 Apr 2004
Location: Germany

Post Posted: Nov 09, 2006 02:26 Posts Comp View users profile Send private message Reply with quote

The problem with Transport Streams is the enormous amount of possible contents... Within a transport stream you may have several video streams (even with different encoding formats like mpeg or h264) which may change the aspect ratio individually at any point. For such streams ProjectX is the only possibility (and you need the info for which stream at which time/byte position the info should be gathered from). If your transport streams are more simple (only one video stream, constant aspect ratio, mpeg only), then you can evaluate one mpeg sequence header and get the aspect ratio information quite easy. I have some visual basic code for this purpose (parse a mpeg header - not specific for ts files), but I don't know if it would help you. The structure of the mpeg headers can be found here:
http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html#seq
_________________
GUI for dvdauthor:
http://www.videohelp.com/~gfd/


jeromedroz
Member


Joined: 07 Aug 2006
Location: Switzerland

Post Posted: Nov 09, 2006 03:08 Posts Comp View users profile Send private message Reply with quote

Thank you for the quick response. The files I have to deal with contain one video stream encoded in MPEG-2 with a constant aspect ratio and one audio stream. I'll examine carefully the page about mpeg headers, and possibly give you some feedback depending on whether I succeed or not. I don't have much knowledge in visual basic, but if you don't mind supplying me with the code sample, I'd be very pleased...
Thanks again.


jeromedroz
Member


Joined: 07 Aug 2006
Location: Switzerland

Post Posted: Nov 09, 2006 05:45 Posts Comp View users profile Send private message Reply with quote

OK, I'm able to get MPEG header informations thanks to the url provided...
This is the very simple code I wrote:

Code:
String filename = "/movie/myfile.ts";
File f = new File(filename);
try {
   BufferedInputStream in =
      new BufferedInputStream(new FileInputStream(f));
   byte[] buf = new byte[4];
   int len = -1, ar = 0, fr = 0;
   while ((len = in.read(buf)) != -1) {
      if (len == 4) {
         BigInteger bi = new BigInteger(buf);
         int i = bi.intValue();
         if (i == 0x1b3) {
            in.skip(3);
            int b = in.read();
            ar = b >>> 4;
            fr = ar * 16 ^ b;
            break;
         }
      }
   }
   in.close();
   System.out.println("Aspect ratio: " + ar);
   System.out.println("Frame rate  : " + fr);
} catch (IOException e) {
   e.printStackTrace();
}


borax
Member


Joined: 20 Apr 2004
Location: Germany

Post Posted: Nov 09, 2006 10:18 Posts Comp View users profile Send private message Reply with quote

As I told you, it is quite easy... smile.gif
One remark: I don't know your files, but I have encountered the quadword 000001B3 sometimes inside an ac3 stream. Then the found 'Aspect ratio' is crap...
ATM I help myself with an additional check if a Video Stream header (000001E0) can be found within the next 100 bytes after the sequence header. If not, I search the next 000001B3 quadword.
_________________
GUI for dvdauthor:
http://www.videohelp.com/~gfd/


Reply to topic All times are GMT - 6 Hours
Forum Index -> Video -> Programming Page 1 of 1





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
You cannot vote in polls in this forum



Jump to:  
Display:   
About   Advertise   Forum Archive   RSS Feeds   Statistics