vlc 缓冲大小 设置_用libvlc 播放指定缓冲区中的视频流

//vlcTest.cpp : 定义控制台应用程序的入口点。//#include"stdafx.h"#include#include"vlc/vlc.h"#include#include#include#includeQMutex 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;const char* TestFile = "b040_20170106.dat";//

/**

\brief Callback method triggered by VLC to get image data from

a custom memory source. This is used to tell VLC where the

data is and to allocate buffers as needed.

To set this callback, use the "--imem-get="

option, with memory_address the address of this function in memory.

When using IMEM, be sure to indicate the format for your data

using "--imem-cat=2" where 2 is video. Other options for categories are

0 = Unknown,

1 = Audio,

2 = Video,

3 = Subtitle,

4 = Data

When creating your media instance, use libvlc_media_new_location and

set the location to "imem:/" and then play.

\param[in] data Pointer to user-defined data, this is your data that

you set by passing the "--imem-data=" option when

initializing VLC instance.

\param[in] cookie A user defined string. This works the same way as

data, but for string. You set it by adding the "--imem-cookie="

option when you initialize VLC. Use this when multiple VLC instances are

running.

\param[out] dts The decode timestamp, value is in microseconds. This value

is the time when the frame was decoded/generated. For example, 30 fps

video would be every 33 ms, so values would be 0, 33333, 66666, 99999, etc.

\param[out] pts The presentation timestamp, value is in microseconds. This

value tells the receiver when to present the frame. For example, 30 fps

video would be every 33 ms, so values would be 0, 33333, 66666, 99999, etc.

\param[out] flags Unused,ignore.

\param[out] bufferSize Use this to set the size of the buffer in bytes.

\param[out] buffer Change to point to your encoded frame/audio/video data.

The codec format of the frame is user defined and set using the

"--imem-codec=," where 4 letter is the code for your

codec of your source data.*/

int MyImemGetCallback (void *data,const char *cookie,

int64_t*dts,

int64_t*pts,

unsigned*flags,

size_t*bufferSize,void **buffer)

{static int64_t _dts = 0, _pts = 0;if (!g_isInit){/*load local file*/local= fopen(TestFile,"rb");if (!local){return true;

}

size_t count= fread(in_buffer,1,IMG_WIDTH*IMG_HEIGHT*4,local);*bufferSize =count;*buffer =in_buffer;

g_isInit= true;*dts = _dts; *pts =_pts;

_dts+=30; _pts+=30;return 0;

}

size_t count= fread(in_buffer,1,IMG_WIDTH*IMG_HEIGHT*4,local);*bufferSize =count;*buffer =in_buffer;*dts = _dts; *pts =_pts;

_dts+=30; _pts+=30;if(count>0) {

printf("read %d bytes\n",count);return 0;

}else{return true; /*eof*/}

}/**

\brief Callback method triggered by VLC to release memory allocated

during the GET callback.

To set this callback, use the "--imem-release="

option, with memory_address the address of this function in memory.

\param[in] data Pointer to user-defined data, this is your data that

you set by passing the "--imem-data=" option when

initializing VLC instance.

\param[in] cookie A user defined string. This works the same way as

data, but for string. You set it by adding the "--imem-cookie="

option when you initialize VLC. Use this when multiple VLC instances are

running.

\param[int] bufferSize The size of the buffer in bytes.

\param[out] buffer Pointer to data you allocated or set during the GET

callback to handle or delete as needed.*/

int MyImemReleaseCallback (void *data,const char *cookie,

size_t bufferSize,void *buffer)

{//Since I did not allocate any new memory, I don't need//to delete it here. However, if you did in your get method, you//should delete/free it here.

return 0;

}//

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;

std::vectoroptions;

std::vector::iterator option;

options.push_back("--no-video-title-show");char imemDataArg[256];

sprintf(imemDataArg,"--imem-data=%#p", in_buffer);

options.push_back(imemDataArg);char imemGetArg[256];

sprintf(imemGetArg,"--imem-get=%#p", MyImemGetCallback);

options.push_back(imemGetArg);char imemReleaseArg[256];

sprintf(imemReleaseArg,"--imem-release=%#p", MyImemReleaseCallback);

options.push_back(imemReleaseArg);

options.push_back("--imem-cookie=\"IMEM\"");

options.push_back("--imem-codec=H264");//Video data.

options.push_back("--imem-cat=2");/*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 media item from file

m = libvlc_media_new_location (inst, "imem://"); /*##use memory as input*/

//Set media options

for(option = options.begin(); option != options.end(); option++){

libvlc_media_add_option(m,*option);

}/*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);//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);return 0;

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/487563.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微信小程序开源Demo精选

来自:http://www.jianshu.com/p/0ecf5aba79e1 文/weapphome(简书作者) 原文链接:http://www.jianshu.com/p/0ecf5aba79e1 著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。 1. 仿…

mac mysql的初始密码_MAC版修改MySQL初始密码的方法

解决方式:亲测方法3,已成功重置密码。step1:cd /usr/local/mysql/bin/苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server)step2:cd /usr/local/mysql/bin/回车后 登录管理员权限sudo su…

不输GPS!30颗卫星全部就位!北斗三号全球卫星导航星座部署顺利收官

随着此次发射的成功,北斗三号30颗组网卫星已全部到位,北斗三号全球卫星导航系统星座部署全面完成。来源:澎湃新闻视频:多角度直击北斗三号全球系统“收官之星”发射瞬间,时长约1分12秒6月23日,由中国航天科…

Django ORM 数据库操作

比较有用 转自 http://blog.csdn.net/fgf00/article/details/53678205 一、DjangoORM 创建基本类型及生成数据库表结构 1、简介 2、创建数据库 表结构 二、Django ORM基本增删改查 1、表数据增删改查 2、表结构修改 三、Django ORM 字段类型 1、字段类型介绍 2、字段参数介绍 3…

AI芯片的另一条路

来源:半导体行业观察在先进工艺和架构的协同下,芯片的性能在过去几年获得了爆发性的增长,尤其是在最近几年火热的人工智能行业,这个取得的成就是有目共睹的。据OpenAI在2018年年中发表的报告,自 2012 年以来&#xff0…

JavaScript之event事件

目录 1:事件驱动1 2:事件分类2 3:事件对象event3 4:关于鼠标事件对象属性3 应用:5 5:关于键盘事件对象的属性6 6:目标事件源对象7 7. 事件冒泡7 应用:8 CSS模拟下拉菜单。8 综合应用…

mysql和oracle转换_转MySql 与Oracle区别

http://blog.sina.com.cn/s/blog_61e034d50100k6xn.html近期突击学习了mysql,应杨毅的邀请,简单比较一下mysql和oracle的差别,不当之处欢迎大家指正。一、并发性并发性是oltp数据库最重要的特性,但并发涉及到资源的获取、共享与锁…

四大全球卫星导航系统都能提供什么服务?

来源:远望智库预见未来远望智库特约专家 陈刘成卫星导航系统是人类发明的最为重要的时间和空间测量工具。没有测量就没有科学,没有测量就没有管理。卫星导航系统价值集中体现在帮助人类精确感知、认知、控制物质、能量、信息的时空运行与分布。目前已经建…

UWP开发入门(十六)——常见的内存泄漏的原因

UWP开发入门(十六)——常见的内存泄漏的原因 原文:UWP开发入门(十六)——常见的内存泄漏的原因本篇借鉴了同事翔哥的劳动成果,在巨人的肩膀上把稿子又念了一遍。 内存泄漏的概念我这里就不说了,之前《UWP开…

一文了解72名图灵奖获得者的成就

来源:图灵教育今天是计算机科学之父、人工智能之父 艾伦麦席森图灵 诞辰 108 周年。作为“图灵意志”的传承者,依照惯例,在今日纪念这位伟人。从“图灵机”到“图灵测试”,从破译德军的 Enigma 到自杀之谜,图灵一生都是…

安卓修改wifi已停用_手机连不上wifi显示已保存怎么回事【原因介绍】

问:为什么手机连不上wifi显示已保存?手机在连接WiFi的时候,WiFi显示已保存,手机连接不上wifi信号。请问这是什么原因引起的,应该怎么解决这个问题。答:如果手机连接wifi时,显示已保存,手机连接…

有关 Lambda linq练习 有待整理

1、 查询Student表中的所有记录的Sname、Ssex和Class列。(select sname,ssex,class from student) Students.Select(s> new { sname>s.sname,ssex>s.ssex, class>s.class})linq:from s in Students select new{s.sname, } 2.查询教师所有的单位即不重复的Depart列…

机器人智能抓取系统:目前几种主流的解决方案

文章来源:COBOT机器人大脑、新机器视觉机器人学习中的经典问题之一便是分拣:在一堆无序摆放的物品堆中,取出目标物品。在快递分拣员看来,这几乎是一个不需要思考的过程,但对于机械臂而言,这意味着复杂的矩阵…

mysql 5.6的gtid_mode_[MySQL 5.6] GTID实现、运维变化及存在的bug

本文的主要目的是记下跟gtid相关的backtrace,用于以后的问题排查。另外也会讨论目前在MySQL5.6.11版本中存在的bug。前言:什么是GTID什么是GTID呢, 简而言之,就是全局事务ID(global transaction identifier ),最初由go…

bzoj1018 [SHOI2008]堵塞的交通traffic

题目链接 分析: 这道题的题解很长,所以就不粘题面了,我们一点一点讲明白这道题 很荣幸,我看了题面之后 想到了这道题 可以很高兴的发现10w是线段树能够承受的范围 我们可以利用线段树维护连通性,每个节点内我们要维…

Science重磅!人类特有基因触发猴子长出更强大的大脑

本文系生物谷原创编译,欢迎分享,转载须授权!人类大脑在进化过程中的扩张,特别是新大脑皮层的扩张,与诸如推理和语言等认知能力有关。有一种叫做ARHGAP11B的基因,只在人类身上表达,它能触发大脑干…

mysql不同的类的个数_Mysql数据库-SQL优化-统计某种类型的个数

有时我们想统计某种类型有多少个,会用这个SQL。全表扫描之余,还要filesort,耗时1.34秒。mysql> select country,count(*) from t1 group by country;-------------------| country | count(*) |-------------------| NULL | 32 || africa …

『实践』Matlab实现Flyod求最短距离及存储最优路径

Matlab实现Flyod求最短距离及存储最优路径 一、实际数据 已知图中所有节点的X、Y坐标。 图中的节点编号:矩阵中的编号 J01-J62:1-62; F01-F60:63-122; Z01-Z06:123-128; D01-D02:129-130. 二、Floyd求所有节点间的最小距离及通过矩阵存储最优路径的节点 1 function …

MIT Technology Review 2020年“十大突破性技术”解读 【中国科学基金】2020年第3期发布...

来源:国家自然科学基金委员会MIT Technology Review 2020年“十大突破性技术”解读[编者按] 2020年2月26日,MIT Technology Review一年一度的“十大突破性技术”榜单正式发布。自2001年起,该杂志每年都会评选出当年的…

动态代理Java实现

思考:在IBuyWatermelon添加一个方法selectWatermelon() 静态代理中需要在RealSubject中实现该方法,而且Proxy也要实现该方法调用RealSubject中的实现,如果再增加10个方法还是得这样操作,导致大量的代码重复。 现在来看动态代理&am…