Menu

MPEG2 Demux Config

Steve
2007-08-01
2012-10-29
  • Steve

    Steve - 2007-08-01

    Does anyone have any sample source for configuring the MPEG2-demux. Adding output pins, setting the AMMediaTypes for the pins etc..

     
    • Steve

      Steve - 2007-08-02

      I managed to get it working by remarking the following lines from the above example:

      //videoType.formatType = FormatType.Mpeg2Video;
      //videoType.fixedSizeSamples = false;
      //videoType.temporalCompression = true;
      //videoType.sampleSize = 0;

       
      • snarfle

        snarfle - 2007-08-02

        Interesting. Odd, but interesting.

        Glad it's working for you.

         
    • snarfle

      snarfle - 2007-08-01

      Well, there is some code in Samples\BDA\DTVViewer\BDAGraphBuilder.cs that might be useful. And there is some (really ugly) code in:

      http://directshownet.cvs.sourceforge.net/directshownet/directshowlib/Test/v1.3/IMPEG2StreamIdMapTest.cs?view=markup
      http://directshownet.cvs.sourceforge.net/directshownet/directshowlib/Test/v1.3/IMPEG2PIDMapTest.cs?revision=1.2&view=markup

      However, your best bet might be to look at http://www.codeproject.com/directx/MPEG2_Capture_Device.asp. While it is in c++, it is probably close to what you are trying to do. You can at least read it to see how things work.

       
    • Steve

      Steve - 2007-08-01

      I have looked at both sources and the code seems straight forward. The problem I am having is that after I create the output pins I map the streams. If I look at my graph with Graphedit the mappings don't exist. When I do mapstreams I don't get an error, but the stream mappings don't show up either and I can't connect other filters. I have tested building the entire graph in graphedit and it works fine. The following is the code for the mpeg2 demux:

                  object o;
                  hr = captureGraphBuilder.FindInterface(null, null, winMPEG2Demux , typeof(IMpeg2Demultiplexer).GUID, out o);
                  if (hr < 0)
                  {
                      Logger.DebugMessageLog ("Error Finding interface for MPEG-2 Demux");
                  }
                  mpeg2Demux = (IMpeg2Demultiplexer)o;
                  IPin vidPin;
                  MPEG2VideoInfo mvi = new MPEG2VideoInfo(); 
                  AMMediaType videoType = new AMMediaType();
                  videoType.majorType = MediaType.Video;
                  videoType.subType = MediaSubType.Mpeg2Video ;
                  videoType.formatType = FormatType.Mpeg2Video;
                  videoType.fixedSizeSamples = false;
                  //videoType.temporalCompression = true;
                  videoType.sampleSize = 0;
                  videoType.formatSize = Marshal.SizeOf(typeof(MPEG2VideoInfo));
                  videoType.formatPtr = Marshal.AllocCoTaskMem(videoType.formatSize);
                  Marshal.StructureToPtr(mvi, videoType.formatPtr, false); 
                  hr = mpeg2Demux.CreateOutputPin(videoType, "Video", out vidPin);
                  if (hr < 0)
                  {
                      Logger.DebugMessageLog("Error creating Video Ouput pin on MPEG-2 Demux");
                  }
                  DsUtils.FreeAMMediaType(videoType);
                  IMPEG2StreamIdMap videoStreamMap = (IMPEG2StreamIdMap)vidPin;
      

      IPin audioPin;

                  AMMediaType audioType = new AMMediaType();
                  WaveFormatEx wfe = new WaveFormatEx();
                  wfe.wFormatTag = 0;
                  wfe.nChannels = 2;
                  wfe.nSamplesPerSec = 48000;
                  wfe.nAvgBytesPerSec = 0;
                  wfe.wBitsPerSample = 16;
                  wfe.nBlockAlign = (short)(wfe.wBitsPerSample / 8 * wfe.nChannels);
                  wfe.cbSize = 0;
      
                  audioType.majorType = MediaType.Audio;
                  audioType.subType = MediaSubType.Mpeg2Audio;
                  audioType.formatType = FormatType.WaveEx ;
                  audioType.fixedSizeSamples = false;
                  audioType.temporalCompression = false;
                  audioType.sampleSize = 0;
                  audioType.formatSize = Marshal.SizeOf(typeof(WaveFormatEx));
                  audioType.formatPtr = Marshal.AllocCoTaskMem(audioType.formatSize);
                  Marshal.StructureToPtr(wfe, audioType.formatPtr, false); 
                  mpeg2Demux.CreateOutputPin(audioType, "Audio", out audioPin);
                  if (hr < 0)
                  {
                      Logger.DebugMessageLog("Error creating Audio Ouput pin on MPEG-2 Demux");
                  }
                  DsUtils.FreeAMMediaType(audioType);
                  IMPEG2StreamIdMap audioStreamMap = (IMPEG2StreamIdMap)audioPin;
      

      Then later after I connect the input to the MPEG-2 Demux filter I map the streams like:

      hr = videoStreamMap.MapStreamId(0xE0, MPEG2Program.ElementaryStream, 0, 0);
      if (hr < 0)
      {
      Logger.DebugMessageLog("Could not map stream id 0xe0 to video pin");
      }

                  hr = audioStreamMap.MapStreamId(0xC0, MPEG2Program.ElementaryStream, 0, 0);
                  if (hr &lt; 0)
                  {
                      Logger.DebugMessageLog(&quot;Could not map stream id 0xc0 to audio pin&quot;);
                  }
      
       
  • kjj902

    kjj902 - 2009-11-16

    Hi, Naildawg and Snarfle,

    I was searching posts about MPEG2VideoInfo, and found this one. I understand
    this is over two years old.

    But, I just have a quick question. Where is MPEG2VideoInfo struct? I have
    search all namespaces under DirectShowLib, but not able to find it.

    Apparently, Naildawg has used it in the posted C# code. How could I use it?
    What I need to do is similar to yours: to preview some MPEG2(H.264) Video. One
    step is to create an output pin of MPEG2 Demux. In an MS example (C++ code), I
    found that I have to use MPEG2VideoInfo to alloc memory for
    AMMediaType.formatPtr, but I could not find it under current DirectShowLib
    namespace.

    Thank you very much

     
  • kjj902

    kjj902 - 2009-11-17

    Hi, Snarfle,

    Sorry for the late thanks. I was caught by a few other emergencies and have
    just got a chance to look at your message carefully.

    It seems that we have to define MPEG2VideoInfo by ourselves. Are there any
    special reasons for not defining it in DirectShowLib?

    Also, according to http://beta.codeproject.com/KB/directx/MPEG2_Capture_Devic
    e.aspx,

    we should be able to use graphedt to build a graph to preview MPEG2 Video. But
    I can't open MPEG2 Demux properties dialog. (There is always an error message
    mentioning that the properties can't be shown.) I have followed the
    instruction to install DirectX, but it still doesn't work. Any idea for that?

    Many thanks indeed.
    kjj902

     
  • snarfle

    snarfle - 2009-11-17

    Sounds like you have failed to regsvr32 proppage.dll.

     
  • kjj902

    kjj902 - 2009-11-17

    Thank you very much indeed. After I resvr32 proppage.dll, everything works
    fine now. Many thanks.

     
  • kjj902

    kjj902 - 2009-11-18

    Hi, snarfle,

    Sorry for bothering you again with a few questions. I am try using graphedt to
    build a graph to preview a H.264 camera, but I don't know much details about
    that camera, so a lot of guess work.

    I am quite sure it pushes MPEG2 TS, since GraphEdt filter properties dialog
    shows that the SubType is MPEG2_TRANSPORT. I also think that the TS packet
    contains nothing but one H.264 Elementary Stream.

    However, I don't know the PID of the H.264 PES. Is there a way for me to find
    out the PID?

    Also, I am confused when adding a new output pin to MPEG2 demux using
    GraphEdt. I think I should choose "MPEG2 Program Video" for the media type,
    right? This "Program Video" has nothing to do with MPEG2 Program Stream,
    right? In the PID mappings, I think I should choose "Elementary Stream (A/V
    only), right?

    I can play with GraphEdt to understand the second question, but I stuck on
    finding out PID. There are so many choices. How could we find it out??

    Thank you very much.

     
  • snarfle

    snarfle - 2009-11-18

    Sorry, I'm not enough of an expert on H.264 or MPEG transport streams to be
    able to help here.

     
  • kjj902

    kjj902 - 2009-11-18

    Still thank you very much in any case. I will try posting a separate thread to
    see whether anyone else has any ideas.

     

Log in to post a comment.

Auth0 Logo