[FFmpeg-devel] [PATCH] AVFoundation: Add -pixel_format option

Lukasz Marek lukasz.m.luki2 at gmail.com
Sun May 11 11:43:01 CEST 2014


On 11.05.2014 11:13, sfan5 wrote:
> +static const struct AVFPixelFormatSpec avf_pixel_formats[] = {
> +    { AV_PIX_FMT_MONOBLACK, kCVPixelFormatType_1Monochrome },
> +    { AV_PIX_FMT_GRAY8, kCVPixelFormatType_8Indexed },
> +    { AV_PIX_FMT_RGB555BE, kCVPixelFormatType_16BE555 },
> +    { AV_PIX_FMT_RGB555LE, kCVPixelFormatType_16LE555 },
> +    { AV_PIX_FMT_RGB565BE, kCVPixelFormatType_16BE565 },
> +    { AV_PIX_FMT_RGB565LE, kCVPixelFormatType_16LE565 },
> +    { AV_PIX_FMT_RGB0, kCVPixelFormatType_24RGB },
> +    { AV_PIX_FMT_BGR0, kCVPixelFormatType_24BGR },
> +    { AV_PIX_FMT_ARGB, kCVPixelFormatType_32ARGB },
> +    { AV_PIX_FMT_BGRA, kCVPixelFormatType_32BGRA },
> +    { AV_PIX_FMT_ABGR, kCVPixelFormatType_32ABGR },
> +    { AV_PIX_FMT_RGBA, kCVPixelFormatType_32RGBA },
> +    { AV_PIX_FMT_BGR48BE, kCVPixelFormatType_48RGB },
> +    { AV_PIX_FMT_UYVY422, kCVPixelFormatType_422YpCbCr8 },
> +    { AV_PIX_FMT_YUVA444P, kCVPixelFormatType_4444YpCbCrA8R },
> +    { AV_PIX_FMT_YUVA444P16LE, kCVPixelFormatType_4444AYpCbCr16 },
> +    { AV_PIX_FMT_YUV444P, kCVPixelFormatType_444YpCbCr8 },
> +    { AV_PIX_FMT_YUV422P16, kCVPixelFormatType_422YpCbCr16 },
> +    { AV_PIX_FMT_YUV422P10, kCVPixelFormatType_422YpCbCr10 },
> +    { AV_PIX_FMT_YUV444P10, kCVPixelFormatType_444YpCbCr10 },
> +    { AV_PIX_FMT_YUV420P, kCVPixelFormatType_420YpCbCr8Planar },
> +    { AV_PIX_FMT_NV12, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange },
> +    { AV_PIX_FMT_YUYV422, kCVPixelFormatType_422YpCbCr8_yuvs },
> +    { AV_PIX_FMT_GRAY8, kCVPixelFormatType_OneComponent8 },
> +    { AV_PIX_FMT_NONE, 0 }
> +};

GRAY8 is included twice.

>   typedef struct
>   {
>       AVClass*        class;
> @@ -53,8 +86,9 @@ typedef struct
>       pthread_cond_t  frame_wait_cond;
>       id              avf_delegate;
>
> -    int             list_devices;
> -    int             video_device_index;
> +    int                list_devices;
> +    int                video_device_index;

You should not change not relevant code in single patch.

> +    enum AVPixelFormat pixel_format;
>
>       AVCaptureSession         *capture_session;
>       AVCaptureVideoDataOutput *video_output;
> @@ -241,7 +275,20 @@ static int avf_read_header(AVFormatContext *s)
>           goto fail;
>       }
>
> -    NSNumber     *pixel_format = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_24RGB];
> +    struct AVFPixelFormatSpec pxl_fmt_spec;
> +    pxl_fmt_spec.ff_id = AV_PIX_FMT_NONE;
> +    for(int i = 0; avf_pixel_formats[i].ff_id != AV_PIX_FMT_NONE; i++) {

minor: space between for and (, the same bellow between ifs and (

> +        if(ctx->pixel_format == avf_pixel_formats[i].ff_id) {
> +            pxl_fmt_spec = avf_pixel_formats[i];
> +            break;
> +        }
> +    }
> +    if(pxl_fmt_spec.ff_id == AV_PIX_FMT_NONE) {
> +        av_log(s, AV_LOG_ERROR, "Selected pixel format not supported by AVFoundation\n");

Selected pixel format IS not supported

> +        goto fail;
> +    }
> +
> +    NSNumber     *pixel_format = [NSNumber numberWithUnsignedInt:pxl_fmt_spec.avf_id];
>       NSDictionary *capture_dict = [NSDictionary dictionaryWithObject:pixel_format
>                                                  forKey:(id)kCVPixelBufferPixelFormatTypeKey];
>
> @@ -285,7 +332,7 @@ static int avf_read_header(AVFormatContext *s)
>       stream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
>       stream->codec->width      = (int)image_buffer_size.width;
>       stream->codec->height     = (int)image_buffer_size.height;
> -    stream->codec->pix_fmt    = AV_PIX_FMT_RGB24;
> +    stream->codec->pix_fmt    = pxl_fmt_spec.ff_id;
>
>       CFRelease(ctx->current_frame);
>       ctx->current_frame = nil;
> @@ -352,6 +399,7 @@ static const AVOption options[] = {
>       { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" },
>       { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" },
>       { "video_device_index", "select video device by index for devices with same name (starts at 0)", offsetof(AVFContext, video_device_index), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
> +    { "pixel_format", "Set pixel format", offsetof(AVFContext, pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_RGB24}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},

minor: use lower case as for other options.

No more comments from me.




More information about the ffmpeg-devel mailing list