[Libav-user] Mapping / converting QTCapture's to FFmpeg's pixel format

Michel Marchand michel at marex.tv
Tue Feb 5 13:09:46 CET 2013


First one looks good. If the image is distorded then it could be the pitch
of line of pixels that is wrong. This would offset the start of a pixel row
and could produce different visual effects.

I wouls start by replacing al Cr Cb bytes by 128 to get monochrome and see
if that looks ok in gray. This can give you hints on whether it's the pitch
or the pointer to a plane that is offset.

Sent from my iPad

On Feb 5, 2013, at 12:52 AM, Brad O'Hearne <brado at bighillsoftware.com>
wrote:

Thanks for the reply Michel. I've actually tried the following pixel
formats on the QT Capture side:

kCVPixelFormatType_420YpCbCr8Planar
Planar Component Y'CbCr 8-bit 4:2:0. baseAddr points to a big-endian
CVPlanarPixelBufferInfo_YCbCrPlanar struct.
<file:///Users/brado/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10_8.CoreReference.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelFormatDescriptionRef/Reference/reference.html>
kCVPixelFormatType_420YpCbCr8PlanarFullRange
Planar Component Y'CbCr 8-bit 4:2:0, full range. baseAddr points to a
big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct.
<file:///Users/brado/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10_8.CoreReference.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelFormatDescriptionRef/Reference/reference.html><file:///Users/brado/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10_8.CoreReference.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelFormatDescriptionRef/Reference/reference.html>
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
Bi-Planar Component Y'CbCr 8-bit 4:2:0, video-range (luma=[16,235]
chroma=[16,240]). baseAddr points to a big-endian
CVPlanarPixelBufferInfo_YCbCrBiPlanar struct.
<file:///Users/brado/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10_8.CoreReference.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelFormatDescriptionRef/Reference/reference.html>
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
Bi-Planar Component Y'CbCr 8-bit 4:2:0, full-range (luma=[0,255]
chroma=[1,255]). baseAddr points to a big-endian
CVPlanarPixelBufferInfo_YCbCrBiPlanar struct.
<file:///Users/brado/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10_8.CoreReference.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelFormatDescriptionRef/Reference/reference.html>

The first two cause the avcodec_encode_video2 line to crash. The last two
transmit video properly but are distorted. I have in my mind that the first
one is probably the right pixel format (also the one I need to use), but
there's some state of the resulting frame / packet that isn't being set
properly I'm guessing, and it is causing to dereference a null pointer
somewhere inside libavcodec. Does anyone have any idea what might be
causing this? Is there some value I need to set before encoding the video?

Thanks,

Brad

On Feb 4, 2013, at 6:05 PM, Michel Marchand <michel at marex.tv> wrote:

I'm no expert in ffmpeg but one in broadcast video and normally YCrCb 422
is not full range that is Y ranges from16 to 235 and Cr/Cb are signed and
range from 16 to 240 (128 being 0). The Full range term may use the full
0-255 range and that could cause problems but not sure...

On Mon, Feb 4, 2013 at 7:31 PM, Brad O'Hearne <brado at bighillsoftware.com>wrote:

> Carl,
>
> Thanks for the reply. I've tried both PIX_FMT_NV12 and PIX_FMT_NV21 (in
> fact, those were the ones I originally thought would work based on
> description). However, when I use either of those formats in place of
> PIX_FMT_YUV420P in the following line of code:
>
> int returnVal = avpicture_fill((AVPicture*)avFrame,
> frameBufferBaseAddress, PIX_FMT_YUV420P, width, height);
>
> then while it executes the avpicture_fill line successfully, the
> subsequent line of code
>
> returnVal = avcodec_encode_video2(_videoStream->codec, &avPacket,
> avFrame, &gotPacket);
>
> crashes the whole app with an EXC_BAD_ACCESS error --  and there's no
> message of any kind written to the console. I have no idea what is causing
> the crash. Here's the complete block of the code between those two lines:
>
> ...
>  int returnVal = avpicture_fill((AVPicture*)avFrame,
> frameBufferBaseAddress, PIX_FMT_NV21, width, height);
>
>     if (returnVal < 0)
>     {
>         if (error)
>         {
>          NSLOG(@"Frame fill failed.");
>         }
>
>         return NO;
>     }
>
>     AVPacket avPacket;
>     av_init_packet(&avPacket);
>     avPacket.data = NULL;
>     avPacket.size = 0;
>     int gotPacket;
>
>     returnVal = avcodec_encode_video2(_videoStream->codec, &avPacket,
> avFrame, &gotPacket);
> ...
>
> That's been pretty standard for most of the other pixel formats I've
> tried. There have been one or two that didn't crash the app, but had very
> wacky distortions (like half the image being neon green), but most of them
> just crash the app outright.
>
> Ideas?
>
> Brad
>
> On Feb 4, 2013, at 4:55 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
>
> Brad O'Hearne <brado at ...> writes:
>
> "Bi-Planar Component Y'CbCr 8-bit 4:2:0, full-range
> (luma=[0,255] chroma=[1,255]). baseAddr points to a
> big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct."
>
> My code (heavily abridged for brevity) hits these high points:
>
> NOTE: frameBufferAddress is a CVImageBufferRef received
> from the QT capture callback:
>
>     int returnVal = avpicture_fill((AVPicture*)avFrame,
> frameBufferBaseAddress, PIX_FMT_YUV420P, width, height);
>
>
> Could "biplanar" point to AV_PIX_FMT_NV12?
> (Or something else that is not AV_PIX_FMT_YUV420P)
>
> Carl Eugen
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130205/f6d96cc8/attachment.html>


More information about the Libav-user mailing list