View Full Version : Container documentation


Eretria-chan
3rd August 2006, 15:55
I was wondering if anyone has technical info on layout and/or libaries for different containers? I want, if possible, to extract audio streams for the containers (mp4, ogm, mkv, avi, etc) without the use of a lot of external applications, if possible.

Any help is appreciated :thanks:

Sirber
3rd August 2006, 16:39
Look in the sourcecode of MediaInfo.

including libMatroska and GPAC in your app could be the way.

Eretria-chan
3rd August 2006, 16:44
Aye, MediaInfo. Messy, but the source is there.
Heard of libMatroska and GPAC is the framework for MP4Box, no? Nice. I'll see what I can find in those sources.

bond
3rd August 2006, 19:56
why not read the specs?

Eretria-chan
3rd August 2006, 20:00
I don't know where to find them. But if I could get my hands on them, I'd love to. Maybe I just haven't looked at the right places... hmmm...

Sirber
3rd August 2006, 20:01
why not asking bond? ;)

bond
3rd August 2006, 20:11
I don't know where to find them. But if I could get my hands on them, I'd love to. Maybe I just haven't looked at the right places... hmmm...:readfaq:

Eretria-chan
3rd August 2006, 20:24
Okay, so for now, no avi doc. Ogg is very complex (they're very bad at writing documentation), matroska - can't compile library, no tutorials, but if I got it working, then I could probably try something. Mp4? I don't know where to find the specs for it. Going to check FAQ for answers.

Koepi
3rd August 2006, 20:33
There is a ogg sdk (or use the libogg library source from http://www.xiph.org/downloads/). You just need to include a header file from it (and add the paths to the include dir) and can use it's functions to parse, mux and demux files.

Cheers
Koepi

Eretria-chan
3rd August 2006, 20:36
Ya, but does it say how? What is all the terms used? What do I need to locate the audio stream(s)? And then, how do I extract them? Such information does not exist. They describe the functions, sure, but it's still like finding a needle in a haystack.
It's just that every thing I find is broken somehow. No documentation how to use, does not compile because of missing files, no binaries...

OGG: No idea how to use. Bad doc.
Matroska: Doesn't compile.
MP4: No library found yet.
GPAC: Doesn't compile; no binaries. No doc.

It's driving me MAD. Why can't people do things RIGHT?

Sirber
3rd August 2006, 20:56
ogg is not very used so you can safely skip it.
gpac is for MP4 ;)

also, I remember me saying you that you will take 2+ years to do your GUI in C++ :D

Eretria-chan
3rd August 2006, 21:10
Don't be so sure, Sirber. The core function (the encoding process) is already finished (well, for AVI anyway). Trying to finish up a nice progress gui, then it will be a release worthy product.
I'm just bumping into issues which MFC / Windows really should have fixed, eg shouldn't be there (like drawing a transparent image). Oh, and the issue (I think) that converns MFC (or is it Windows?) is that it floods my dialog with paint messages eating up an entire core (and there's no code handling the paint message!).
It's just that, unlike you, I don't like to rely on external apps. Libraries are fine, but it would be cool if I could parse and extract the audio streams myself.

Oh and I have a couple of movies stored in ogm containers, so I do need it.

Sirber
3rd August 2006, 21:13
k

good luck with your project :)

Eretria-chan
3rd August 2006, 22:01
Thanks to an INCREDIBLY helpful article, I gained a little ground into ogg. Articles such as this: http://www.ogghelp.com/ogg/bb/viewtopic.php?id=73 is EXACTLY what I want to see! So helpful and explains it so well! If I had such documentation for all ogg I would be able to read it in NO TIME!

Sirber
3rd August 2006, 22:06
Also, OGM is not OGG :)

Eretria-chan
3rd August 2006, 22:14
No? Then how come I find an OGG HEADER in there?
EDIT:
OGM is another extention for the OGG container adopted by Windows users to distinguish music (OGG) and video (OGM). Although not an official extention it is used by DivX and Xvid encoders that put video into the Ogg container.
http://filext.com/detaillist.php?extdetail=ogm&Search=Search

Sirber
3rd August 2006, 22:43
I've been told (Sharktooth maybe) that OGM is a fork of AVI.

Eretria-chan
3rd August 2006, 22:45
FileXt says it's Ogg and I find that (at least my ogm files) are indeed ogg files because I'm actually reading data from them according to specs.

Sirber
3rd August 2006, 23:01
k. I will shot the layer then :D

foxyshadis
3rd August 2006, 23:04
OGM is AVI data stored in OGG, it's definitely not a fork of AVI. The riff headers are replaced with ogg headers. There's no such thing as native codecs in OGM though.

For MKV try Haali's parser (the open source base of his splitter):
http://haali.cs.msu.ru/mkv/MatroskaParser.zip

Eretria-chan
3rd August 2006, 23:06
Now. A question:
The specs and docs say all about (although very poorly) about the structure of an ogg file, but what of the actual data? How am I supposed to identify what is inside the container and what data is audio?

Oh, wow to the source. Very, very, very helpful it seems. I could borrow haali's code for Matroska, I bet.

Sirber
3rd August 2006, 23:11
make sure your thing is GPL though ;)

Eretria-chan
3rd August 2006, 23:37
Sigh. Liceses. You never get tired of them. But from what I remember, if you have permission from the author, it does not need to be GPL or? I never really understand these licenses and they are too complex to read.
EDIT: On a second look, maybe I can't borrow code. It isn't complete. It can only be used for reference. Still, that isn't bad.

foxyshadis
4th August 2006, 00:07
Why not use lavc, which can parse all of those formats and more?

Haali's parser and libogg are xiph/bsd, which requires only a copyright notice, and lavc is LGPL, which only requires source if it's compiled in directly (as opposed to using as a shared object).

Eretria-chan
4th August 2006, 00:12
There are lots of things that are named lavc. Can you provide a link?

Sirber
4th August 2006, 00:16
libavcodec

http://ffmpeg.mplayerhq.hu/

Eretria-chan
4th August 2006, 00:49
Ah, libavcodec. You should have said so! :sly:
But I didn't think libavcodec parsed file containers?

So I have the source of ffmpeg. So how do I compile the crap? Non-windows users always make life a pain with all their weirdness.

Sirber
4th August 2006, 02:28
use mingw

Non-linux user are so useless and crybaby ;)

foxyshadis
4th August 2006, 02:34
libavcodec itself doesn't parse containers, but its sister libavformat does. Look in that subfolder of the ffmpeg source tree and you'll get a list of all the containers it supports. mp4 support is implemented in mov.c, but you might still want something more robust, like mpeg4ip, lavf's isn't fully compliant. (See the big warning at the top of the file.)

Eretria-chan
4th August 2006, 11:09
use mingw

Non-linux user are so useless and crybaby ;)
I think linux users demand too much out of us. They expect us to know everything. I say it's the linux users who are at fault. Good thing Windows is easy, then Windows users doesn't make your life hard :p
EDIT: All I see is a HUGE table with files and I don't know what to get. Typical non-windows. Mostly anyway.

Sirber
4th August 2006, 12:20
http://prdownloads.sf.net/mingw/MSYS-1.0.10.exe?download
http://prdownloads.sf.net/mingw/mingw32-make-3.80.0-3.exe?download

maybe :)

Eretria-chan
4th August 2006, 12:27
I am SO going to scrap this until someone can post a step-by-step guide covering how to compile that stuff.

Sirber
4th August 2006, 12:46
lol!

good luck :D

Eretria-chan
4th August 2006, 12:58
On the bright side, I managed to travel through an ogg container from beginning to end (with my own code)!
Now parsing AVI files!

bond
6th August 2006, 09:54
found the mp4 specs?

there are lots of opensource mp4 parser: gpac, mpeg4ip, bento4, libavformat, mplayer, videolan... they should all work pretty fine

Eretria-chan
6th August 2006, 17:58
No, I haven't looked into it yet. There's lot of experimenting and trying to be done and I'm working with avi files now. I found the headers and the audio stream, but still having some issues extracting it and finding junk data in the container?

Also had limited progress on ogm. Then there's matroska...

Eretria-chan
9th August 2006, 14:56
This is bothersome! I find no good doc on matroska specs and the library *will not compile*! How am I supposed to understand it if I have no information or specs?

GodofaGap
9th August 2006, 15:01
http://www.matroska.org/technical/specs/index.html

libebml and libmatroska both compile fine on mingw. If you are finding it already hard doing that, maybe you are in way over your head writing your own fileparsers... no offense.

squid_80
9th August 2006, 18:00
I found Alex Noe's guide to be a lot better than the website: http://www.matroska.org/technical/specs/matroska.pdf

No problem building libebml or libmatroska here with visual studio either.

Eretria-chan
9th August 2006, 18:11
libebml and libmatroska both compile fine on mingw. If you are finding it already hard doing that, maybe you are in way over your head writing your own fileparsers... no offense.
Well, they didn't compile with either msvc or dev-c++, which AFAIK, uses mingw for compiler.
And it's not that I'm bad at writing stuff, it's just lack of information. I found a little article on avi and have written my own avi parser which works perfectly.
I will give you an example:

The official specs mention and describe some things about matroska, but does it tell what I find at what offset in the file and how those headers look like? And how they work? No, they don't - and it's that technical information that I need!

That pdf document seems technical and after *scanning* through it, it looks like it could be of help.

But I still don't understand how you compiled libmatroska? I gets lots of weird errors when trying to compile it. Perhaps it's that I can't download the right files? Then what am I supposed to download? How do I know what to download? Such information *never* exists with non-windows projects.

I download some samples from codeproject. Open and compile. Maybe some few errors, but they are easily fixable. I download other non-windows stuff, like ffmpeg or libmatroska... they don't compile. And I have troubles finding what to download.

squid_80
9th August 2006, 18:23
Both libmatroska and libebml have visual studio solutions in their make/vc6 and make/vc7 directories. Libebml needs to be compiled first as libmatroska depends on it.

Matroska has variable sizes for most headers, so you won't find information about offsets and such. Even the layout of the sections is variable. Once you get the hang of how ebml works it's easy enough: everything is an ebml element, and an element is made up of an ID, a size and data.

Eretria-chan
9th August 2006, 18:31
Both libmatroska and libebml have visual studio solutions in their make/vc6 and make/vc7 directories. Libebml needs to be compiled first as libmatroska depends on it.
Doesn't work out of the blue, either of msvc 2005 or dev-c++. I do use those solution, but libmatroska generates a lot of errors. Libembl compiles fine, though.

Matroska has variable sizes for most headers, so you won't find information about offsets and such. Even the layout of the sections is variable. Once you get the hang of how ebml works it's easy enough: everything is an ebml element, and an element is made up of an ID, a size and data.
Yeah, I read that. But I mean like this
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/avirifffilereference.asp
Obviously it is much different from any other article I've found because it explains the layout of an avi file. Using that information I was able to write a parser for avi files.

GodofaGap
9th August 2006, 18:37
If you want help with compiling I am sure you understand you need to give more info than "weird errors".

Also, if you want online help with Matroska you can go to irc.corecodec.org/#matroska

AFAIK there are no other documents describing Matroska as the ones given before, so they will have to do. :p

Eretria-chan
9th August 2006, 18:40
If you want help with compiling I am sure you understand you need to give more info than "weird errors".
Yes, I figure... but there are 100s of them. There might just be a way around it, though... MediaInfo contains both the dlls and libs for libmatroska.
But you *did* say you were able to compile them, so is there any possible reason you could tell *how* you did it? What files you downloaded? What settings you changed? A walkthrough.

Also, if you want online help with Matroska you can go to irc.corecodec.org/#matroska
Last I went there no one helped me >_< Though I suppose I could try again.

AFAIK there are no other documents describing Matroska as the one given before, so they will have to do. :p
And it's going to be a headache before I can get it to work with that poor documentation...

GodofaGap
9th August 2006, 18:52
I compiled with mingw so I can only explain that.


do an SVN checkout of libebml and libmatroska
cd to the mingw dir of libebml and do 'make'
copy libebml.dll.a to ./mingw/lib and ./libebml/ebml/ to ./mingw/include (as a whole direcotory)
go to the mingw dir of libmatroska and do 'make' again


That's all.

And it's going to be a headache before I can get it to work with that poor documentation...
Please stop complaining. No one is asking you to do anything.

Eretria-chan
9th August 2006, 18:56
If only it was that easy. I don't want msys/mingw crap on the computer. We're not living in DOS anymore.

GodofaGap
9th August 2006, 19:29
Then why did you ask me how I did it?

But ok, suit yourself. You're not worth any more of my time.

Eretria-chan
9th August 2006, 20:37
Then why did you ask me how I did it?

But ok, suit yourself. You're not worth any more of my time.
How did I know you used mingw? Why am I to sacrifice easyness to compile some crap and install some non-windows crap. If Linux wasn't so command-liny-ish I bet a lot more people would try it out.

emmel
9th August 2006, 20:55
If you take a look at the libebml files, you'll find ready-to-go directories for linux, mingw32, vc6, and vc7. So, you'll have to choose from one of those, or do your own port.

I just followed GodofaGap's instructions to check if really is so hard. It took 6 minutes to download the source and compile the libs.

Eretria-chan
9th August 2006, 21:01
If you take a look at the libebml files, you'll find ready-to-go directories for linux, mingw32, vc6, and vc7. So, you'll have to choose from one of those, or do your own port.
Yes, works for libebml, but not for libmatroska.

I just followed GodofaGap's instructions to check if really is so hard. It took 6 minutes to download the source and compile the libs.
It's not that I can't do it, but I don't *want* to. I will *not* download all that crap again and install it ad polute my system because it can't reside in a directory which has spaces in it. And I won't pollute my system with a stupid dos-like prompt that uses linux commands & directory syntax. This is windows. We like GUIs and not to type commands ourselves.

emmel
9th August 2006, 21:20
Yes, works for libebml, but not for libmatroska.

Well, there you have cygwin and macosx also to choose from. Anyways, it works fine.


It's not that I can't do it, but I don't *want* to. I will *not* download all that crap again and install it ad polute my system because it can't reside in a directory which has spaces in it. And I won't pollute my system with a stupid dos-like prompt that uses linux commands & directory syntax. This is windows. We like GUIs and not to type commands ourselves.

If you don't like it, then use vc6, vc7 or do your own port.

All MinGW -stuff is located in one single diretory and your system is supposed to remember only one single environment variable (path). No fooling around with the registry. It is not spread all over the disk and system and it does not pollute anything. Using spaces in names is a bad practise anyways.

Just use it to build the libs, and then continue with the tools you prefer. Knowing linux or mingw is simply a must whether you like it or not. GUIs are supposed to make life easier, but if and when they do not, it is better to forget about them and get back to basics.

Eretria-chan
9th August 2006, 21:52
If you don't like it, then use vc6, vc7 or do your own port.
I tried, but it didn't work did it?

All MinGW -stuff is located in one single diretory and your system is supposed to remember only one single environment variable (path). No fooling around with the registry. It is not spread all over the disk and system and it does not pollute anything. Using spaces in names is a bad practise anyways.
I know it might not be a good idea, but programs that have issues with it needs to be fixed. All my programs are installed into a directory which has a space (Yes, a SPACE!).

Just use it to build the libs, and then continue with the tools you prefer. Knowing linux or mingw is simply a must whether you like it or not. GUIs are supposed to make life easier, but if and when they do not, it is better to forget about them and get back to basics.
We're not living in DOS anymore, so grow up. That's all the advice I can give to linux. It's quite pathetic. No wonder no one but hard-core savvy users use it.

Sirber
9th August 2006, 22:06
We're not living in DOS anymore, so grow up. That's all the advice I can give to linux. It's quite pathetic. No wonder no one but hard-core savvy users use it.Linux ain't dos... :mad:
Linux ain't easy
Life ain't easy
so Linux is Life! :D

Eretria-chan
9th August 2006, 22:08
Linux != user friendly
Linux == pathetic
On a second note, let's stop this pointless discussion. I just want to build parser for container but it isn't easy. Especially not thanks to all the linux crap out there.

Sirber
9th August 2006, 22:09
Linux != user friendly
Linux == pathetic
Windows == user friendly
Windows === pathetic

=== is php style, means equal and same type

foxyshadis
9th August 2006, 22:19
Well, to be honest, open msys and typing
cd /ffdshow
make
has never been a particular burden on me, even though I vastly prefer IDEs and only use msys when forced. (Using fstab to symlink the folder.) I save that for useless compiler errors. If it's an affront the process of running the commands can be automated into a batch file. But most free container/codec formats are developed on *nix and use their conventions.

Once you have the dll all you need is the .mak to use it to link with any other compiler.

Putting spaces into folder names is not "bad practice", and not supporting them is just stupid in 2006 - but mingw/msys/cygwin has never given me trouble with them, for all their occasional dire warnings. Dev-C++ (and some ancient win16 crap) is the only software I know that refuses to read them. C'mon, it's not 1986 anymore, even unix supports them. Assuming everything's going to be in /bin is about as laughable and hackish as software that assumes everything goes in C:\Program Files or C:\Windows. [/rant]

Eretria-chan
9th August 2006, 23:56
Windows == user friendly
Windows === pathetic

=== is php style, means equal and same type
Well, in C++ == means equal and != means not equal and I'm a c++ user.
Aside from that, is there any doc that tells how to use libmatroska? There is none from what I could see in the source download.

Oh and did I tell you that it's extremely stupid not to provide binary downloads? Not everyone has a compiler y'know... or the knowledge to use 'em.

I can copy the stupid dll and libs and includes from mediainfo and screw msys/mingw completely.

squid_80
10th August 2006, 10:03
Well, in C++ == means equal and != means not equal and I'm a c++ user.
Aside from that, is there any doc that tells how to use libmatroska? There is none from what I could see in the source download.
There's example programs in the test directory.
Oh and did I tell you that it's extremely stupid not to provide binary downloads? Not everyone has a compiler y'know... or the knowledge to use 'em.
No, providing binary downloads is stupid since practically every compiler has different standards. And what would you do with them if you didn't have a compiler?

Haali
10th August 2006, 10:11
There are few layout rules for matroska containers:
* The EBML header must precede other elements in the file
* It's preferable to have the CRC element at the start of its parent node
* Blocks in clusters must be properly interleaved and should appear in coding order

All other elements can occur in any order, though most files will have SegmentInfo, Tracks, SeekHead and other similar info about the file near its start, and some of it at the end (like tags).

Eretria-chan
10th August 2006, 12:46
There's example programs in the test directory.
I'll check them out but I don't have much hope.

No, providing binary downloads is stupid since practically every compiler has different standards. And what would you do with them if you didn't have a compiler?
Providing binary downloads is the smartest things anyone has done... yeah...
Do I need to bother myself with what is inside the source? So far as I can tell - I only need the dll, headers and libs and that's all.

Eretria-chan
10th August 2006, 15:19
On a side note, the avi index (idx1) seems to refer data out-of-order. If I scan the file manually and find all the audio samples, then write them to a file, then it can be played back. But when I do it with the index, it doesn't play. I noticed that the first found sample in the file was not the same as the first sample referd to in index. Is it supposed to be like that?