How to look up Photo Pixel Formate Types?

I listed the AVCapturePhotoSettings.availablePhotoPixelFormatTypes array in my iPhone 14 during a running photo session and I got these type numbers:

875704422
875704438
1111970369

I have no idea what these numbers mean. How can I use these numbers to look up a human readable string that can tell me what these types are in a way I am familiar with, such as jpeg, tiff, png, bmp, dng, etc, so I know which of these numbers to choose when I instantiate the class: AVCaptureSession?

Accepted Reply

Hello,

These values are the integer representation of the Four Character Code (FourCC) that represents the pixel format.

If you run the following:

let pixelFormats: [UInt32] = [875704422, 875704438, 1111970369]
            
for format in pixelFormats {
    let formatDescription = try! CMVideoFormatDescription(videoCodecType: .init(rawValue: format), width: 0, height: 0)
                
    print(formatDescription.mediaSubType.description)
}

You will see that these values correspond to the '420f', '420v', and 'BGRA' pixel formats respectively.

From there, you can determine the "kCVPixelFormatType" constant matches the FourCC by looking at the CoreVideo pixel format type constants within CVPixelBuffer.h

In this case, that is kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, and kCVPixelFormatType_32BGRA respectively.

  • Thanks for your reply. The default format for when AVCaptureSession() is instantiated without an argument is jpeg. So I expected to jpeg would be one of the options, but it is not the case. I am looking for a way to get captured image data in a lossless format, of which jpeg is not. Of the three image file formats it appears the BGRA is what I am seeking given that it stands a bit pattern that stands for Blue Green Red Alpha. Is there a way to read back how many bits there are for each color?

  • No problem. It seems that there may be a misunderstanding, jpeg is an image codec, whereas these are pixel formats. Not quite the same thing.

    Regardless, I believe what you are really asking for here is a RAW photo, and so I recommend that you take a look at this article: https://developer.apple.com/documentation/avfoundation/photo_capture/capturing_photos_in_raw_and_apple_proraw_formats

  • Thank you for your link. I modified my code to integrate into it the code example given there. But the example is not working for me. I have opened a new thread about the difficulty here: https://developer.apple.com/forums/thread/733924#733924021

Add a Comment

Replies

Hello,

These values are the integer representation of the Four Character Code (FourCC) that represents the pixel format.

If you run the following:

let pixelFormats: [UInt32] = [875704422, 875704438, 1111970369]
            
for format in pixelFormats {
    let formatDescription = try! CMVideoFormatDescription(videoCodecType: .init(rawValue: format), width: 0, height: 0)
                
    print(formatDescription.mediaSubType.description)
}

You will see that these values correspond to the '420f', '420v', and 'BGRA' pixel formats respectively.

From there, you can determine the "kCVPixelFormatType" constant matches the FourCC by looking at the CoreVideo pixel format type constants within CVPixelBuffer.h

In this case, that is kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, and kCVPixelFormatType_32BGRA respectively.

  • Thanks for your reply. The default format for when AVCaptureSession() is instantiated without an argument is jpeg. So I expected to jpeg would be one of the options, but it is not the case. I am looking for a way to get captured image data in a lossless format, of which jpeg is not. Of the three image file formats it appears the BGRA is what I am seeking given that it stands a bit pattern that stands for Blue Green Red Alpha. Is there a way to read back how many bits there are for each color?

  • No problem. It seems that there may be a misunderstanding, jpeg is an image codec, whereas these are pixel formats. Not quite the same thing.

    Regardless, I believe what you are really asking for here is a RAW photo, and so I recommend that you take a look at this article: https://developer.apple.com/documentation/avfoundation/photo_capture/capturing_photos_in_raw_and_apple_proraw_formats

  • Thank you for your link. I modified my code to integrate into it the code example given there. But the example is not working for me. I have opened a new thread about the difficulty here: https://developer.apple.com/forums/thread/733924#733924021

Add a Comment