0

so i have code that reads from an AVAsset using kCVPixelFormat_32BGRA. I get the next sample buffer by calling

[vidInput copyNextSamplebuffer];

Then I proceed with Apple's code on their AVFoundation guide http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_MediaRepresentations.html#//apple_ref/doc/uid/TP40010188-CH2-SW4

What troubles me is that sometimes

size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);

gives me something that isnt the width*4, and as a result, when I attempt to use it, the image is teared very badly. Has anyone experienced anything similar?

bogardon
  • 896
  • 2
  • 10
  • 22
  • The bytes per row might be padded out to be divisible by 16. Is that a problem? – Rhythmic Fistman Jun 20 '11 at 01:02
  • i doubt that. the dimensions are 568 x 320. if you take any of the two and multiply by 4, the result will be divisible by 16. – bogardon Jun 20 '11 at 05:37
  • In any case rowbytes doesn't have to be 4*width - that's why rowbytes exists. – Rhythmic Fistman Jun 20 '11 at 06:51
  • it doesn't have to be, but i specified that it takes it in as 32BGRA, which means every pixel is 32bits, or 4 bytes, and hence row per bytes should be 4*width. – bogardon Jun 21 '11 at 18:33
  • 2
    Nuhuh, AVAssetReader is free to choose any rowbytes it likes as long as rowbytes >= pixelSize*width. This implementation is a classic example of a memory/speed tradeoff. In any case, you'll have to deal with. Good luck! – Rhythmic Fistman Jun 21 '11 at 20:04

1 Answers1

1

@Rhythmic was spot on - if you want to look at another question this is discussed (in more detail): iOS CVImageBuffer distorted from AVCaptureSessionDataOutput with AVCaptureSessionPresetPhoto

Community
  • 1
  • 1
Oded Ben Dov
  • 9,936
  • 6
  • 38
  • 53