用libvlc 抓取解码后的帧数据
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*/
static void 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. */
static void 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 = ;
int IMG_HEIGHT = ;
char in_buffer[**];
char out_buffer[**];
FILE *local;
int frameNum = ; const char* TestFile = "b040_20170106.dat";
//////////////////////////////////////////////////////////////////////////
static void *lock(void *data, void **p_pixels)
{
g_mutex.lock();
*p_pixels = out_buffer; /*tell VLC to put decoded data to this buffer*/
return ; /* picture identifier, not needed here */
} /*##get the argb picture AND save to file*/
static void unlock(void *data, void *id, void *const *p_pixels)
{
QImage image((unsigned char*)out_buffer,,,QImage::Format_ARGB32);
std::ostringstream oss;
oss << "d:/img"
<< frameNum
<< ".jpg";
frameNum++;
image.save(oss.str().c_str());
g_mutex.unlock();
} static void 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=; /* 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, );
libvlc_video_set_format(mp, "RGBA", IMG_WIDTH, IMG_HEIGHT,IMG_WIDTH*); // 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/);
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); return ;
}
用libvlc 抓取解码后的帧数据的更多相关文章
- Hawk: 20分钟无编程抓取大众点评17万数据
1. 主角出场:Hawk介绍 Hawk是沙漠之鹰开发的一款数据抓取和清洗工具,目前已经在Github开源.详细介绍可参考:http://www.cnblogs.com/buptzym/p/545419 ...
- Wireshark抓取本地回环接口数据包 RawCap.exe
Wireshark提供了winpcap可以抓取远程网卡数据包...但我尝试了不成功.后来发现RawCap.exe不仅可以抓取回环接口数据包,远程跑了拿到pcap文件再打开用起来比winpcap更方便最 ...
- 抓取摩拜单车API数据,并做可视化分析
抓取摩拜单车API数据,并做可视化分析 纵聊天下 百家号|04-19 15:16 关注 警告:此篇文章仅作为学习研究参考用途,请不要用于非法目的. 摩拜是最早进入成都的共享单车,每天我从地铁站下来的时 ...
- 使用 usbmon 抓取 usb 总线上的数据
使用 usbmon 抓取 usb 总线上的数据 usbmon 即 usb monitor,是 linux 内置的 usb 抓包工具.usbmon 本质是一个内核模块,在我的 ubuntu14.0 4中 ...
- SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享
SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享 第一步建库和建表 USE [master] GO CREATE DATABASE [MonitorElapsedHighSQL] G ...
- SQL Server定时自动抓取耗时SQL并归档数据脚本分享
原文:SQL Server定时自动抓取耗时SQL并归档数据脚本分享 SQL Server定时自动抓取耗时SQL并归档数据脚本分享 第一步建库 USE [master] GO CREATE DATABA ...
- 测试开发Python培训:抓取新浪微博评论提取目标数据-技术篇
测试开发Python培训:抓取新浪微博评论提取目标数据-技术篇 在前面我分享了几个新浪微博的自动化脚本的实现,下面我们继续实现新的需求,功能需求如下: 1,登陆微博 2,抓取评论页内容3,用正则表 ...
- 利用wireshark抓取远程linux上的数据包
原文发表在我的博客主页,转载请注明出处. 前言 因为出差,前后准备总结了一周多,所以博客有所搁置.出差真是累人的活计,不过确实可以学习到很多东西,跟着老板学习做人,学习交流的技巧.入正题~ wires ...
- 用PHP抓取百度贴吧邮箱数据
注:本程序可能非常适合那些做百度贴吧营销的朋友. 去逛百度贴吧的时候,经常会看到楼主分享一些资源,要求留下邮箱,楼主才给发. 对于一个热门的帖子,留下的邮箱数量是非常多的,楼主需要一个一个的去复制那些 ...
随机推荐
- 学习python-20191208(1)-Python Flask高级编程开发鱼书_第03章_数据与flask路由
视频01: 略...... ———————————————————————————————————————————————————————————— 视频02: 搜索需要外部数据源,也就是需要外部的A ...
- Xming+SecureCRT的安装与使用
博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽 Xming下载地址:https://xming.en.softonic.com/ 安装完后打开文件位置: 一.Xming ...
- 谷歌眼镜、亚马逊音箱,5G时代隐私或将面临更大颠覆
别看现在的智能手机.平板电脑.可穿戴设备.智能家居等那么火爆,但离开网络它们其实什么也不是.当然,智能终端设备的迭进也是与网络制式不断向前演变相辅相成的,二者算是互相成就.不过也由此衍生出很多问题,尤 ...
- mysql 数据库 创建用户和授权
创建用户和密码 CREATE USER '用户名'@'%' IDENTIFIED BY '密码'; 创建几个数据库 例如 db1,db2 用户授权访问指定的数据库 grant all privileg ...
- org.apache.http.NoHttpResponseException
org.apache.http.NoHttpResponseException 异常: org.apache.http.NoHttpResponseException: The target serv ...
- mongo的基本命令操作
基本用法学习:https://www.runoob.com/mongodb/mongodb-create-database.html MongoDB数据库基本用法 show dbs:显示数据库列表 s ...
- abator中可生成iBatis的代码
1.insert 不论你设置多少个字段,统一都要添加一遍 比如:insert into tb_user (id,name,age,password) value (null,”张三”,null,nul ...
- SQL update 关联更改,内部需要引用表名
select A.Id,A.Email,( select C.Email from [nopCommerce].[dbo].[Customer] C left join [nopCommerce].[ ...
- MyBatisUtil
package com.it.util; import java.io.IOException; import java.io.Reader; import org.apache.ibatis.io. ...
- MIUI 7 会是小米的救命稻草吗?
7 会是小米的救命稻草吗?" title="MIUI 7 会是小米的救命稻草吗?"> 花无百日红,人无千日好.再绚烂的曾经,或许一朝不慎,就会成为过去.在科技圈,诺 ...