Further investigation (looping through pixel formats) found that it compiles with PIX_FMT_YUV410P which is YUV 4:1:0. But the program seg-faults when calling avcodec_encode_video( pOCodecCtx,Buffer,BufSiz,pFrame ); Any ideas?
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Cameron Sent: Wednesday, February 09, 2011 11:56 AM To: [email protected] Subject: [libav-user] colorspace not supported in jpeg Hi, I am starting out using ffmpeg and I am trying to turn an AVFrame into a jpg image. I have used some code I found to try doing this, but it sends me the error: "[mjpeg @ 0x8a36ab0]colorspace not supported in jpeg" It is generated by the code below I think from mpeg video_enc.c in the libavcodec directory case CODEC_ID_MJPEG: if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); return -1; } I have tried to look into this, and have discovered that the error is from changed from PIX_FMT_YUV420P to PIX_FMT_YUV422P with no success. Is there some way to fix this? Thanks, C. (below is the code I am trying) http://permalink.gmane.org/gmane.comp.video.ffmpeg.libav.user/5127 int WriteJPEG (AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo){ AVCodecContext *pOCodecCtx; AVCodec *pOCodec; uint8_t *Buffer; int BufSiz; int BufSizActual; int ImgFmt = PIX_FMT_YUV420P; //for the newer ffmpeg version, this int to pixelformat FILE *JPEGFile; char JPEGFName[256]; BufSiz = avpicture_get_size ( ImgFmt,pCodecCtx->width,pCodecCtx->height ); Buffer = (uint8_t *)malloc ( BufSiz ); if ( Buffer == NULL ) return ( 0 ); memset ( Buffer, 0, BufSiz ); pOCodecCtx = avcodec_alloc_context ( ); if ( !pOCodecCtx ) { free ( Buffer ); return ( 0 ); } pOCodecCtx->bit_rate = pCodecCtx->bit_rate; pOCodecCtx->width = pCodecCtx->width; pOCodecCtx->height = pCodecCtx->height; pOCodecCtx->pix_fmt = ImgFmt; pOCodecCtx->codec_id = CODEC_ID_MJPEG; pOCodecCtx->codec_type = CODEC_TYPE_VIDEO; pOCodecCtx->time_base.num = pCodecCtx->time_base.num; pOCodecCtx->time_base.den = pCodecCtx->time_base.den; pOCodec = avcodec_find_encoder ( pOCodecCtx->codec_id ); if ( !pOCodec ) { free ( Buffer ); return ( 0 ); } if ( avcodec_open ( pOCodecCtx, pOCodec ) < 0 ) { free ( Buffer ); printf("Could not open codec\n"); return ( 0 ); } pOCodecCtx->mb_lmin = pOCodecCtx->lmin = pOCodecCtx->qmin * FF_QP2LAMBDA; pOCodecCtx->mb_lmax = pOCodecCtx->lmax = pOCodecCtx->qmax * FF_QP2LAMBDA; pOCodecCtx->flags = CODEC_FLAG_QSCALE; pOCodecCtx->global_quality = pOCodecCtx->qmin * FF_QP2LAMBDA; pFrame->pts = 1; pFrame->quality = pOCodecCtx->global_quality; printf("hERE3\n"); BufSizActual = avcodec_encode_video( pOCodecCtx,Buffer,BufSiz,pFrame ); printf("hERE4\n"); sprintf ( JPEGFName, "%06d.jpg", FrameNo ); JPEGFile = fopen ( JPEGFName, "wb" ); fwrite ( Buffer, 1, BufSizActual, JPEGFile ); fclose ( JPEGFile ); avcodec_close ( pOCodecCtx ); free ( Buffer ); return ( BufSizActual ); } Thank you, C _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
