none
Gettting H.264 out of MPEG-2 Demultiplexer for DVBT BDA

    Question

  • I have created the following graph:


    I am able to tune to a DVB-T program (I registered proppage.dll to get tuner properties) and I always get sound. But sometimes I do not get video. Demux filter does not tell to the output that it is streaming H.264 so Microsoft DTV-DVD gives black screen and other H.264 decoders do not connect at all to the pin 003. Only after I run the graph once, then disconnect Microsoft DTV-DVD and do "Render pin" - then Microsoft DTV-DVD connects automatically again and this time I get video. Also then I am able to disconnect Microsoft DTV-DVD and connect some other H.264 decoder (but some of them still refuse to connect, like DivX H/264).

    What is the procedure to _always_  get MPEG-2 demuxer to work fine with H.264?  I mean - how can I change in the Graphedit the output media type to h.264 for MPEG-2 demuxer pin before I connect anything to that pin? Does Graphedit support modifying media subtype at all?

    And also how that H.264 supporting procedure can be done from code - is it just a simple setting for output pin subtype and after that all H.264 codecs will be able to connect to it or maybe there are some caveats? 



    Thanks.
    Tuesday, February 23, 2010 8:44 PM

Answers

  • Hi Midix,

    that is a really good question.  there is very little documentation out there on h264 BDA streams.


    it is possible to change the media type on the pin, however AFAIK the pin type gets overridden.  I am not sure if it is the network provider or the TIF that does the overriding.  


    if you want to do it just from graphedit then you can add 2 new pins to the end  of the demuxer (call them testpin31 and testpin32 ) ( you have to press the refresh button on graphedit to get it to show the new pins )

    make testpin31 a video mediatype.  im afraid i dont know what mediatype h264 is under graphedit ( i am only familiar with the mpeg2 stuff ).
    make testpin32 an ac3 mediatype.  then when the graph is running find out the PID for pin 3 and 4.   set the PID from pin 3 to testpin31  and the PID from 4 to testpin32.

    now you can change the mediatypes as much as you like on the 2 test pins without them being overwritten.



    here in Australia AFAIK the HD broadcasts are all still mpeg2, so i am looking forward to the time i can test out h264 BDA broadcasts.



    i find it very interesting that you have to start the graph, then stop it disconnect then reconnect the dtv-dvd video decoder to get it working for h264.  

    i found a similar situation with the audio when changing from a from SD to HD.  i found that i needed to use and outside filter (ac3filter) to get audio working when swapping channels. if there is a way to do it with the microsfot dtv-dvd audio decoder that would be great.




    definitely update this thread with any progress that you make.




    Cheers
    Anton




    • Marked as answer by midix Saturday, February 27, 2010 11:52 AM
    Wednesday, February 24, 2010 3:07 PM

All replies

  • Hi Midix,

    that is a really good question.  there is very little documentation out there on h264 BDA streams.


    it is possible to change the media type on the pin, however AFAIK the pin type gets overridden.  I am not sure if it is the network provider or the TIF that does the overriding.  


    if you want to do it just from graphedit then you can add 2 new pins to the end  of the demuxer (call them testpin31 and testpin32 ) ( you have to press the refresh button on graphedit to get it to show the new pins )

    make testpin31 a video mediatype.  im afraid i dont know what mediatype h264 is under graphedit ( i am only familiar with the mpeg2 stuff ).
    make testpin32 an ac3 mediatype.  then when the graph is running find out the PID for pin 3 and 4.   set the PID from pin 3 to testpin31  and the PID from 4 to testpin32.

    now you can change the mediatypes as much as you like on the 2 test pins without them being overwritten.



    here in Australia AFAIK the HD broadcasts are all still mpeg2, so i am looking forward to the time i can test out h264 BDA broadcasts.



    i find it very interesting that you have to start the graph, then stop it disconnect then reconnect the dtv-dvd video decoder to get it working for h264.  

    i found a similar situation with the audio when changing from a from SD to HD.  i found that i needed to use and outside filter (ac3filter) to get audio working when swapping channels. if there is a way to do it with the microsfot dtv-dvd audio decoder that would be great.




    definitely update this thread with any progress that you make.




    Cheers
    Anton




    • Marked as answer by midix Saturday, February 27, 2010 11:52 AM
    Wednesday, February 24, 2010 3:07 PM
  • I used some graphspy library which registers all the graphs on ROT, so I could hook into Windows Media Center. I could not save the graph (GraphEdit said - unsupported feature)  but I was able to stop/play it from GraphEdit and Windows Media Center reacted appropirately.

    Now I know that WMC is using a filter called "Decoding tagger filter" to force stream subtypes. A solution similar to this one:

    I do not know if it is only in Windows 7 or also in Vista and XP, I guess no, because then the author of that article would not have such problems on Vista/XP.

    When connecting to WMC, there were 4 graphs - one for Analog TV, I ignored that, two seemed identical, they both had some unknown tmpSBE filters as a root and they had those "Decoding tagger filter" between out pins of tmpSBE and in pins of DTV/DVD audio and video decoders.

    The third graph connects to Network provider and my TV tuner as ususal, but then it has many  "ET Video" and " ET Audio" filters and "Video analysis" filters between MPEG2 Demux and Time Shift Sink filter (BTW, time shifting works straight from Graphedit when clicking Pause button).

    It seems I have not lucky day today - I crashed GraphEdit some times. The worst thing is - after crashing once, none of DVB software was detecting my TV tuner. DVB dream told Hardware Error1, gb-pvr just stopped responding for a while and then returned to the home screen.  But Windows Media Center worked normally. Really curious, how it can get access to my TV tuner regardless of anything. 

    Is there any way I can reset BDA after failed experiment to avoid restarting my PC? If WMC is able to do that, then there must be some way to achieve that.
    Thursday, February 25, 2010 4:18 PM
  • Hi Midix


    with the resetting i do it physically.

    I use usb tuners for development and if something major goes wrong i unplug them.   that way i dont have to reboot the machine.


    With graph edit could you post a screenshot of the graph for wmc.



    cheers
    Anton





    Friday, February 26, 2010 12:41 AM
  • I used the tool described here:
    http://alax.info/blog/777

    it can be downloaded from the project SVN website, just registered DirectShowSpy.dll library and was able to get the following graphs:

    http://i283.photobucket.com/albums/kk308/progmars/wmc2.png

    http://i283.photobucket.com/albums/kk308/progmars/wmc1.png


    By the way, how "generic network provider", "Microsoft Network provider" and "Microsoft DVBT network provider" differ?  The third one crashes GraphEdit if I do a TuneRequest.

    Anyway, I can tune only if using a graph which is created programmatically. If I try to create a graph from scratch in GraphEdit, something does not work. I guess, one problem is the MPEG2 demultiplexer - the one which is inserted if I inspect some other program's graph, has a yellow clock on it. If I find MPEG2 Demultiplexer in Filters dialog and insert it - it does not have that yellow clock icon. I just cannot make it to use clock, no matter how I try :( I think I'll stop trying to do that in Graphedit, I have some C# code to play with, so I 'll try to get H264 out of the code, where I have more control over the process and pins.

    Also it is weird that I have to create a tune request before I connect filters (according to MSDN). Then the workflow seems illogical - what if I need to scan for channels at the beginning because I do not know any ONID/TSID/SID? Does it mean, I have to construct and destruct my graph many times during the running time of my application?


    Friday, February 26, 2010 5:41 PM
  • Hi Midix,

    By the way, how "generic network provider", "Microsoft Network provider" and "Microsoft DVBT network provider" differ?  The third one crashes GraphEdit if I do a TuneRequest.


    i only use microsoft dvbt network provider.  AFAIK its the one to use for any digital free to air transmissions.  i havent used the other network providers.

    it definitely works from graphedit.   here is a graph under windows 7 that will show a tv show.

    http://i738.photobucket.com/albums/xx21/smovietv/tunerequest.png

    the things to note on the tunerequest is the carrier frequency.   177500 is for channel 7 here in australia ( mpeg2)  the rest of the values are -1.  once you type in a carrier frequency for one of your tv stations, press the "submit request" button.   then run the graph.


    i havent included the audio to keep the example as simple as possible.

    Anyway, I can tune only if using a graph which is created programmatically. If I try to create a graph from scratch in GraphEdit, something does not work. I guess, one problem is the MPEG2 demultiplexer - the one which is inserted if I inspect some other program's graph, has a yellow clock on it. If I find MPEG2 Demultiplexer in Filters dialog and insert it - it does not have that yellow clock icon. I just cannot make it to use clock, no matter how I try :( I think I'll stop trying to do that in Graphedit, I have some C# code to play with, so I 'll try to get H264 out of the code, where I have more control over the process and pins.


    with the yellow clock,  dont worry about it till you have everything else going.  it is to help keep audio and video in sync.
    Also it is weird that I have to create a tune request before I connect filters (according to MSDN). Then the workflow seems illogical - what if I need to scan for channels at the beginning because I do not know any ONID/TSID/SID? Does it mean, I have to construct and destruct my graph many times during the running time of my application?
    You are right on creating a tune request before connecting the graph seems a little illogical, but "so be it", the end result works and it is the only way.
    there is sample code in directshowlib that goes through how to do it.  Be aware though it the sample does not work under windows 7.  under vista or xp it will work.  the name of the sample is "DTVViewer"

    Scanning channels is a whole other can of worms.  To get started, if you can find out the frequency of one of your tv stations, you can test with that.
    I used a program called "scanchannelsbda uk" (dont worry about the uk part )  to find out my local fequencies, onid, tsid and SID.  

    there is also source code available for scanchannelsbda uk.  a guy called nate worked all this stuff out a few years back and his work really is the only solid examples available.

    You wont have to construct/destruct your graph multiple times for mpeg2.  for channel changes from mpeg2 to h264 i dont know.


    BTW if you do end up running scannchannelsbda can you email me the log file from it ( antonwinter [at] smovietv.com )


    Cheers
    Anton

    Friday, February 26, 2010 11:22 PM
  • Thanks a lot for help, now it works! And I got some idea also about audio problems.

    What confused me was that if I connect to some graph in some application, pin 007 of demux is going to audio. So I kept rendering 007 to audio for my own Graphedit graphs and got no audio and no video (because of not being able to render H264) and decided that I have some tuning problems - especially because the Network provider also did not show Signal strength right after the tune request.

    Now I inspected the MPEG2 demux pins and did as you suggested. I 'll describe it step by step:

    1. Insert Microsoft DVBT Network Provider.

    2. Use default tuning space to issue request. I get parameters from gb-pvr application, also my hardware box decoder for TV set shows ONID/TSID/SID.

    3. Now when I look at properties for Microsoft DVBT Network Provider still signal strength is 0. I noticed that sometimes it says "-2147467259 when .. ISCannngTuner::get_SignalStrength" but after everything is connected, this error disappears.

    4. Insert Tuner and Capture and MPEG2 Demux. Connect them all as usual. Right after I connected Tuner, when looking at properties for Microsoft DVBT Network Provider, it shows some reasonable number at signal strength. So it seams tune request is OK. Then connect capture and demux, demux gets populated with many pins. When looking at the mapping, there are no PIDs yet - I guess they'll appear after TIF filter. STill I tried to render - just for fun - they all (except 001, which I left untouched for now) render to "Microsoft DTV DVD video decoder" or audio decoder. It seems MPE2 Demux has its own internal default mapping which works even when no info from tuner about PIDs is received. 

    5. Insert BDA MPEG2 Transport Information filter. Connect to pin 001. Still no PID mapping info in Demux properties.

    6. Run the graph for some seconds and then stop. Now finally there is PID/pin mapping visible in Demux properties.

    7. Now I did as I've seen in other graphs - render pins 004 and 007. Run graph again - no sound, no video. Inspecting PID mappings - and surprise: 
    pin 007 is not mapped to anything at all. But when I did Render pin, it rendered to "Microsoft DTV DVD audio decoder". Really curious - why MPEG demux needs so many pins if most of them are not mapped to anything. 
    Pins 003 and 004 are both mapped to "Elementary stream (A/V only)". But if you try to render them - they both give "Microsoft DTV DVD video decoder". Still no audio at this point - pin 007 does not give anything out.

    8. Now I did as you said - created new pins, called them Audio (MPEG1 Mono format, I know our TV company is using it for audio) and Video (H264) and mapped PID of 003 to Video, PID of 004 to Audio pins - it somehow logically seems right, that if Demux has only two PIDs for "Elementary stream (A/V only)", then one should be audio and not video (although they both render to video by default).

    9. Render Audio and Video pins. Audio by default was rendered to ffdshow. Video - to "Microsoft DTV DVD video decoder".

    10. Run the graph. And - it works! 

    But still no sound on pin 007. This is confusing - which pin then should be used for audio - 004 or 007 and when to use which? The first idea is - after I add demux and TIF in C# code, I could iterate through all the pins and find the first audio and the first video, render both, and then it should work, hopefully also for XP and Vista.

    And next time I  tuned to other channel, I got no audio any more, but the video was playing from the previous channel. 

    When inspecting PID mappings, I saw that 003 and 004 have different PIDs now. So - for each tune request I get different audio/video PIDs and my self-made pins do not work any more. From C# I can use pins 003/004, just if I could always find the right media type to force on them - so the question is when should I look what decoder to attach to each pin, how to find out the media subtype when it is exposed on a pin? 

    Also this ability to render video from previous channel when new tune request has been issued, gives me idea about how can PIP functionality be implemented :D

     I made a second Video2 pin, mapped it to new video and now I got two video windows - form old and form new tune request. But audio did not work that way - old Audio pin was silent.

    And even now after I have run the graph multiple times, pins 004 and 003 still say:

    Major Type:  Video - Sub Type:  MPEG2_VIDEO - Format:  RGB  704x480, 0 bits,
    Aspect Ratio: 16x9,
    Interlace format: Frames
    rcSrc=(0,0,704,480)
    rcDst=(0,0,0,0)
    CtrlFlags=00000000


    Anyway, thanks for idea about pin config, it will help me to move on.
    Saturday, February 27, 2010 11:51 AM
  • Good To hear Midix,


    Pin 4 and pin 7 for audio.  that is also an interesting one.


    There is an easy fix.   You can click on my profile and look at my threads.   I have a couple posts on how to set up pin 4.   it actually is easy to fix, but boy did it take a while to find an answer to it.



    Cheers
    Anton

    Sunday, February 28, 2010 12:16 AM
  • So I got to coding - everything is fine with audio (although automatically pin 007 is recognized as audio, for now I do not care, as long as I hear something). I am able to insert any audio decoder I want.

    The problem is still video - I can connect only Microsoft DTV/DVD Video Decoder in both Graphedit and form code using DirectConnect() and a H264 media format specification (which I got from MediaPorta SVN repository. 
    Can anyone point me to the H264 format description which I can use in ConnectDirect to connect ffdshow, DivX or some other non-"Microsoft DTV/DVD Video Decoder" to the MPEG2 Demux?

    Thursday, March 04, 2010 5:55 PM
  • Hi Midix,

    here is some code from Nates library that may help.  it sets up media types.   i cut/paste the one the one for h264 and mpeg4.  the rest of the code can be found 



    Set the mediatype on the video pin before you do the directconnect.   this stuff here is "probably the way to do it"  unfortunatley without a h264 broadcaster here, i an unable to test it, so do let me know if it is on the right path.



    HRESULT FilterGraphTools::GetH264Media(AM_MEDIA_TYPE *pintype)
    
    {
    	HRESULT hr = E_INVALIDARG;
    
    	if(pintype == NULL)
    		return hr;
    
    	ZeroMemory(pintype, sizeof(AM_MEDIA_TYPE));
    	pintype->majortype = MEDIATYPE_Video;
    //	pintype->subtype = FOURCCMap(MAKEFOURCC('h','2','6','4'));
    	pintype->subtype = H264_SubType;
    	pintype->bFixedSizeSamples = FALSE;
    	pintype->bTemporalCompression = TRUE;
    	pintype->lSampleSize = 1;
    
    	pintype->formattype = FORMAT_VideoInfo;
    	pintype->pUnk = NULL;
    	pintype->cbFormat = sizeof(H264VideoFormat);
    	pintype->pbFormat = H264VideoFormat;
    
    	return S_OK;
    }
    
    HRESULT FilterGraphTools::GetMpeg4Media(AM_MEDIA_TYPE *pintype)
    {
    	HRESULT hr = E_INVALIDARG;
    
    	if(pintype == NULL)
    		return hr;
    
    	ZeroMemory(pintype, sizeof(AM_MEDIA_TYPE));
    	pintype->majortype = MEDIATYPE_Video;
    	pintype->subtype = FOURCCMap(MAKEFOURCC('A','V','C','1'));
    	pintype->bFixedSizeSamples = FALSE;
    	pintype->bTemporalCompression = TRUE;
    	pintype->lSampleSize = 1;
    	pintype->formattype = FORMAT_MPEG2Video;
    	pintype->pUnk = NULL;
    	pintype->cbFormat = sizeof(g_Mpeg2ProgramVideo);
    	pintype->pbFormat = g_Mpeg2ProgramVideo;
    
    	return S_OK;
    }
    Friday, March 05, 2010 12:43 AM
  • Difference between Generic Provider and DVB-T Network provider is that first one is newer and works fine for automapping with new MPEG2 demux and TIF. Check my post here about that : http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/99b2bb6f-13d5-4747-9834-904e166434bc

    "What is the procedure to _always_  get MPEG-2 demuxer to work fine with H.264?"

    I experimented a lot with DVB-T content both MPEG and H.264/AVC/AAC in FTA and scrambled channels and did not notice any instability of media type detection.

    If you want to stop automapping, just remove TIF. Or switchback to DVB-T provider.

    Monday, May 17, 2010 6:57 AM
  • I've been running into the H.264 issue with a DVB-S graph. While MPEG-2 video plas well, H.264 channels do not. I only get a black image. The video media type is still MPEG-2 and not H.264 after tune request. I suspect there should be a dynamic format change happen on the pin?

    What are the correct steps to make H.264 work? Is there any reasonable documentation on BDA graph building. The BDA information on MSDN is poor and incomplete and doesn't even mention H.264-related topics. It would be great if a Microsoft employee explain step-by-step how to get a proper BDA graph that works for both MPEG-2 and H.264 channels.

    Here is the graph of my application:

     3dtv.at Stereo Renderer
      In connected to 3dtv.at Stereo Transformation (P420, 12 bpp, 1 x 704 x 240, 44:15)
    MPEG-2 Sections and Tables 0009
      In connected to BDA MPEG2 Transport Information Filter 0008 (MPEG2 sections, MPEG2 data)
    DirectSound Audio Renderer
      Audio Input pin (rendered) connected to Microsoft DTV-DVD Audio Decoder (2 ch, 48000 Hz, 32 bits)
    MPEG-2 Sections and Tables
      In connected to MPEG-2 Demultiplexer (MPEG2 sections, MPEG2 data)
    BDA MPEG2 Transport Information Filter
      IB Input connected to MPEG-2 Demultiplexer (MPEG2 sections, DVB SI)
      OOB Input not connected
      iTV Out not connected
      SBE OUT not connected
    3dtv.at Stereo Transformation
      Input 1 connected to Microsoft DTV-DVD Video Decoder (NV12, 12 bpp, 704 x 480, 16:9, 59,939998626709 fps)
      Subpicture Input not connected
      Output 1 connected to 3dtv.at Stereo Renderer (P420, 12 bpp, 1 x 704 x 240, 44:15)
    BDA MPEG2 Transport Information Filter 0008
      IB Input connected to MPEG-2 Demultiplexer (MPEG2 sections)
      OOB Input not connected
      iTV Out not connected
      SBE OUT connected to MPEG-2 Sections and Tables 0009 (MPEG2 sections, MPEG2 data)
    Microsoft DTV-DVD Audio Decoder
      XForm In connected to MPEG-2 Demultiplexer (2 ch, 48000 Hz)
      XFrom Out connected to DirectSound Audio Renderer (2 ch, 48000 Hz, 32 bits)
    Microsoft DTV-DVD Video Decoder
      Video Input connected to MPEG-2 Demultiplexer (MPEG2, 704 x 480, 16:9, 59,939998626709 fps)
      Subpicture Input not connected
      Video Output 1 connected to 3dtv.at Stereo Transformation (NV12, 12 bpp, 704 x 480, 16:9, 59,939998626709 fps)
      ~Line21 Output not connected
    MPEG-2 Demultiplexer
      MPEG-2 Stream connected to TerraTec Mantis DVBS Caputre BDA Receiver (Stream, BDA MPEG2 transport)
      001 connected to BDA MPEG2 Transport Information Filter (MPEG2 sections, DVB SI)
      002 connected to MPEG-2 Sections and Tables (MPEG2 sections, MPEG2 data)
      003 connected to Microsoft DTV-DVD Video Decoder (MPEG2, 704 x 480, 16:9, 59,939998626709 fps)
      004 connected to Microsoft DTV-DVD Audio Decoder (2 ch, 48000 Hz)
      005 connected to BDA MPEG2 Transport Information Filter 0008 (MPEG2 sections)
    TerraTec Mantis DVBS Caputre BDA Receiver
      Input0 connected to TerraTec Mantis DVBS BDA Receiver (Stream, MPEG2 transport)
      MPEG2 Transport connected to MPEG-2 Demultiplexer (Stream, BDA MPEG2 transport)
    TerraTec Mantis DVBS BDA Receiver
      Input0 connected to DVB-S Network Provider (BDA antenna)
      MPEG2 Transport connected to TerraTec Mantis DVBS Caputre BDA Receiver (Stream, MPEG2 transport)
    DVB-S Network Provider
      Antenna Out connected to TerraTec Mantis DVBS BDA Receiver (BDA antenna)

     The obvious problem is the wrong video media type on the MPEG-2 Demultiplexer output 003. But why didn't it change to H.264?

    Thanks for your help!

    Peter

     

     

     

    Wednesday, November 03, 2010 11:01 PM
  • Is there any movement in this problem after almost 2 years? I need to implement it on Windows XP so I can't use Generic network provider.
    I was able to create new PIN on MPEG-2 Demux, but I'm not able to render it.
    What is the basic idea how it should work here? Use MPEG-2 Demux until H264 channel is tunned and then reconnect pins?
    Thank you for advices...
    Thursday, February 23, 2012 4:28 PM