Can anybody please tell me in what format the video data is saved in opencv, after decoding it by ffmpeg. I mean if it is saved as a matrix then is it 8bit/pixel kind of thing? If anybody can provide some documents or link explaining in details will be a great help. I also tried to google but couldn't find something related.
Thanks.
The definitive reference to examine is probably the code itself! Look at the function CvCapture_FFMPEG::open
in the file modules/highgui/src/cap_ffmpeg_impl.hpp
. This method is called by, for example, cvCaptureFromAVI()
and cvCaptureFromFile()
. The code excerpted below clearly gets the width and height from the file, but it ignores the input bit depth and always uses a packed 8:8:8 bit RGB representation of the video in memory (as indicated by the PIX_FMT_BGR24
constant):
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
int err = avformat_open_input(&ic, _filename, NULL, NULL);
#else
int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
#endif
.......
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 3, 0)
avformat_find_stream_info(ic, NULL);
#else
av_find_stream_info(ic);
#endif
.......
avpicture_fill( (AVPicture*)&rgb_picture, rgb_picture.data[0],
PIX_FMT_BGR24, enc->width, enc->height );
Further evidence that this is the case is provided by the following code in CvCapture_FFMPEG::retrieveFrame
:
img_convert_ctx = sws_getCachedContext(
NULL,
video_st->codec->width, video_st->codec->height,
video_st->codec->pix_fmt,
video_st->codec->width, video_st->codec->height,
PIX_FMT_BGR24,
SWS_BICUBIC,
NULL, NULL, NULL
);
Looking at the ffmpeg documentation, the PIX_FMT_BGR24
in this call specifies the destination pixel format, i.e., what will be handed off to opencv.