添加VLC录像API

最近使用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()注销是因为有些情况下这个函数会造成死锁,这个涉及到线程安全的一些问题,以后再研究。

转载于:https://www.cnblogs.com/shulianghe/p/3724127.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
//创建初始化播放器资源 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] extern public static IntPtr libvlc_new(int argc, IntPtr argv); //创建播放器实例 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_player_new(IntPtr libvlc_instance); // 释放libvlc实例 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern void libvlc_release(IntPtr libvlc_instance); //获取库版本信息 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern String libvlc_get_version(); // 从视频来源(例如Url)构建一个libvlc_meida RTSP [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_new_location(IntPtr libvlc_instance, IntPtr path); // 从本地文件路径构建一个libvlc_media rtsp串流不适合调用此接口 // [MarshalAs(UnmanagedType.LPStr)] string path [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_new_path(IntPtr libvlc_instance, IntPtr path); /// /// 影片长度 /// /// /// [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_player_get_length(IntPtr libvlc_media_player); //释放对象 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern void libvlc_media_release(IntPtr libvlc_media_inst); // 将视频(libvlc_media)绑定到播放器上 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern void libvlc_media_player_set_media(IntPtr libvlc_media_player, IntPtr libvlc_media); //创建(libvlc_media)播放窗口 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] publ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值