0

I use to read AVAssetReaderTrackOutput video.

Setting "kCVPixelBufferPixelFormatTypeKey" - "kCVPixelFormatType_32BGRA" work!

But I need a 16 bit video.

If set setting value "kCVPixelFormatType_16...." does not work. [asset_reader_output copyNextSampleBuffer] - always nil =(

Why is this happening?

How do I change a bit color?

UPD: `code:

[videoWriterInput requestMediaDataWhenReadyOnQueue:queueVideo usingBlock:^
{
    while([videoWriterInput isReadyForMoreMediaData])
    {
        CMSampleBufferRef sampleBuffer=[video_asset_reader_output copyNextSampleBuffer];
        if(sampleBuffer)
        {
            NSLog(@"write video");
            [videoWriterInput appendSampleBuffer:sampleBuffer];
            CFRelease(sampleBuffer);
        } else
        {
            [videoWriterInput markAsFinished];
            dispatch_release(queueVideo);
            videoFinished=YES;
            break;
        }
    }
}];

`

Rinat
  • 3
  • 3

1 Answers1

0

Core Video doesn't support all the pixel formats. BGRA is guaranteed to work though. You have to perform your own conversion. What are you using the buffer for?

UPDATE: To access the pixels, use something like this:

CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);

void* bufferAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);

// Read / modify the pixel data with bufferAddress, height & bytesPerRow
// For BGRA format, it's 4-byte per pixel in that order

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
Khanh Nguyen
  • 11,112
  • 10
  • 52
  • 65
  • I added code in question for you. I need to change CMSampleBufferRef? – Rinat Jun 21 '13 at 07:54
  • I updated the answer with code snippet for accessing/modifying the CMSampleBuffer. I don't think AVFoundation supports writing (or reading) 16-bit video frame though. Why do you want to write 16-bit video? – Khanh Nguyen Jun 21 '13 at 09:52
  • Thank you! I need the video to send to the server. Always a realtime. If there is a bad connection, it must be hard to compress video ... 16...8...black and white. Tell me, please, how to work with it? "bufferAddress" – Rinat Jun 21 '13 at 10:45
  • If that's the case, you should change the video recording settings, not playing with the frame buffer (manipulating frame buffer is also harder and potentially very slow). Not sure if you have read [this](http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html), but it's a good starting point, and should be sufficient for your requirements. You may want to record the video at lower quality, or in grayscale mode. AVFoundation automatically compresses video in H264 format, so you don't really have to implement your own compression – Khanh Nguyen Jun 21 '13 at 11:05
  • The following link may help: (http://stackoverflow.com/questions/5687341/iphoneprogrammatically-compressing-recorded-video-to-share)http://stackoverflow.com/questions/5687341/iphoneprogrammatically-compressing-recorded-video-to-share – Khanh Nguyen Jun 21 '13 at 11:10