VideoHelp Forum




+ Reply to Thread
Results 1 to 5 of 5
  1. Member
    Join Date
    Aug 2006
    Location
    Switzerland
    Search Comp PM
    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?
    Quote Quote  
  2. 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
    Quote Quote  
  3. Member
    Join Date
    Aug 2006
    Location
    Switzerland
    Search Comp PM
    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.
    Quote Quote  
  4. Member
    Join Date
    Aug 2006
    Location
    Switzerland
    Search Comp PM
    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();
    }
    Quote Quote  
  5. As I told you, it is quite easy...
    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.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!