开发者

Video size (horizontal and vertical) from MPEG-2 Transport Stream

I need to know how to get the height and width, and any other descriptive data I can, out of an MPEG Transport Stream (TS).

Before this answer shows up: I'm well aware of the video sequence header (00 00 00 B3). That's part of the spec for an MPEG program stream (i.e. an MPEG file), not the MPEG transport stream.

If I save out a transport stream to a .ts file I can get this information from ffmpeg, but I need to be able to do it in开发者_高级运维dependently from ffmpeg in an environment where ffmpeg isn't available. Therefore I need to parse for this data in the file manually, and I can't seem to find ANYTHING about any relevant metadata except timestamps (slice starts) from MPEG-TS.

Thanks!


I'm afraid that you'll have to check ISO 13818-1 (also known as H.222) and read a bit about transport stream packets, PID filtering and PES packets.

The stream is divided into packets. Each packet is (normally) 188 bytes long. The packet header contains the PID (packet ID) which allows you to filter only the packets you're interested in.

The packets make up PES packets which hold MPEG-2 data + metadata (such as timing data). You will need to build and then parse the PES packets before you can find out the width and height of the video.

How do you know which PIDs you're interested in? For that you'll have to read about PAT and PMT. The PAT tells you how to get the PMT, and the PMT tells you which PIDs contain MPEG-2 information.

All of this is described (at length) in the documents above. But there are many tutorials and explanations online. For example here but there are many others. The Wikipedia article is a good place to start from.


Video size is NOT a property of Transport stream. This is a property of the elementary video stream itself. The transport stream or PES packet doesn't contain any header.

In order to extract the resolution (width x height) you will have to identify PES start (with PUSI) packet and then start parsing the es headers. You need to extract Sequence header part of ISO/IEC 13818-part 2 (video) will give you the answer. Check this wiki for quick reference.


Actually video sequence header (00 00 01 B3) is a part of ISO/IEC 13818-2 specification, which describes elementary video bitstream. So transport stream will contain this header too.

Problem here is to extract this header contents. You can't just find this start code and use bytes that follows it. It can be quite a complicated task because: 1. Header contents can be split into two PES or transport stream packets 2. If transport stream contains not only video stream, this sequence of bytes can be found in some audio or binary data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜