MPEG 2 - Adding custom tags via editing the source
I'm looking for advice and whether what I want to do is possible.
I've been ask to create something similar to ID3 mp3 tags that can be used with MPEG 2/MPEG-TS video files. Because I'm a crude individual, I was thinking of just dumping some sort of XML structu开发者_如何转开发re within the file itself. However, this causes problems with applications trying to decode/play the video file as the app is not expecting XML/ASCII data in the file.
I'm not sure whether it is possible to have some sort of END OF FILE 'command' that can be amended to the end of MPEG files, and I can dump my XML after that part.
Compatibility wise, I only need avoid the video file from 'breaking' any commercial app that is reading it. The tag information will be parsed by an application I have yet to write.
Any ideas? Or is what I'm suggesting impossible?
Thanks.
Any program that is decoding an MPEG2-TS file will be looking for a 188 byte packet over and over again. If you look at the hex, you will see a 0x47 byte, which is the sync byte (also first byte) of every packet every 188 bytes. That is why adding XML data to the file will screw up any decoders.
What you could do is add your own packets, or hijack the null-PID packets typically at the start of an MPEG2-TS file. Unfortunately, to do this properly, you would likely want this data to be in a Network Information Table, which may not already exist. This means you may have to add a reference to the NIT in the PMT. All requiring advanced knowledge and parsing/writing capability of the transport stream.
You might be able to get away with adding packets at the start of the file without having to adjust clock references. Or just hijack the existing null-PID packets (no clock reference changes needed). Then in your new packets use a packet ID that probably won't be used like 8190. Doing this without modifying the PMT to reference a NIT would not be a completely valid MPEG2-TS because of the unreferenced PID, but would probably still work in most commercial decoders.
A lot of this is not making sense I'm sure, because you are just trying to add some tag info and not familiar with MPEG2-TS. But the standard that defines the exact format is ISO/IEC 13818-1. Beware this is pretty heavy reading. If you want to go lighter (and cheaper), you might be able to get away with just wikipedia.
There is a straight forward way to do this MPEG 2/MPEG-TS
Basically you can add custom descriptors and/or custom tables (and even custom stream types) which has its' own PID in the stream. They won't be WITHIN video, and won't break working application, but they can be read
To give you perspective, Teletext, VBI data, Cue-tone signals, EPG, DSC-CC commands (and some even talk about using MPEG systems for transmitting general data), are all example of Custom data over MPEG-Ts.
Go through MPEG2- ISO 13818-1 in details (there is a section on custom tables) and refine your question.
精彩评论