ffmpeg - swscaler@0dd9e620: deprecated pixel format used, make sure you did set range correctly" -
i decoding rtsp video stream ffmpeg. @ display time (call cv::imshow(...)
), following exception:
[swscaler @ 0d55e5c0] deprecated pixel format used, make sure did set range correctly
i converting pixel format "av_pix_fmt_yuvj420p" "av_pix_fmt_yuv420p". still getting above exception. appreciated;
int decodestream() { av_register_all(); avdevice_register_all(); avcodec_register_all(); avformat_network_init(); const char *filenamesrc = "rtsp://192.168.1.67/gnz_media/second"; avcodeccontext *pcodecctx; avformatcontext *pformatctx = avformat_alloc_context(); avcodec * pcodec; avframe *pframe, *pframergb; if(avformat_open_input(&pformatctx,filenamesrc,null,null) != 0) {return -1;} if(av_find_stream_info(pformatctx) < 0) {return -1;} av_dump_format(pformatctx, 0, filenamesrc, 0); int videostream = 1; for(int i=0; < pformatctx->nb_streams; i++) { if(pformatctx->streams[i]->codec->coder_type==avmedia_type_video) { videostream = i; break; } } if(videostream == -1) return -1 ; pcodecctx = pformatctx->streams[videostream]->codec; pcodec =avcodec_find_decoder(pcodecctx->codec_id); if(pcodec==null) {return -1;} //codec not found if(avcodec_open2(pcodecctx,pcodec,null) < 0) { return -1;} pframe = avcodec_alloc_frame(); pframergb = avcodec_alloc_frame(); uint8_t *buffer; int numbytes; avpixelformat pformat; switch (pformatctx->streams[videostream]->codec->pix_fmt) { case av_pix_fmt_yuvj420p : pformat = av_pix_fmt_yuv420p; break; case av_pix_fmt_yuvj422p : pformat = av_pix_fmt_yuv422p; break; case av_pix_fmt_yuvj444p : pformat = av_pix_fmt_yuv444p; break; case av_pix_fmt_yuvj440p : pformat = av_pix_fmt_yuv440p; default: pformat = pformatctx->streams[videostream]->codec->pix_fmt; break; } numbytes = avpicture_get_size(pformat,pcodecctx->width,pcodecctx->height) ; buffer = (uint8_t *) av_malloc(numbytes*sizeof(uint8_t)); avpicture_fill((avpicture *) pframergb,buffer,pformat,pcodecctx->width,pcodecctx->height); int res, framefinished; avpacket packet; while(res = av_read_frame(pformatctx,&packet)>=0) { if(packet.stream_index == videostream){ avcodec_decode_video2(pcodecctx,pframe,&framefinished,&packet); if(framefinished){ struct swscontext * img_convert_ctx; img_convert_ctx = sws_getcachedcontext(null,pcodecctx->width, pcodecctx->height, pcodecctx->pix_fmt, pcodecctx->width, pcodecctx->height, av_pix_fmt_bgr24, sws_bicubic, null, null,null); sws_scale(img_convert_ctx, ((avpicture*)pframe)->data, ((avpicture*)pframe)->linesize, 0, pcodecctx->height, ((avpicture *)pframergb)->data, ((avpicture *)pframergb)->linesize); cv::mat img(pframe->height,pframe->width,cv_8uc3,pframergb->data[0]); cv::imshow("display",img); cvwaitkey(10); } } } //memory clean code goes here }
Comments
Post a Comment