简体   繁体   English

opencv中的视频数据

[英]video data in opencv

Can anybody please tell me in what format the video data is saved in opencv, after decoding it by ffmpeg. 任何人都可以通过ffmpeg对它进行解码后告诉我视频数据以什么格式保存在opencv中。 I mean if it is saved as a matrix then is it 8bit/pixel kind of thing? 我的意思是如果它被保存为矩阵那么它是8位/像素的东西吗? 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 . 查看文件modules/highgui/src/cap_ffmpeg_impl.hpp中的函数CvCapture_FFMPEG::open This method is called by, for example, cvCaptureFromAVI() and cvCaptureFromFile() . 该方法由例如cvCaptureFromAVI()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): 下面摘录的代码清楚地从文件中获取宽度和高度,但它忽略了输入位深度,并且始终使用内存中视频的打包8:8:8位RGB表示(如PIX_FMT_BGR24常量所示):

#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 : 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, ie, what will be handed off to opencv. 查看ffmpeg文档,此调用中的PIX_FMT_BGR24指定目标像素格式,即将传递给opencv的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM