Hello, I'm Soonwon.
We’re currently developing a UVC camera device and trying to stream MJPEG video via AVFoundation on macOS. However, we’re running into a problem with custom resolutions.
When we try to use AVFoundation on macOS to capture MJPEG video at 1000x6000, the stream is not accepted or simply doesn’t work. Lower resolutions work fine.
(Interestingly, using the same device on iPadOS, we can capture the 1000x6000 MJPEG stream successfully by using AVCaptureSessionPresetInputPriority.)
Is there any way to receive custom-resolution MJPEG streams (like 1000x6000) from a UVC device using AVFoundation on macOS? Are there specific session presets, entitlements, or known limitations that affect MJPEG handling at custom resolutions on macOS?
Does macOS handle MJPEG differently from iPadOS in AVFoundation? Any insight or guidance would be greatly appreciated. Thank you!
NSError *error = nil;
if ([selectedDevice lockForConfiguration:&error]) {
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetHigh;
bool foundFormat = false;
for (AVCaptureDeviceFormat *format in selectedDevice.formats) {
CMVideoDimensions dims = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
FourCharCode pixelFormat = CMFormatDescriptionGetMediaSubType(format.formatDescription);
foundFormat = true;
if (dims.width == 1000 && dims.height == 6000) {
selectedDevice.activeFormat = format;
foundFormat = true;
break;
}
}
if(foundFormat == false)
{
NSLog(@"Failed to foundFormat : ");
[session commitConfiguration];
return false;
}
NSError* error = nil;
AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:selectedDevice error:&error];
if (error || ![session canAddInput:input])
{
NSLog(@"Failed to add video input: %@", error.localizedDescription);
[session commitConfiguration];
return false;
}
[session addInput:input];
AVCaptureVideoDataOutput* output = [[AVCaptureVideoDataOutput alloc] init];
output.alwaysDiscardsLateVideoFrames = YES;
output.videoSettings = @{ (NSString*)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) };
[output setSampleBufferDelegate:delegate queue:queue];
if ([session canAddOutput:output])
{
[session addOutput:output];
}
[session commitConfiguration];
[selectedDevice unlockForConfiguration];
} else {
NSLog(@"Failed to lock device for configuration: %@", error.localizedDescription);
}
// start~