views:

308

answers:

2

Hi everyone;

I'm messed up with codec issue for days, and still couldn't see the big picture yet. It is my first time do deal with audio/video formats and codecs. So I really need some help about that. Here is the work.

I'm writing several components that is responsible for encoding and decoding customized mpeg files. On top of standart de/compression process (for both audio and video) i will implement some custom de/encryption. Writing both codec and software libraries for this. Things i can't figure out are listed.

  • For WMP, what is the codec locating policy.
  • How do I differantiate my custom file format from mpeg-3 format for example. What is the standarts and programming structs for this. (The real part I'm messed up is this. Container formats, video formats, fourcc codes...etc drive me to the death)
  • For this work on Windows what method do you suggest to write codec(DMO or Filter)

I'm hoping to cope with listed problems by your helps. Infos and some usefull links will be appreciated. Except MSDN :) because i couldn't find what i'm searching on it.

+1  A: 

For WMP, what is the codec locating policy.

Until Windows Media Player 7.0, it was just a pure DirectShow player. Since 7.0, Microsoft has started handling different file types differently. This was mostly the case with WMV files. WMP now will use MediaFoundation media pipeline in Vista and 7 for some file types.

How do I differantiate my custom file format from mpeg-3 format for example. What is the standarts and programming structs for this. (The real part I'm messed up is this. Container formats, video formats, fourcc codes...etc drive me to the death)

You could do this (lol, sorry for the MSDN link), if you are creating your own custom container format, but if you want to make life easier on yourself, I'd choose an existing and/or open-source container, such as AVI or MKV. When you create a stream in either of these formats, you'd provide a codec code, such as a fourcc for video or a format tag for audio. Since you are doing your own custom format, you should just make up your own fourcc or format tag values, but careful not to pick one people already use.

Lets say you were using an AVI. The built in avi demux would read the AVI headers and look at the meta data for each stream within the file. It might find a video stream with the fourcc DX50 and an audio stream with the format tag of WAVE_FORMAT_PCM. DirectShow will enum registered filters and query their pins to see if they support taking a DX50 video or a WAVE_FORMAT_PCM audio. So if you AVI had a fourcc of XXXX, DirectShow would enum filters looking for types that take XXXX. You would then make a transform filter that will accept fourcc XXXX. Your transformation filter will decode the video and output an uncompressed format. Maybe RGB24. DirectShow will detect that your output pin outputs that media type and will probably connect it directly to the renderer. The process is the same for audio, except we deal with format tags instead of fourccs (and you deal with WAVEFORMATEX and VIDEOINFOHEADER).

For this work on Windows what method do you suggest to write codec(DMO or Filter)

I've never written an DMO personally, but I would highly recommend looking into it. I've heard there is less boiler plate COM stuff and IIRC, MediaFoundation has a DMO wrapper, so you may get automatic MediaFoundation support.

Besides the DShow SDK samples, you may want to check out this. May help you get started. Also this website has great samples also, but might not be exactly what you want.

Jeremiah Morrill
Thanks for the answer. As I understand handling fourcc and format tag is being handled by default source filter. Then it's connecting to corresponding transform filter that i have to write myself. Still 2 questions:1- For audio what is the effects of using mp3 format.2- I couldn't find a element of structure VIDEOINFOHEADER for putting fourcc code.
Göktürk Gezer
There are no effects of using an MP3 format. For the sake of easy understanding, pretend that DSHOW doesn't know anything about MP3 format and the DSHOW docs don't say anything about MP3. To DShow, it's just another format defined by you :)The FourCC is in the VIDEOINFOHEADER.bmiHeader.biCompression of VIDEOINFOHEADER. One thing that might not be obvious, is the first 4 bytes of AM_MEDIA_TYPE.subType WILL be the fourcc too! The rest of the GUID will be FORMAT_VideoInfo (FORMAT_VideoInfo will be majorType)
Jeremiah Morrill
Thank you Jeremiah. All helped me to much.
Göktürk Gezer
Just noticed an error in what I told you! FORMAT_VideoInfo I meant to say MEDIATYPE_Video!
Jeremiah Morrill
Not a big deal, thanks :)
Göktürk Gezer
Me again :) I have a question about this "byte pattern" thing at your first link. I'm defining my file dependent format by these rules if i got that right. So, by these rules, do i have to define my custom fourcc code or wave tag in corresponding file format(avi or mp3) ??
Göktürk Gezer
I don't know much about the mp3 format, or if it is a container format. If using an AVI, MKV, MOV container formats, the headers will contain your tags/fourcc. For example, an encoding graph, using your transform filter, would look like:source_filter -> decoder -> your encoder transform filter --[outputs media type with your fourcc/format code]--> AVI Mux -> file writer.In this case, the AVI Mux filter will get your format (fourcc and format tag) via the output pin of your filter and automatically create the correct headers. The decode graph:source ->avi demux ->your decoder->etc
Jeremiah Morrill
A: 

Hi again. There isn't enough space for comments I think :)

I had some understanding about filters and directshow by your answers and graphedit program at last. I'll use AVI container for both audio and video. And internally i'll use mpeg format that'll be encrypted by my algorithm. I'll implement transform filter or DMO. (DMO likely)

I'm wondering how the AVI Splitter will deliver the data to my registered codecs. I mean in which format datas will be. I think there must be some standart. I have made a peace with MSDN along my researchs but couldn't find informations about actual buffer formats in data flow for individual formats. (AVI in my case)

Göktürk Gezer
There really is no buffer format. You simply get a buffer of your full sample. For instance, if you have a compressed video frame (using you custom compression/encryption) in an AVI, the AVI splitter will send you the full frame sample via your input pin.
Jeremiah Morrill
Will the splitter send me a header for the frame or just the content?
Göktürk Gezer