VideoCamera Gets Supported Permissions

I am using the DirectShow library (DirectShowLib-2005.dll) with C # to capture a camcorder image. When I determine the size of the capture object, I have the following options:

const int VIDEOWIDTH = 640; // Depends on video device caps
const int VIDEOHEIGHT = 480; // Depends on video device caps
const int VIDEOBITSPERPIXEL = 24; // BitsPerPixel values determined by device

capture = new Capture(0, VIDEOWIDTH, VIDEOHEIGHT, VIDEOBITSPERPIXEL, pictureBox1);

I use this loop to get device names. Can I somehow read all the possible resolutions for each camera?

DsDevice[] capDevices;
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
if (capDevices.Length == 0)
{
  //Could not found camera
}
else
{
  for (var i = 0; i < capDevices.Length; i++)
  {
    myCamerName = capDevices[i].Name.ToString();
  }
} 
+1
source share
2 answers

, , (, ), - . , , , :

  • IAMStreamConfig.GetStreamCaps () . MSDN : , . , , , , .

  • IPin.EnumMediaTypes ( ).

. :

0

-, , , IPin.EnumMediaTypes

private List<string> GetAllAvailableResolution(DsDevice vidDev)
{
   try
   {
     int hr, bitCount = 0;

     IBaseFilter sourceFilter = null;

     var m_FilterGraph2 = new FilterGraph() as IFilterGraph2;
     hr = m_FilterGraph2.AddSourceFilterForMoniker(vidDev.Mon, null, vidDev.Name, out sourceFilter);
     var pRaw2 = DsFindPin.ByCategory(sourceFilter, PinCategory.Capture, 0);
     var AvailableResolutions = new List<string>();

     VideoInfoHeader v = new VideoInfoHeader();
     IEnumMediaTypes mediaTypeEnum;
     hr = pRaw2.EnumMediaTypes(out mediaTypeEnum);

     AMMediaType[] mediaTypes = new AMMediaType[1];
     IntPtr fetched = IntPtr.Zero;
     hr = mediaTypeEnum.Next(1, mediaTypes, fetched);

     while (fetched != null && mediaTypes[0] != null)
     {
       Marshal.PtrToStructure(mediaTypes[0].formatPtr, v);
       if (v.BmiHeader.Size != 0 && v.BmiHeader.BitCount != 0)
       {
         if (v.BmiHeader.BitCount > bitCount)
         {
           AvailableResolutions.Clear();
           bitCount = v.BmiHeader.BitCount;
         }
         AvailableResolutions.Add(v.BmiHeader.Width +"x"+ v.BmiHeader.Height);
       }
       hr = mediaTypeEnum.Next(1, mediaTypes, fetched);
     }
     return AvailableResolutions;
   }
   catch (Exception ex)
   {
     MessageBox.Show(ex.Message);
     return new List<string>();
   }
}
+2

Source: https://habr.com/ru/post/1779672/


All Articles