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?
+ Reply to Thread
Results 1 to 5 of 5
-
-
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#seqGUI for dvdauthor:
https://www.videohelp.com/~gfd/ -
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. -
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(); }
-
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.GUI for dvdauthor:
https://www.videohelp.com/~gfd/
Similar Threads
-
Stream Transport
By Soixante in forum ComputerReplies: 4Last Post: 4th Apr 2014, 05:05 -
Problem converting from MPEG Program Stream to Transport Stream
By vivajam in forum Newbie / General discussionsReplies: 5Last Post: 24th Jan 2011, 04:40 -
Some questions about the Transport Stream.
By Talayero in forum Video ConversionReplies: 4Last Post: 22nd Jul 2008, 18:42 -
Conversion from Transport Stream
By mparter in forum Video ConversionReplies: 3Last Post: 7th Mar 2008, 14:02 -
need MPEG2 Transport stream and Program stream profiler
By afarun in forum ProgrammingReplies: 3Last Post: 23rd Aug 2007, 01:06