Blue tint on h264 video stream in iOS app running on Apple Silicon Mac

Hi,

We have an iOS application used to control an underwater drone. The video feed from the drone is h264 transmitted over the RTSP protocol.

We have had the app in production for a long time, with no issues on iPhone and iPad. The app also launches and runs fine on M1 Macs. However, the video is rendered with a strange blue tint (no color, except black, white, and blue).

This happens when running our app installed from the App Store on an M1 mac, or when building on an M1 app running it directly.

I can't find any relevant warnings or errors in the app output neither.

This is the code rendering a frame:

Code Block
- (void)renderFrame:(CVImageBufferRef)imageBuffer withPresentationTime:(CMTime)presentationTime {
    CVPixelBufferLockBaseAddress(imageBuffer, 0);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
    void *lumaBuffer = CVPixelBufferGetBaseAddress(imageBuffer);
    CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
  
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    size_t bitsPerComponent = 8;
    CGContextRef context = CGBitmapContextCreate(lumaBuffer,
width,
height,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst
);
    CGImageRef image = CGBitmapContextCreateImage(context);
    [self.delegate decoderFrameAvailable:image withTimeStamp:presentationTime.value];
    [self.diagnostics trackNewFrameDimensionsWithWidth:width andHeight:height];
    CGImageRelease(image);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
}


I was not able to attach a screenshot or even link to it.

Answered by follesoe in 657994022
I was able to resolve the issue by changing the byte order from kCGBitmapByteOrder32Little to kCGBitmapByteOrderDefault
Accepted Answer
I was able to resolve the issue by changing the byte order from kCGBitmapByteOrder32Little to kCGBitmapByteOrderDefault
Blue tint on h264 video stream in iOS app running on Apple Silicon Mac
 
 
Q