ffmpeg sws_scale avframe转为cv::Mat崩溃
0
使用sws_scale将avframe转为cv::Mat,windows没有问题,但是linux在分辨率1080*1920时就会崩溃,提示double free or corruption (!prev)。
这里需要宽度按照32对齐,所以需要先对齐在裁切即可。
int w = frame->width;
int h = frame->height;
if(frame->width % 32 != 0) {
w = ((w + 31) / 32) * 32;
}
cv::Mat mat(h, w, CV_8UC3);
uint8_t* dst_data = mat.data;
int dst_stride = mat.step1();
int out_heigth = sws_scale(sws_ctx, frame->data, frame->linesize, 0, h, &dst_data, &dst_stride);
if(frame->width % 32 != 0) {
mat = mat(cv::Rect(0, 0, frame->width, frame->height));
}