/// <summary>
    /// AnnexB formatted h264 bitstream
    /// </summary>
    /// <param name="streamInfo"></param>
    /// <returns></returns>
    public static AMMediaType H264_AnnexB(InputstreamInfo streamInfo)
    {
      int width = (int)streamInfo.Width;
      int height = (int)streamInfo.Height;

      if (streamInfo.ExtraData.Length > 0)
      {
        var codecData = new H264CodecData(streamInfo.ExtraData);

        SPSUnit spsUnit = new SPSUnit(codecData.SPS);
        width = spsUnit.Width();
        height = spsUnit.Height();
      }

      VideoInfoHeader2 vi = new VideoInfoHeader2();
      vi.SrcRect.right = width;
      vi.SrcRect.bottom = height;
      vi.TargetRect.right = width;
      vi.TargetRect.bottom = height;

      int hcf = HCF(width, height);
      vi.PictAspectRatioX = width / hcf;
      vi.PictAspectRatioY = height / hcf;

      vi.BmiHeader.Width = width;
      vi.BmiHeader.Height = height;
      vi.BmiHeader.Planes = 1;
      vi.BmiHeader.Compression = FOURCC_H264;

      AMMediaType amt = new AMMediaType();
      amt.majorType = MediaType.Video;
      amt.subType = MediaSubType.H264;
      amt.temporalCompression = true;
      amt.fixedSizeSamples = false;
      amt.sampleSize = 1;
      amt.SetFormat(vi);
      return amt;
    }
    public static AMMediaType E_AC3(InputstreamInfo streamInfo)
    {
      WaveFormatEx wf = new WaveFormatEx();
      wf.wFormatTag = 8192;
      wf.nBlockAlign = 24;
      wf.wBitsPerSample = 32;
      wf.cbSize = 0;

      AMMediaType amt = new AMMediaType();
      AssignStreamInfoFields(streamInfo, ref wf, ref amt);
      amt.majorType = MediaType.Audio;
      amt.subType = MEDIASUBTYPE_DOLBY_DDPLUS;
      amt.temporalCompression = false;
      amt.fixedSizeSamples = true;
      amt.SetFormat(wf);
      return amt;
    }
 /// <summary>
 /// Sets AMMediaType format data with Mpeg2VideoInfo and optional extra data.
 /// </summary>
 /// <param name="vi"></param>
 /// <param name="extraData"></param>
 /// <param name="amt"></param>
 static void SetFormat(Mpeg2VideoInfo vi, byte[] extraData, AMMediaType amt)
 {
   int cb = Marshal.SizeOf(vi);
   int add = extraData == null || extraData.Length < 4 ? 0 : extraData.Length - 4;
   IntPtr ptr = Marshal.AllocCoTaskMem(cb + add);
   try
   {
     Marshal.StructureToPtr(vi, ptr, false);
     if (extraData != null)
       Marshal.Copy(extraData, 0, ptr + cb - 4, extraData.Length);
     amt.SetFormat(ptr, cb + add);
     amt.formatType = FormatType.Mpeg2Video;
   }
   finally
   {
     Marshal.FreeCoTaskMem(ptr);
   }
 }
    public static AMMediaType AAC_LC(InputstreamInfo streamInfo)
    {
      WaveFormatEx wf = new WaveFormatEx();
      wf.wFormatTag = 255;
      wf.nBlockAlign = 1;
      wf.wBitsPerSample = 16;
      wf.cbSize = 0;

      AMMediaType amt = new AMMediaType();
      AssignStreamInfoFields(streamInfo, ref wf, ref amt);
      amt.majorType = MediaType.Audio;
      amt.subType = MEDIASUBTYPE_ADTS; // Works better than RAW_AAC1 (tested with Amazon Prime and 7TV)
      amt.temporalCompression = false;
      amt.fixedSizeSamples = true;
      amt.SetFormat(wf);
      return amt;
    }