qq_15106323 2017-06-22 07:19 采纳率: 66.7%
浏览 1867

x264 中x264_encoder_encode函数崩溃

最近在做录屏项目时用到了H264编码,感觉很崩溃,就在网上down了段代码,调试的时候不动屏幕还好,还可以一直编码,一动屏幕(比如最大化,最小化一个窗口,或打开网页等操作)程序就崩溃了,
错误位置:(x264_encoder_encode(h, &nal, &nnal, &pic, &pic_out) < 0)
显示的错误: 0x00000000 处有未经处理的异常: 0xC0000005: Access violation
nal这个变量为NULL。
下面是我初始化的代码:
bool x264enc::InitX264Encoder(unsigned short usWidth,unsigned short usHeight,int nKeyFrameInterval,int nFrameRate,int nQuality)
{
x264_param_t param;
x264_param_default(&param);
param.i_width = usWidth;
param.i_height = usHeight;
param.rc.i_qp_min=20;
param.rc.i_qp_max=31;
param.rc.f_qcompress=0.5f;
param.rc.i_qp_constant=0;
param.rc.i_rc_method = X264_RC_CRF;
param.rc.f_rf_constant = 8.5f;
param.i_log_level = X264_LOG_NONE;

h = x264_encoder_open(&param); 
if(h == NULL) 
{ 
    return false; 
} 

m_usWidth=usWidth; 
m_usHeight=usHeight; 
return true; 

}
下面是我编码时候的代码:
bool x264enc::X264Encode(unsigned char* pInFrame,const int& nInLen,unsigned char* pOutFrame,int& nOutLen,bool& bKeyFrame)
{
x264_nal_t *nal;
x264_picture_t pic_out;
x264_picture_t pic;
int nnal = 0;
if(pInFrame)
{
pic.img.i_csp = X264_CSP_I420;
pic.img.i_plane = 3;
pic.img.plane[0] = pInFrame;
pic.img.plane[1] = pInFrame + m_usWidth*m_usHeight;
pic.img.plane[2] = pic.img.plane[1] + (m_usWidth*m_usHeight / 4);
pic.img.i_stride[0] = m_usWidth;
pic.img.i_stride[1] = m_usWidth / 2;
pic.img.i_stride[2] = m_usWidth / 2;
pic.i_type = X264_TYPE_AUTO;

    if(x264_encoder_encode(h, &nal, &nnal, &pic, &pic_out) < 0) 
    { 
        return false; 
    } 
} 
else 
{ 
    if(x264_encoder_encode(h, &nal, &nnal, NULL, &pic_out) < 0) 
    { 
        return false; 
    } 
} 

if(nnal <= 0) 
    return false; 

nOutLen = encode_nals(pOutFrame,nOutLen, nal, nnal); 

if(nOutLen < 0) 
{ 
    return false; 
} 
if(pic_out.i_type == X264_TYPE_IDR) 
{ 
    bKeyFrame = true; 
} 
else 
{ 
    bKeyFrame = false; 
} 
return true; 

}
我在网上看大家写的都差不多,搞不懂是哪里错了,求大神指点,有没有x264的开发文档啊,里面的参数都不知道是什么意思,英文的也行。

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2018-09-01 15:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示