Using objc2 crate to set AVCaptureVideoDataOutput video settings causes fatal runtime error: "Rust cannot catch foreign exceptions"

⚓ rust    📅 2025-05-05    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 60 days ago. The information described in this article may have changed.

I'm currently using the objc2 crates, specifically the following crates:

  • objc2_foundation
  • objc2_core_video
  • objc2_av_foundation

Im trying to set the video settings for an AVCaptureVideoDataOutput instance to use the kCVPixelFormatType_32BGRA pixel format.

Here is my code:

use objc2_foundation::{NSString, NSNumber, NSDictionary};
use objc2_core_video::kCVPixelFormatType_32BGRA;
use objc2_av_foundation::AVCaptureVideoDataOutput;

fn main() {
    unsafe {
        let output = AVCaptureVideoDataOutput::new();

        let pixel_format_key = NSString::from_str("kCVPixelBufferPixelFormatTypeKey");
        let pixel_format_value = NSNumber::new_u32(kCVPixelFormatType_32BGRA);

        let video_settings = NSDictionary::from_slices::<NSString>(
            &[pixel_format_key.as_ref()],
            &[pixel_format_value.as_ref()],
        );

        output.setVideoSettings(Some(&video_settings));
    }
}

Thanks!!

1 post - 1 participant

Read full topic

🏷️ rust_feed