Assertion desc failed at src/libswscale/swscale_internal.h:668

举报
风吹稻花香 发表于 2021/06/05 01:07:53 2021/06/05
【摘要】 Assertion desc failed at src/libswscale/swscale_internal.h:668 其实报错的代码: struct SwsContext *img_convert_ctx; img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCo...


Assertion desc failed at src/libswscale/swscale_internal.h:668

其实报错的代码:

struct SwsContext *img_convert_ctx;

img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);

原因:获取视频的宽高为0或者不正常,

pCodecCtx->width, pCodecCtx->height

解决方法:

printf("camno %d find stream\n", cam_no);
pFormatCtx->probesize = 1000 * 1024;
pFormatCtx->max_analyze_duration = 10 * AV_TIME_BASE;
pCodec = NULL;
while (pCodec == NULL) {
printf("%d start find stream info \n", cam_no);
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
printf("Couldn't find stream info %d\n", cam_no);
goto restart_stream;
continue;
}
videoindex = -1;
for (i = 0; i < pFormatCtx->nb_streams; i++)
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (videoindex == -1) {
videoindex = i;
}
//break;
}
if (videoindex == -1) {
printf("%d Didn't find a video stream.\n", cam_no);
goto restart_stream;
}
pCodecCtx = pFormatCtx->streams[videoindex]->codec;
//pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);

pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec == NULL) {
printf("%d Codec not found \n", cam_no);
goto restart_stream;
//return -1;
}
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
printf("%d Could not open codec.\n", cam_no);
goto restart_stream;
continue;
//return -1;
}
if (pCodecCtx->width <= 0 || pCodecCtx->height <= 0 || pCodecCtx->height >2000 || pCodecCtx->width >3000) {
printf("cam %d pCodecCtx error 1 width %d height %d ", cam_no, pCodecCtx->width, pCodecCtx->height);
goto restart_stream;
}
goto ok;
restart_stream:
printf("%d restart 1  ", cam_no);
avformat_free_context(pFormatCtx);
printf("restart 2  ");
//avformat_close_input(&pFormatCtx);
pFormatCtx = NULL;
pFormatCtx = avformat_alloc_context();
printf("restart 3  ");
//av_freep(aviobuffer);
//printf("restart 4");
aviobuffer = (unsigned char *)av_malloc(1512);
printf("restart 4  ");
AVIOContext *avio2 = avio_alloc_context(aviobuffer, 1512, 0, &deviceInfo, read_buffer, NULL, NULL);
pFormatCtx->pb = avio2;
pFormatCtx->probesize = 1000 * 1024;
pFormatCtx->max_analyze_duration = 10 * AV_TIME_BASE;
if (avformat_open_input(&pFormatCtx, NULL, NULL, NULL) != 0) {
printf("2Couldn't open input stream %d\n", cam_no);
//return -1;
}
printf("restart 5\n");
pCodec = NULL;
continue;
ok:
break;

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/80185858

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。