添加VLC录像API
2015-08-16 18:32
447 查看
转自 : http://m.blog.csdn.net/blog/shulianghe/19200753
最近使用VLC播放RTSP数据想在本地截图录像,但libvlc中并不包含录像api,网上找到一些资料,自己添加这个接口并测试成功。接口主要是按照官方网站来做的(https://patches.videolan.org/patch/606/)。我是用的源码是最新的,编译过程中很顺利,前提是安装好各种依赖包。测试代码如下:#include <vlc/vlc.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
static const char * test_defaults_args[] = {
"-v",
"--ignore-config",
"-I",
"dummy",
"--no-media-library"
};
static const int test_defaults_nargs =
sizeof (test_defaults_args) / sizeof (test_defaults_args[0]);
int main (void)
{
libvlc_instance_t *instance;
libvlc_media_t *media;
libvlc_media_player_t *player;
const char * file = "rtsp://192.168.1.68";
//instance = libvlc_new (test_defaults_nargs, test_defaults_args);
instance = libvlc_new (0, NULL);
assert (instance != NULL);
//打开文件
//media = libvlc_media_new_path (instance, file);
//打开串流
media = libvlc_media_new_location (instance, file);
assert (media != NULL);
player = libvlc_media_player_new_from_media (media);
assert (player != NULL);
libvlc_media_release (media);
libvlc_media_player_play (player);
printf("play\n");
libvlc_media_player_record_start(player, "testfile");
printf("record\n");
sleep(10*10);
libvlc_video_take_snapshot(player,0,"test.jpg",0,0);
printf("%d\n", libvlc_media_player_get_state(player));
printf("stop record\n");
libvlc_media_player_record_stop(player);
printf("stop play\n");
//libvlc_media_player_stop (player);
printf("player release\n");
libvlc_media_player_release (player);
printf("release\n");
libvlc_release (instance);
return 0;
}
很惊讶选项里面竟然没有C...。
编译:gcc test.c -o test -lvlc
运行之后截图录像均正常。这里libvlc_media_player_stop()注销是因为有些情况下这个函数会造成死锁,这个涉及到线程安全的一些问题,以后再研究。
最近使用VLC播放RTSP数据想在本地截图录像,但libvlc中并不包含录像api,网上找到一些资料,自己添加这个接口并测试成功。接口主要是按照官方网站来做的(https://patches.videolan.org/patch/606/)。我是用的源码是最新的,编译过程中很顺利,前提是安装好各种依赖包。测试代码如下:#include <vlc/vlc.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
static const char * test_defaults_args[] = {
"-v",
"--ignore-config",
"-I",
"dummy",
"--no-media-library"
};
static const int test_defaults_nargs =
sizeof (test_defaults_args) / sizeof (test_defaults_args[0]);
int main (void)
{
libvlc_instance_t *instance;
libvlc_media_t *media;
libvlc_media_player_t *player;
const char * file = "rtsp://192.168.1.68";
//instance = libvlc_new (test_defaults_nargs, test_defaults_args);
instance = libvlc_new (0, NULL);
assert (instance != NULL);
//打开文件
//media = libvlc_media_new_path (instance, file);
//打开串流
media = libvlc_media_new_location (instance, file);
assert (media != NULL);
player = libvlc_media_player_new_from_media (media);
assert (player != NULL);
libvlc_media_release (media);
libvlc_media_player_play (player);
printf("play\n");
libvlc_media_player_record_start(player, "testfile");
printf("record\n");
sleep(10*10);
libvlc_video_take_snapshot(player,0,"test.jpg",0,0);
printf("%d\n", libvlc_media_player_get_state(player));
printf("stop record\n");
libvlc_media_player_record_stop(player);
printf("stop play\n");
//libvlc_media_player_stop (player);
printf("player release\n");
libvlc_media_player_release (player);
printf("release\n");
libvlc_release (instance);
return 0;
}
很惊讶选项里面竟然没有C...。
编译:gcc test.c -o test -lvlc
运行之后截图录像均正常。这里libvlc_media_player_stop()注销是因为有些情况下这个函数会造成死锁,这个涉及到线程安全的一些问题,以后再研究。
相关文章推荐
- 车行无忧 v5.0.3 安卓版
- leetcode 146 —— LRU Cache
- 找出字符串中第一个只出现一次的字符
- 递归函数查询菜单列表
- 15岁女生偷偷攒钱买手机出走 4个月了无音讯----现在的孩子太任性
- Struts2中validator校验器不起作用的情况
- hdu2064汉诺塔递推
- 【QC】安装
- ubuntu开启root用户登录方法
- POJ 3414-Pots(BFS)
- python操作MySQL
- mybatis if test 相等的情况如何动态拼接sql
- 利用mybatis-generator自动生成代码
- Spiral Matrix II
- Contest 7 1007 Gray code【DP/贪心】
- 明天去云台山....
- 如何手动解析CrashLog
- 不可变字符串 NSString 的基础使用方法
- HDU-5339 Untitled
- linux命令之pstack