繁体   English   中英

为什么编解码器x264 / x265忽略输入帧的pts和dts?

[英]Why codecs x264/x265 ignores pts and dts of input frame?

我正在尝试使用libx265(更早尝试过的libx264)对来自网络摄像头的图像进行编码...
网络摄像头无法以稳定的FPS进行拍摄,因为进入矩阵的光量不同,因此延迟也不同。 因此,我对传入帧的fps和dts进行计数,并为x265_image对象的相应参数设置这些值,然后将编码器fpsNum为1000,将fpsDenom为1(毫秒时基)。
问题是编码器会忽略输入图像的pts和dts并以1000 fps进行编码! 使用时基的相同技巧可以使用libvpx产生流畅的记录。 为什么它不适用于x264 / x265编解码器?

这是参数初始化:

...
    error = (x265_param_default_preset(param, "fast", "zerolatency") != 0);
    if(!error){
        param->sourceWidth = width;
        param->sourceHeight = height;
        param->frameNumThreads = 1;
        param->fpsNum = 1000;
        param->fpsDenom =  1;
        // Intra refres:
        param->keyframeMax = 15;
        param->intraRefine = 1;
        // Rate control:
        param->rc.rateControlMode = X265_RC_CQP;
        param->rc.rfConstant = 12;
        param->rc.rfConstantMax = 48;
        // For streaming:
        param->bRepeatHeaders = 1;
        param->bAnnexB = 1;
        encoder = x265_encoder_open(param);
        ...
    }
...

这是帧添加功能:

bool hevc::Push(unsigned char *data){
    if(!error){
        std::lock_guard<std::mutex> lock(m_framestack);
        if( timer > 0){
            framestack.back()->dts = clock() - timer;
            timer+= framestack.back()->dts;
        }
        else{timer = clock();}
        x265_picture *picture = x265_picture_alloc();
        if( picture){
            x265_picture_init(param, picture);
            picture->height = param->sourceHeight;
            picture->stride[0] = param->sourceWidth;
            picture->stride[1] = picture->stride[2] = picture->stride[0] / 2;
            picture->planes[0] = new char[  luma_size];
            picture->planes[1] = new char[chroma_size];
            picture->planes[2] = new char[chroma_size];

            colorspaces::BGRtoI420(param->sourceWidth, param->sourceHeight, data, (byte*)picture->planes[0], (byte*)picture->planes[1], (byte*)picture->planes[2]);
            picture->pts = picture->dts = 0;
            framestack.emplace_back(picture);
        }
        else{error = true;}
    }
    return !error;
}

在调用x265_encoder_encode之后,全球PTS不断增加: pts+= pic_in->dts; 并将其设置为来自framestack队列的新图像的pts。

x265 / x264编解码器能否以可变fps进行编码? 是,如何配置?

我不了解x265,但在x264中对可变帧率(VFR)视频进行编码时,应启用x264_param_t.b_vfr_input选项,该选项已由零延迟调整禁用(VFR编码需要1帧延迟)。 另外,至少在x264时基中,i_timebase_num / i_timebase_den和i_fps_num / i_fps_den应该为平均fps(如果您不知道fps,则保持默认值为25/1),否则将破坏速率控制。

暂无
暂无

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

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