ffmpeg使用了os x的vda

时间:2014-05-13 09:01:36

标签: macos video ffmpeg

我尝试使用ffmpeg

启用先前解码的硬件解码项目

ffmpeg支持硬拷贝解码 在这里文件kotoroya我做了https://github.com/dilaroga/ffmpeg-vda/wiki/FFmpeg-vda-usage 我的代码

enum AVPixelFormat myGetFormatCallback(struct AVCodecContext *ctx, const enum AVPixelFormat * fmt)
{
    struct vda_context *vda_ctx;
    vda_ctx = (struct vda_context *)malloc(sizeof(vda_context));
    vda_ctx->decoder = NULL;
    vda_ctx->width = ctx->width;
    vda_ctx->height = ctx->height;
    vda_ctx->format = 'avc1';
    vda_ctx->use_ref_buffer = 1;
    switch (ctx->pix_fmt) {
        case PIX_FMT_UYVY422:{
            vda_ctx->cv_pix_fmt_type = '2vuy';
            break;
        }
        case PIX_FMT_YUYV422:{
            vda_ctx->cv_pix_fmt_type = 'yuvs';
            break;
        }
        case PIX_FMT_NV12:{
            vda_ctx->cv_pix_fmt_type = '420v';
            break;
        }
        case PIX_FMT_YUV420P:{
            vda_ctx->cv_pix_fmt_type = 'y420';
            break;
        }
        default:{
            av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %d\n", ctx->pix_fmt);
            Logger::debug(LOG_LEVEL_ERROR, "Unsupported pixel format: %d", ctx->pix_fmt);
            throw AbstractException("Unsupported pixel format");
        }
     }
    int status = ff_vda_create_decoder(vda_ctx, (unsigned char*)ctx->extradata,ctx->extradata_size);
    if (status){
        Logger::debug(LOG_LEVEL_ERROR, "Error create VDA decoder");
        throw AbstractException("Error create VDA decoder");
    }else{
        ctx->hwaccel_context = vda_ctx;
    }

    return ctx->pix_fmt;
}

static void release_vda_context(void *opaque, uint8_t *data)
{
    vda_buffer_context *vda_context = (vda_buffer_context *)opaque;
    av_free(vda_context);
}

int myGetBufferCallback(struct AVCodecContext *s, AVFrame *av_frame, int flags)
{
    vda_buffer_context *vda_context = (vda_buffer_context *)av_mallocz(sizeof(*vda_context));
    AVBufferRef *buffer = av_buffer_create(NULL, 0, release_vda_context, vda_context, 0);

    if( !vda_context || !buffer )
    {
        av_free(vda_context);
        return -1;
    }

    av_frame->buf[0] = buffer;
    av_frame->data[0] = (uint8_t*)1;
    return 0;
}


static void release_buffer(struct AVCodecContext *opaque, AVFrame *pic)
{
    vda_buffer_context *context = (vda_buffer_context*)opaque;
    CVPixelBufferUnlockBaseAddress(context->cv_buffer, 0);
    CVPixelBufferRelease(context->cv_buffer);
    av_free(context);
}

main(){
    //init ff context
    if (avcodec_open2(mCodecContext, mCodec, NULL) < 0) throw AbstractException("Unable to open codec");

    mCodecContext->get_format = myGetFormatCallback;
    mCodecContext->get_buffer2 = myGetBufferCallback;
    mCodecContext->release_buffer = release_buffer;
}

但我调用的方法没有myGetFormatCallback,而且调用了myGetBufferCallback 为什么不调用myGetFormatCallback?怎么了?可能效果不好

0 个答案:

没有答案