--- cap_ffmpeg_22.cpp Thu Mar 31 10:03:59 2011 +++ cap_ffmpeg.cpp Thu Mar 31 10:03:52 2011 @@ -476,13 +476,23 @@ picture = avcodec_alloc_frame(); rgb_picture.data[0] = (uint8_t*)cvAlloc( - avpicture_get_size( PIX_FMT_BGR24, + //avpicture_get_size( PIX_FMT_BGR24, + avpicture_get_size( enc->pix_fmt, enc->width, enc->height )); avpicture_fill( (AVPicture*)&rgb_picture, rgb_picture.data[0], - PIX_FMT_BGR24, enc->width, enc->height ); + // PIX_FMT_BGR24, enc->width, enc->height ); + enc->pix_fmt, enc->width, enc->height ); + // TODO do we want to generate an image of the same format as the source video or automatically convert to RGB + int channels = 3; + int depth = 8; + if ( PIX_FMT_BGR24 == enc->pix_fmt ) { + // 8,3 + } else if ( PIX_FMT_GRAY8 == enc->pix_fmt ) { + channels = 1; + } cvInitImageHeader( &frame, cvSize( enc->width, - enc->height ), 8, 3, 0, 4 ); + enc->height ), depth, channels, 0, 4 ); cvSetData( &frame, rgb_picture.data[0], rgb_picture.linesize[0] ); break; @@ -597,7 +607,8 @@ video_st->codec->pix_fmt, video_st->codec->width, video_st->codec->height, - PIX_FMT_BGR24, + //PIX_FMT_BGR24, + video_st->codec->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL); @@ -1265,6 +1276,17 @@ bitrate_scale = 128; break; case CODEC_ID_RAWVIDEO: + switch (fourcc) { + case 0x30303859: //Y800 + case 0x20203859: //Y8 + case 0x59455247: // GREY + codec_pix_fmt = input_pix_fmt = PIX_FMT_GRAY8; + break; + default: + codec_pix_fmt = input_pix_fmt; + break; + } + break; default: // good for lossy formats, MPEG, etc. codec_pix_fmt = PIX_FMT_YUV420P;