当前位置: 首页>>代码示例>>C++>>正文


C++ NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer方法代码示例

本文整理汇总了C++中NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer方法的具体用法?C++ NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer怎么用?C++ NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NV_ENCODE_API_FUNCTION_LIST的用法示例。


在下文中一共展示了NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: memcpy

bool fcH264EncoderNVIDIA::encode(fcH264Frame& dst, const void *image, fcPixelFormat fmt, fcTime timestamp, bool force_keyframe)
{
    if (!isValid()) { return false; }

    dst.timestamp = timestamp;

    // convert image to NV12
    AnyToNV12(m_nv12_image, m_rgba_image, image, fmt, m_conf.width, m_conf.height);
    NV12Data data = m_nv12_image.data();

    NVENCSTATUS stat;

    // upload image to input buffer
    {
        NV_ENC_LOCK_INPUT_BUFFER lock_params = { 0 };
        lock_params.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
        lock_params.inputBuffer = m_input.inputBuffer;
        stat = nvenc.nvEncLockInputBuffer(m_encoder, &lock_params);
        memcpy(lock_params.bufferDataPtr, data.y, m_nv12_image.size());
        stat = nvenc.nvEncUnlockInputBuffer(m_encoder, m_input.inputBuffer);
    }


    NV_ENC_PIC_PARAMS params = { 0 };
    params.version = NV_ENC_PIC_PARAMS_VER;
    params.inputBuffer = m_input.inputBuffer;
    params.outputBitstream = m_output.bitstreamBuffer;
    params.bufferFmt = NV_ENC_BUFFER_FORMAT_NV12;
    params.inputWidth = m_conf.width;
    params.inputHeight = m_conf.height;
    params.completionEvent = 0;
    params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
    params.encodePicFlags = 0;
    if (force_keyframe) {
        params.encodePicFlags |= NV_ENC_PIC_FLAG_FORCEINTRA;
    }
    params.inputTimeStamp = to_usec(timestamp);
    params.inputDuration = to_usec(1.0 / m_conf.target_framerate);

    // encode! 
    stat = nvenc.nvEncEncodePicture(m_encoder, &params);

    // retrieve encoded data
    {
        NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
        lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
        lock_params.outputBitstream = m_output.bitstreamBuffer;

        stat = nvenc.nvEncLockBitstream(m_encoder, &lock_params);

        dst.data.append((char*)lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
        dst.gatherNALInformation();

        stat = nvenc.nvEncUnlockBitstream(m_encoder, m_output.bitstreamBuffer);
    }

    return true;
}
开发者ID:unity3d-jp,项目名称:FrameCapturer,代码行数:58,代码来源:fcH264EncoderNVIDIA.cpp

示例2: nvenc_enqueue_frame

static int nvenc_enqueue_frame(AVCodecContext *avctx, const AVFrame *frame,
                               NVENCInputSurface **in_surf)
{
    NVENCContext *ctx               = avctx->priv_data;
    NV_ENCODE_API_FUNCTION_LIST *nv = &ctx->nvel.nvenc_funcs;
    NV_ENC_LOCK_INPUT_BUFFER params = { 0 };
    NVENCInputSurface *in           = get_input_surface(ctx);
    int ret;

    if (!in)
        return AVERROR_BUG;

    params.version     = NV_ENC_LOCK_INPUT_BUFFER_VER;
    params.inputBuffer = in->in;


    ret = nv->nvEncLockInputBuffer(ctx->nvenc_ctx, &params);
    if (ret != NV_ENC_SUCCESS) {
        av_log(avctx, AV_LOG_ERROR, "Cannot lock the buffer %p.\n",
               in);
        return AVERROR_UNKNOWN;
    }

    ret = nvenc_copy_frame(&params, frame);
    if (ret < 0)
        goto fail;

    ret = nv->nvEncUnlockInputBuffer(ctx->nvenc_ctx, in->in);
    if (ret != NV_ENC_SUCCESS) {
        av_log(avctx, AV_LOG_ERROR, "Cannot unlock the buffer %p.\n",
               in);
        return AVERROR_UNKNOWN;
    }

    *in_surf = in;

    return 0;

fail:
    nv->nvEncUnlockInputBuffer(ctx->nvenc_ctx, in->in);

    return ret;
}
开发者ID:theambient,项目名称:libav,代码行数:43,代码来源:nvenc.c


注:本文中的NV_ENCODE_API_FUNCTION_LIST::nvEncUnlockInputBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。