首页 / 更多教程 / 用libvlc 抓取解码后的帧数据
用libvlc 抓取解码后的帧数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了用libvlc 抓取解码后的帧数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3303字,纯文字阅读大概需要5分钟。
内容图文
vlc是一套优秀的开源媒体库,其特点是提供了完整的流媒体框架, 用它可以非常方便的实现抓取解码帧的功能。
与此功能有关的关键API为
libvlc_video_set_callbacks /*设置回调,用来抓取解码后的帧*/
libvlc_video_set_format /*设置解码帧的格式 yuv or rgba ?*/
这个函数将三个函数指针作为参数
/* callback function, lock the shared memory, and tell vlc where to put the output frame data */ static void *lock(void *data, void **p_pixels); /*##get the out frame data AND u can save it to file, or sent it to a next module*/staticvoid unlock(void *data, void *id, void *const *p_pixels); /*how to display the result frame data, u can let vlc do not pop out the displaying gui via this fuction. */staticvoid display(void *data, void *id);
下面是完整示例子:
#include "stdafx.h" #include <Windows.h> #include "vlc/vlc.h" #include <vector> #include <qmutex> #include <sstream> #include <qimage> QMutex g_mutex; bool g_isInit = false; int IMG_WIDTH = 640; int IMG_HEIGHT = 480; char in_buffer[640*480*4]; char out_buffer[640*480*4]; FILE *local; int frameNum = 0; constchar* TestFile = "b040_20170106.dat"; //////////////////////////////////////////////////////////////////////////staticvoid *lock(void *data, void **p_pixels) { g_mutex.lock(); *p_pixels = out_buffer; /*tell VLC to put decoded data to this buffer*/return0; /* picture identifier, not needed here */ } /*##get the argb picture AND save to file*/staticvoid unlock(void *data, void *id, void *const *p_pixels) { QImage image((unsigned char*)out_buffer,640,480,QImage::Format_ARGB32); std::ostringstream oss; oss << "d:/img" << frameNum << ".jpg"; frameNum++; image.save(oss.str().c_str()); g_mutex.unlock(); } staticvoid display(void *data, void *id) { /* do not display the video */ (void) data; } //////////////////////////////////////////////////////////////////////////int main(int argc, char* argv[]) { libvlc_instance_t * inst; libvlc_media_player_t *mp; libvlc_media_t *m; libvlc_time_t length; int wait_time=5000; /* Load the VLC engine */ inst = libvlc_new (int(options.size()), options.data()); // Configure any transcoding or streaming // options for the media source. options.clear(); //Create a new item //Method 1: //m = libvlc_media_new_location (inst, "file:///F:\\movie\\cuc_ieschool.flv"); //Screen Capture //m = libvlc_media_new_location (inst, "screen://"); //Method 2:
m = libvlc_media_new_path (inst, "D:\\warehouse\\data\\615\\haze.mp4"); /* Create a media player playing environment */ mp = libvlc_media_player_new_from_media (m); /* No need to keep the media now */ libvlc_media_release (m); /*##comment the followint 2 lines , if you want the out frame display in screen*/ libvlc_video_set_callbacks(mp, lock, unlock, display, 0); libvlc_video_set_format(mp, "RGBA", IMG_WIDTH, IMG_HEIGHT,IMG_WIDTH*4); // play the media_player libvlc_media_player_play (mp); //wait until the tracks are created _sleep (wait_time); length = libvlc_media_player_get_length(mp); IMG_WIDTH = libvlc_video_get_width(mp); IMG_HEIGHT = libvlc_video_get_height(mp); printf("Stream Duration: %ds\n",length/1000); printf("Resolution: %d x %d\n",IMG_WIDTH,IMG_HEIGHT); //Let it play _sleep (length-wait_time); // Stop playing libvlc_media_player_stop (mp); // Free the media_player libvlc_media_player_release (mp); libvlc_release (inst); return0; }
原文:http://www.cnblogs.com/enigma19971/p/6269014.html
内容总结
以上是互联网集市为您收集整理的用libvlc 抓取解码后的帧数据全部内容,希望文章能够帮你解决用libvlc 抓取解码后的帧数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。