简体   繁体   English

vp9 编码器返回一个空包

[英]vp9 encoder returns a null packet

i using this code to encode video stream using vp8 and i decided to give vp9 a try so i changed every thing with starts with vp_* from 8 to 9.我使用此代码使用 vp8 对视频流进行编码,我决定尝试使用 vp9,因此我将所有以 vp_* 开头的内容从 8 更改为 9。

but the vp9 encoder always return a null packet although the encoder doesn't return any error.但是 vp9 编码器总是返回一个空包,尽管编码器没有返回任何错误。
here is the code i'am using for configuring.这是我用于配置的代码。

vpx_codec_err_t error = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &enc_cfg, 0);
if(error != VPX_CODEC_OK)
    return error;
enc_cfg.g_timebase.den = fps;
enc_cfg.rc_undershoot_pct = 95;
enc_cfg.rc_target_bitrate = bitrate;
enc_cfg.g_error_resilient = 1;
enc_cfg.kf_max_dist = 999999;
enc_cfg.rc_buf_initial_sz = 4000;
enc_cfg.rc_buf_sz = 6000;
enc_cfg.rc_buf_optimal_sz = 5000;
enc_cfg.rc_end_usage = VPX_CBR;
enc_cfg.g_h = height;
enc_cfg.g_w = width;
enc_cfg.rc_min_quantizer = 4;
enc_cfg.rc_max_quantizer = 56;
enc_cfg.g_threads = 4;
enc_cfg.g_pass = VPX_RC_ONE_PASS;

error = vpx_codec_enc_init(&codec, vpx_codec_vp9_cx(), &enc_cfg, 0);
if(error != VPX_CODEC_OK)
    return error;
vpx_img_alloc(&vpx_image,VPX_IMG_FMT_I420 , width, height, 1);
configured = true;
return VPX_CODEC_OK; 

and the code for the encoding和编码的代码

  libyuv::RAWToI420(frame, vpx_image.d_w * 3, vpx_image.planes[VPX_PLANE_Y],vpx_image.stride[VPX_PLANE_Y],
    vpx_image.planes[VPX_PLANE_U], vpx_image.stride[VPX_PLANE_U], vpx_image.planes[VPX_PLANE_V], 
    vpx_image.stride[VPX_PLANE_V], vpx_image.d_w, vpx_image.d_h);
const vpx_codec_cx_pkt_t *pkt;
vpx_codec_err_t error = vpx_codec_encode(&codec, &vpx_image, 0, 1, 0, VPX_DL_GOOD_QUALITY);
if(error != VPX_CODEC_OK)
    return vector<byte>();
vpx_codec_iter_t iter = NULL;
if((pkt = vpx_codec_get_cx_data(&codec, &iter)))//always return null ?
{
    if(pkt->kind == VPX_CODEC_CX_FRAME_PKT)
    {
        int length = pkt->data.frame.sz;
        byte* buf = (byte*) pkt->data.frame.buf;
        vector<byte> data(buf, buf + length);
        return data;
    }
    return vector<byte>();
}
return vector<byte>();  

the code is fully working if i'am using vp8 instead of 9, any help is welcomed如果我使用的是 vp8 而不是 9,则代码完全正常工作,欢迎任何帮助

Just came across this post because I faced the same problem.刚刚看到这篇文章是因为我遇到了同样的问题。 Just for other to know: I solved it with setting仅供其他人知道:我通过设置解决了它

enc_cfg.g_lag_in_frames = 0;

This basically disallows the encoder to consume up to default 25 frames until it produces any output.这基本上不允许编码器消耗最多默认 25 帧,直到它产生任何输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM