实现使用libVLC录像功能

本文介绍如何通过修改VLC源代码来为libVLC添加录像功能。主要步骤包括添加录像函数声明、实现在video.c中的录像逻辑及重新编译VLC。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        分类:            vlc 235人阅读 评论(0) 收藏 举报

VLC的强大功能我就不赘述了,相信看到这篇文章的朋友都已经有所了解了,如果还不太清楚,可以访问http://www.videolan.org/vlc/features.html.         首先大家需要下载一份VLC的源码,地址http://www.videolan.org/vlc/download-sources.html 编译方法上面也有阐述,不过根据我的经验,希望大家不要去尝试在windows上去编译VLC,而是在buntu/fedora或是其他的linux操作系统上使用cross_compile去编译各个平台上的VLC.这个方法也是VLC官网上推荐的方法.

         进入正题,如何使libVLC支持录像功能(VLC本身带有录像功能,但是我也不知道为什么vlc官方确没有在libVLC中加入这一功能,出于保守?)

          1.添加申明函数:找到include\vlc\libvlc_media_player.h文件,搜索libvlc_video_take_snapshot(实现截图功能的)这个函数,之所以我提到这个函数,是因为实现录像功能的函数与这个函数非常相像,如果想添加另外的功能,也可以参照VLC已有的功能函数去实现.找到libvlc_video_take_snapshot后,在其后面添加名为VLC_PUBLIC_API int libvlc_video_toggle_record( libvlc_media_player_t *p_mi,const char *psz_filepath, const char *psz_fileame );的录像函数,我的录像函数的思想是这样的:调用一次时开始录像,再调用一次时停止录像.所以名为toggle.这样申明函数就添加好了.

          2.添加实现函数:找到src\control\video.c ,然后添加函数实现如下:

  1. int libvlc_video_toggle_record( libvlc_media_player_t *p_mi, 
  2.                                constchar *psz_filepath,constchar *psz_filename ) 
  3.     input_thread_t *p_input = libvlc_get_input_thread( p_mi ); 
  4.     if(p_input == NULL) 
  5.        return -1;   
  6.     var_CreateGetString(p_input, "input-record-path");
       var_SetString( p_input, "input-record-path", psz_filepath );
       var_CreateGetString(p_input, "sout-record-dst-prefix");
       var_SetString( p_input, "sout-record-dst-prefix", psz_fileame );
       var_ToggleBool( p_input, "record");
  7.     vlc_object_release(p_input); 
  8.     return 0; 

  3.修改好上述文件后,重新编译VLC,这样libvlc.dll中就有了录像函数了.

          vlc好坏!

 

转载:http://blog.youkuaiyun.com/maikforever/article/details/7354756

//创建初始化播放器资源 [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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值