Save videoStream to file in iOS - change color space efficiently

I’m trying to save a video from OF to file in iOS.

I found some good code to do that here:

And it works quite well, but I have some problems of color space.
original image:

video frame saved:

AVAssetWriterInputPixelBufferAdaptor gives me error if I change the color space from ARGB to RGBA.

NSDictionary* bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

AVAssetWriterInputPixelBufferAdaptor* avAdaptor = [[AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput sourcePixelBufferAttributes:bufferAttributes] retain];

What is the most efficient way to change a buffer from RGBA to ARGB?

Did anyone experience other strategies to work with AVAssetWriter to feed directly oF video stream?