我正在尝试使用 libx265(libx264 之前尝试过)对来自网络摄像头的图像进行编码......
由于进入矩阵的光量不同,因此网络摄像头无法以稳定的 FPS 拍摄,因此延迟不同。因此,我计算传入帧的 fps 和 dts 并将这些值设置为对象的相应参数,并使用 1000 和1(用于毫秒时基)x265_image
初始化编码器。
问题是编码器忽略了输入图像的 pts 和 dts 并以 1000 fps 进行编码!与时基相同的技巧使用 libvpx 产生平滑的记录。为什么它不适用于 x264/x265 编解码器?fpsNum
fpsDenom
这是参数初始化:
...
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;
}
全局 PTS 在x265_encoder_encode
调用后立即增加:
当涉及到编码器时,它设置为队列pts+= pic_in->dts;
中新图像的 pts 。framestack
x265/x264 编解码器能否以可变 fps 进行编码?如果是,如何配置?