Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoCharacteristics not detected #125

Closed
SignalMQ opened this issue Dec 22, 2023 · 17 comments
Closed

VideoCharacteristics not detected #125

SignalMQ opened this issue Dec 22, 2023 · 17 comments
Labels
question Further information is requested

Comments

@SignalMQ
Copy link

SignalMQ commented Dec 22, 2023

Hello everyone!👋👋👋
I used an example from the project description. I haven't decided on the characteristics for the video.

My software and hardware information

image
image

Aditional Context

using FlashCap;

// Capture device enumeration:
var devices = new CaptureDevices();
var descriptor0 = devices.EnumerateDescriptors().ElementAt(0);

byte[] imageData = await descriptor0.TakeOneShotAsync(
    descriptor0.Characteristics.FirstOrDefault());

// Save to file
await File.WriteAllBytesAsync("oneshot", imageData);

image
image

@kekyo
Copy link
Owner

kekyo commented Dec 25, 2023

Thanks for reached out!

If FlashCap is the latest, Characteristics cannot handle are also enumerated as Unknown formats. However, I could not understand why they are not enumerated at all, including them. Can we try other cameras?

@kekyo kekyo added the question Further information is requested label Dec 25, 2023
@SignalMQ
Copy link
Author

SignalMQ commented Dec 26, 2023

I tried code below on my second computer:

using FlashCap;
using SkiaSharp;

var devices = new CaptureDevices();
var descriptor0 = devices.EnumerateDescriptors().ElementAt(0);
byte[] imageData = await descriptor0.TakeOneShotAsync(descriptor0.Characteristics.FirstOrDefault());

using (var ms = new MemoryStream(imageData))
{
    SKBitmap bitmap = SKBitmap.Decode(ms);
    SKFileWStream fs = new("photo.png");
    bitmap.Encode(fs, SKEncodedImageFormat.Png, quality: 100);
}

Other cam:
Logi C270 HD WebCam (USB\VID_046D&PID_0825&MI_00\6&29B00C26&0&0000)

OS:
Windows 11 Enterprise 22H2

Detected and works perfectly, but in my laptop same situation

Result:
photo

@SignalMQ
Copy link
Author

Thanks for reached out!

If FlashCap is the latest, Characteristics cannot handle are also enumerated as Unknown formats. However, I could not understand why they are not enumerated at all, including them. Can we try other cameras?

I dont have other cameras on this device, because it's laptop.

@kekyo
Copy link
Owner

kekyo commented Jan 15, 2024

@SignalMQ On #126 and #127, maybe these issues were a factor. #124 may also affect stable operation, so can I try it after merging these?

@SignalMQ
Copy link
Author

@SignalMQ On #126 and #127, maybe these issues were a factor. #124 may also affect stable operation, so can I try it after merging these?

I don't understand, what you meaning in 'so can I try it...'. I'm try these fixes or you?

@kekyo
Copy link
Owner

kekyo commented Jan 20, 2024

Oh, sorry if it doesn't make sense, I made a mistake in the translation program 😵‍💫
Could you try it with a commit from current develop branch?

@SignalMQ
Copy link
Author

image

Hello @kekyo. I am building nupkg from develop branch but this error appears above.

@SignalMQ
Copy link
Author

SignalMQ commented Jan 22, 2024

Characteristics [VideoCharacteristics[]]:
{FlashCap.VideoCharacteristics[0]}
Description [string]:
"usb-0000:03:00.4-3: uvcvideo"
DeviceType [DeviceTypes]:
V4L2
Identity [object]:
"/dev/video1"
Name [string]:
"USB2.0 HD UVC WebCam: USB2.0 HD"
Non-Public members

here is my decriptors info

@kekyo
Copy link
Owner

kekyo commented Feb 2, 2024

@SignalMQ Sorry later, I am interested in what characteristics are enumerated in your camera. The following sections:

https://github.com/kekyo/FlashCap/blob/854186a445e494548480ae0d6b607c1bf009eb57/FlashCap.Core/Devices/V4L2Devices.cs#L184C29-L184C48

                        return (CaptureDeviceDescriptor)new V4L2DeviceDescriptor(
                            devicePath, ToString(caps.card), $"{ToString(caps.bus_info)}: {ToString(caps.driver)}",
                            EnumerateFormatDesc(fd).
                            SelectMany(fmtdesc =>
                                EnumerateFrameSize(fd, fmtdesc.pixelformat).
                                SelectMany(frmsize =>
                                    EnumerateFramesPerSecond(fd, fmtdesc.pixelformat, frmsize.Width, frmsize.Height).
                                    Collect(framesPerSecond =>
                                        NativeMethods_V4L2.CreateVideoCharacteristics(
                                            fmtdesc.pixelformat, frmsize.Width, frmsize.Height,
                                            framesPerSecond.Value, ToString(fmtdesc.description),
                                            frmsize.IsDiscrete && framesPerSecond.IsDiscrete)))).
                            Distinct().
                            OrderByDescending(vc => vc).
                            ToArray());

Here, if a series of SelectMany() returns no result, the number of characteristics is zero. Such a possibility would be if EnumerateFormatDesc(), EnumerateFrameSize(), or EnumerateFramesPerSecond() returned zero elements. Your camera may fall into one of these cases.

This line is written on a single line, so it may be difficult to verify. For example:

var a = EnumerateFormatDesc(fd).ToArray();
var b = a.SelectMany(fmtdesc =>
{
    var c = EnumerateFrameSize(fd, fmtdesc.pixelformat).ToArray();
    var d = c.SelectMany(frmsize =>
    {
        // ...
    });
    // ...
});

to change the enumeration so that you can check the enumeration and be sure of it on the debugger.

@SignalMQ
Copy link
Author

SignalMQ commented Feb 6, 2024

@kekyo I'm tried to detect my device with V4L2 Devices().Enumerate Descriptors() and surprised for detected 2nd shadow copy of device placed in /dev/video0:

image

Here it seemed strange to me that the devices are listed in reverse order ([/dev/video1, /dev/video0]), or I’m wrong.

@kekyo
Copy link
Owner

kekyo commented Feb 7, 2024

I was surprised too! I'm not sure why there are multiple /dev/video? enumerations in the first place, but I'm not particularly aware of the order:

Directory.GetFiles("/dev", "video*").

If you select /dev/video1, will it capture correctly?

@SignalMQ
Copy link
Author

SignalMQ commented Feb 7, 2024

I was surprised too! I'm not sure why there are multiple /dev/video? enumerations in the first place, but I'm not particularly aware of the order:

Directory.GetFiles("/dev", "video*").

If you select /dev/video1, will it capture correctly?

/dev/video1 - fail
/dev/video0 - sucess

@kekyo
Copy link
Owner

kekyo commented Feb 7, 2024

According to the screenshot, /dev/video0 has zero characteristics and /dev/video1 enumerates several characteristics, did you succeed in the case of /dev/video0?

Are you saying that you used the value of /dev/video1 as the characteristic in that case?

@SignalMQ
Copy link
Author

SignalMQ commented Feb 7, 2024

According to the screenshot, /dev/video0 has zero characteristics and /dev/video1 enumerates several characteristics, did you succeed in the case of /dev/video0?

Are you saying that you used the value of /dev/video1 as the characteristic in that case?

/dev/video0 has 12 characteristics and it's work, but /dev/video1 enumerated in first is not work, because don't have any characteristics listed.

@kekyo
Copy link
Owner

kekyo commented Feb 7, 2024

I see. As a coping remedy, it seems that we need to ignore devices with zero characteristics.

We could ignore devices with zero characteristics when internal FlashCap enumerates them, but I imagine that would probably make it difficult to identify the problem.
Therefore, I would like to make it a policy that this exclusion is handled by the caller. For example:

if (devices.EnumerateDescriptors().
    FirstOrDefault(d => d.Characteristics.Any(c => c.PixelFormat != PixelFormats.Unknown)) is { } device)
{
    // `device` is valid.
}
@SignalMQ SignalMQ closed this as completed Mar 5, 2024
@SignalMQ
Copy link
Author

SignalMQ commented Mar 5, 2024

My problem solved, I use my second device.

@kekyo
Copy link
Owner

kekyo commented Apr 19, 2024

@SignalMQ The next version will support NV12 format. Perhaps devices that were not enumerated (or were Unknown) will become available, so if you are interested, please give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants