libvlc_media_t的创建

创建libvlc_media_t有两种方法:libvlc_media_new_path()和libvlc_media_new_location()。简单描述一下这两个函数的区别:libvlc_media_new_location()用于打开协议,而libvlc_media_new_path()用于打开文件。因而传递给libvlc_media_new_path()的就是普通的文件路径(绝对路径例如D:\xxx.flv,或者相对路径例如xxx.flv),而传递给libvlc_media_new_location()的就是协议地址(例如“udp://….”,“http://”)。但是这里有一点需要注意,在VLC中“文件”也属于一种广义上的“协议”。因此使用libvlc_media_new_location()也可以打开文件,但是必须在文件路径前面加上“文件协议”的标记“file:///”。例如打开“F:\movie\cuc_ieschool.flv”下的视频,实际使用的代码如下所示。

libvlc_media_new_location (inst, "file:///F:\\movie\\cuc_ieschool.flv");  

此外,VLC还支持很多“神奇”的协议,比如输入“screen://”协议就可以进行屏幕录制,代码如下。

libvlc_media_new_location (inst, "screen://"); 

把libVLC的弹出窗口嵌入到程序中

在这里我只实践过Windows下把libVLC的弹出窗口嵌入到程序中。将窗口或者控件的句柄传递给libvlc_media_player_set_hwnd()函数即可。
这里有一点需要注意,如果把libVLC弹出窗口嵌入到程序中的话,“全屏”功能就不能使用了。

关于libVLC加载的问题

在libVLC中可以通过libvlc_media_player_get_length(),libvlc_video_get_width(),libvlc_video_get_height()等函数获取到视频的时长,宽,高等信息。但是有一个很奇怪的现象:如果在调用完libvlc_media_player_play()之后立即调用上述3个函数的话,返回的值都是0,只有“等待”一段时间(例如调用sleep())后再调用上述函数,才能得到正确的数值。对于这种现象,我觉得可能是libVLC加载完成之后,才能通过上述几个函数获得正确的值(自己推测的,还没有深究)。

/**
* 最简单的基于libVLC的播放器
* Simplest libVLC Player
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序是一个最简单的基于libVLC的视频播放器。
* 适合初学者学习libVLC。
*
* This example is the simplest Video Player based on libVLC.
* Suitable for the beginner of libVLC.
*/
#include <Windows.h>
#include "vlc/vlc.h" int main(int argc, char* argv[])
{
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m; libvlc_time_t length;
int width;
int height;
int wait_time=; //libvlc_time_t length; /* Load the VLC engine */
inst = libvlc_new (, NULL); //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, "cuc_ieschool.flv"); /* Create a media player playing environement */
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);
width = libvlc_video_get_width(mp);
height = libvlc_video_get_height(mp);
printf("Stream Duration: %ds\n",length/);
printf("Resolution: %d x %d\n",width,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的推流器
* Simplest libVLC Streamer
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序是一个最简单的基于libVLC的推流器。
* 适合初学者学习libVLC。
*
* This example is the simplest Streamer based on libVLC.
* Suitable for the beginner of libVLC.
*/ #include <Windows.h>
#include "vlc/vlc.h" int main(int argc, char **argv) {
libvlc_instance_t *vlc;
const char *url;
//Send File
//Transcode it. Video codec use x264. Audio codec use mpga.
//Mux it to mpegts format.
//And stream it to udp://233.233.233.233:6666
/*
const char *sout = "#transcode{vcodec=h264,fps=25,venc=x264{preset=ultrafast,"\
"profile=main,tune=zerolatency},vb=512,scale=0.5," \
"acodec=mpa,aenc=ffmpeg,ab=64,channels=2}" \
":standard{access=udp,mux=ts,dst=233.233.233.233:6666}";
*/
//Send and playing at same time
const char *sout = "#transcode{vcodec=h264,fps=25,venc=x264{preset=ultrafast,"\
"profile=baseline,tune=zerolatency},vb=512," \
"acodec=mpga,ab=64,channels=2}" \
":duplicate{dst=display,dst=standard{access=udp,mux=ts,dst=233.233.233.233:6666}}";
const char *media_name = "Lei's test"; //Screen Capture
//url = "screen://"; url = "cuc_ieschool.flv"; vlc = libvlc_new(, NULL);
libvlc_vlm_add_broadcast(vlc, media_name, url, sout, , NULL, true, false);
libvlc_vlm_play_media(vlc, media_name); //play 30s
_sleep(); libvlc_vlm_stop_media(vlc, media_name);
libvlc_vlm_release(vlc);
return ;
}

播放内存中的流(转) --- 未测试

// Local file/media source.
std::string IMEM_SOURCE_FOLDER = "settings/rvideo/samples/bigdog"; class MyImemData
{
public:
MyImemData() : mFrame(), mDts(), mPts() {}
~MyImemData() {}
std::vector<cv::Mat> mImages;
std::size_t mFrame;
int64_t mDts;
int64_t mPts;
}; /**
\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=<memory_address>"
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=<memory_address>" 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=<your_string>"
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=<four_letter>," 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)
{
MyImemData* imem = (MyImemData*)data; if(imem == NULL)
return ;
// Loop...
if(imem->mFrame >= imem->mImages.size())
{
imem->mFrame = ;
}
// Changing this value will impact the playback
// rate on the receiving end (if they use the dts and pts values).
int64_t uS = ; // 30 fps cv::Mat img = imem->mImages[imem->mFrame++];
*bufferSize = img.rows*img.cols*img.channels();
*buffer = img.data;
*dts = *pts = imem->mDts = imem->mPts = imem->mPts + uS; return ;
} /**
\brief Callback method triggered by VLC to release memory allocated
during the GET callback. To set this callback, use the "--imem-release=<memory_address>"
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=<memory_address>" 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=<your_string>"
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 ;
} /**
\brief Method to load a series of images to use as raw image data
for the network stream. \param[in] sourceFolder Path to folder containing jpeg or png images.
*/
std::vector<cv::Mat> GetRawImageData(const std::string& sourceFolder)
{
namespace fs = boost::filesystem;
std::vector<cv::Mat> result;
std::vector<std::string> filenames;
if( fs::exists(sourceFolder) && fs::is_directory(sourceFolder) )
{
for(fs::directory_iterator dir(sourceFolder);
dir != fs::directory_iterator();
dir++)
{
std::string ext = dir->path().extension().string();
if( fs::is_regular_file( dir->status() ) &&
(dir->path().extension() == ".jpeg" ||
dir->path().extension() == ".png") )
{
filenames.push_back(dir->path().string());
}
}
} if(filenames.size() > )
{
// Sort from 0 to N
std::sort(filenames.begin(), filenames.end());
std::vector<std::string>::iterator filename;
for(filename = filenames.begin();
filename != filenames.end();
filename++)
{
cv::Mat img = cv::imread(*filename);
result.push_back(img);
}
}
return result;
} int main(int argc, char* argv[])
{ // Load images first since we need to know
// the size of the image data for IMEM
MyImemData data;
data.mImages =
GetRawImageData(IMEM_SOURCE_FOLDER); if(data.mImages.size() == )
{
std::cout << "No images found to render/stream.";
return ;
} int w, h, channels;
w = data.mImages.front().cols;
h = data.mImages.front().rows;
channels = data.mImages.front().channels(); // You must create an instance of the VLC Library
libvlc_instance_t * vlc;
// You need a player to play media
libvlc_media_player_t *mediaPlayer;
// Media object to play.
libvlc_media_t *media; // Configure options for this instance of VLC (global settings).
// See VLC command line documentation for options.
std::vector<const char*> options;
std::vector<const char*>::iterator option;
options.push_back("--no-video-title-show"); char imemDataArg[];
sprintf(imemDataArg, "--imem-data=%#p", &data);
options.push_back(imemDataArg); char imemGetArg[];
sprintf(imemGetArg, "--imem-get=%#p", MyImemGetCallback);
options.push_back(imemGetArg); char imemReleaseArg[];
sprintf(imemReleaseArg, "--imem-release=%#p", MyImemReleaseCallback);
options.push_back(imemReleaseArg); options.push_back("--imem-cookie=\"IMEM\"");
// Codec of data in memory for IMEM, raw 3 channel RGB images is RV24
options.push_back("--imem-codec=RV24");
// Video data.
options.push_back("--imem-cat=2"); // If using RAW image data, like RGB24, then you
// must specify the width, height, and number of channels
// to IMEM. Other codes may have that information within
// the data buffer, but RAW will not.
char imemWidthArg[];
sprintf(imemWidthArg, "--imem-width=%d", w);
options.push_back(imemWidthArg); char imemHeightArg[];
sprintf(imemHeightArg, "--imem-height=%d", h);
options.push_back(imemHeightArg); char imemChannelsArg[];
sprintf(imemChannelsArg, "--imem-channels=%d", channels);
options.push_back(imemChannelsArg); //options.push_back("--verbose=2"); // Load the VLC engine
vlc = libvlc_new (int(options.size()), options.data()); // Create a media item from file
media = libvlc_media_new_location (vlc, "imem://"); // Configure any transcoding or streaming
// options for the media source.
options.clear(); // Stream as MPEG2 via RTSP
//options.push_back(":sout=#transcode{venc=ffmpeg{keyint=1,min-keyint=1,tune=zerolatency,bframes=0,vbv-bufsize=1200}, vcodec=mp2v,vb=800}:rtp{sdp=rtsp://:1234/BigDog}"); // Stream as MJPEG (Motion JPEG) to http destination. MJPEG encoder
// does not currently support RTSP
//options.push_back(":sout=#transcode{vcodec=MJPG,vb=800,scale=1,acodec=none}:duplicate{dst=std{access=http,mux=mpjpeg,noaudio,dst=:1234/BigDog.mjpg}"); // Convert to H264 and stream via RTSP
options.push_back(":sout=#transcode{vcodec=h264,venc=x264,vb=0,vbv-bufsize=1200,bframes=0,scale=0,acodec=none}:rtp{sdp=rtsp://:1234/BigDog}"); // Set media options
for(option = options.begin(); option != options.end(); option++)
{
libvlc_media_add_option(media, *option);
} // Create a media player playing environment
mediaPlayer = libvlc_media_player_new_from_media (media); // No need to keep the media now
libvlc_media_release (media); // play the media_player
libvlc_media_player_play (mediaPlayer); boost::this_thread::sleep(boost::posix_time::milliseconds()); // Stop playing
libvlc_media_player_stop (mediaPlayer); // Free the media_player
libvlc_media_player_release (mediaPlayer);
// Free vlc
libvlc_release (vlc); return ;
}

wiki

1.https://wiki.videolan.org/Hacker_Guide/  总纲

2.https://wiki.videolan.org/Documentation:Hacker%27s_Guide/Core/#VLC_Pipeline_and_Modularity   基本概念  模块  PIPELINE

VLC 资料整理的更多相关文章

  1. iOS 开发学习资料整理(持续更新)

      “如果说我看得比别人远些,那是因为我站在巨人们的肩膀上.” ---牛顿   iOS及Mac开源项目和学习资料[超级全面] http://www.kancloud.cn/digest/ios-mac ...

  2. zz 圣诞丨太阁所有的免费算法视频资料整理

    首发于 太阁实验室 关注专栏   写文章     圣诞丨太阁所有的免费算法视频资料整理 Ray Cao· 12 小时前 感谢大家一年以来对太阁实验室的支持,我们特地整理了在过去一年中我们所有的原创算法 ...

  3. iOS 学习资料整理

    iOS学习资料整理 https://github.com/NunchakusHuang/trip-to-iOS 很好的个人博客 http://www.cnblogs.com/ygm900/ 开发笔记 ...

  4. H.264的一些资料整理

    本文转载自 http://blog.csdn.net/ljzcom/article/details/7258978, 如有需要,请移步查看. Technorati 标签: H.264 资料整理 --- ...

  5. 转:基于IOS上MDM技术相关资料整理及汇总

    一.MDM相关知识: MDM (Mobile Device Management ),即移动设备管理.在21世纪的今天,数据是企业宝贵的资产,安全问题更是重中之重,在移动互联网时代,员工个人的设备接入 ...

  6. 3分钟带你了解PowerShell发展历程——PowerShell各版本资料整理

    本文带你了解PowerShell发展历程,顺便整理了一点资料,方便大家查询. Windows PowerShell® 是基于任务的命令行管理程序和脚本语言,专为进行系统管理而设计. 在 .NET Fr ...

  7. (转载)2016 CCF大数据与计算智能大赛 开源资料整理

    本文转载自:http://blog.sina.com.cn/s/blog_5399b8660102wxks.html 2016 CCF 大数据与计算智能大赛已经落下帷幕,11个赛题由众多大神包揽奖项, ...

  8. Java 学习资料整理

    Java 学习资料整理 Java 精品学习视频教程下载汇总 Java视频教程 孙鑫Java无难事 (全12CD) Java视频教程 即学即会java 上海交大 Java初级编程基础 共25讲下载 av ...

  9. Niagara帮助文档资料整理

    1.任何软件额发布都会有说明文档,有的不会附具体实践的操作步骤,存在不懂得问题一般可以通过查看榜文文档解决问题 一些软件的帮助文档是一PDF格式存储在软件安装的目录下面,如Niagar workben ...

随机推荐

  1. Elastic学习第一天遇到的问题以及添加的一些操作

    1.刚开始安装好了之后,启动之后, 报错: ERROR: max file descriptors [] ] 需要设置max file descriptors为65536,出现这个是因为普通的用户是1 ...

  2. Cobar + MySQL 技术验证(li)

    一.简介 Cobar是一个对数据进行拆分后进行分布式存储的产品,可以支持使用后台的 MySQL或者Oracle数据库,通过配置,将数据按照一定规则存储入不同的数据库中.即用分布式数据库代替了集中式数据 ...

  3. JS高程4.变量,作用域和内存问题(3)垃圾收集

    JavaScript的自动垃圾收集机制 执行环境会负责管理代码执行过程中使用的内存,编写JavaScript程序时,所需内存的分配以及无用内存的回收完全实现自动管理. 原理: 找出那些不再继续使用的变 ...

  4. Linux命令-文件文本操作grep

    文件文本操作 grep 在文件中查找符合正则表达式条件的文本行 cut 截取文件中的特定字段 paste 附加字段 tr 字符转换或压缩 sort 调整文本行的顺序,使其符合特定准则 uniq 找出重 ...

  5. ABAP游标的使用

    在Oracle,SQLServer中游标的使用是经常的,所以在ABAP不懂是不行的......     1.声明游标 OPEN CURSOR [WITH HOLD] <c> FOR SEL ...

  6. 阶段一:通过网络请求,获得并解析JSON数据(天气应用)

    “阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 在上一篇阶段一:解析JSON中提到,最近在写一个很简单的天气预报应用.即使功能很简单,但我还是想把它做成一个相对完 ...

  7. 【代码笔记】iOS-自定义导航条颜色

    一,效果图. 二,工程图. 三,代码. AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchin ...

  8. iOS项目分析及优化

    iOS项目分析及优化  来源:吴白的简书   从代码看一个程序员的笔力 从代码的整洁度上就可以看出一个程序员的实力,规范其实就是让你养成一种良好习惯的标杆,在此面前我们应该顺从.本篇我们以OC为例,统 ...

  9. 软件工程随笔(1)--jetbrain在软件工程中的应用

    接下来几天我要写半年的软件工程学习后的感想,今天从介绍IDE开始.首先,本人至今为止全部项目都是在mypclise上完成的.本人采用myeclipse唯一的原因就是它使用方便.但是,我也承认myecl ...

  10. [Modern OpenGL系列(二)]创建OpenGL窗口

    本文已同步发表在CSDN:http://blog.csdn.net/wenxin2011/article/details/51295663 在博主的上一篇文章中已经介绍了OpenGL开发环境的搭建,本 ...