Assertion desc failed at src/libswscale/swscale_internal.h:668
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
- 点赞
- 收藏
- 关注作者
评论(0)