libvlc3.0.x增加录像功能

最近做一个项目,需要播放流媒体。网上参考了很多,最终选了vlc。开发到一半,发现libvlc库没有录像接口,在网上搜了很多资料,总结如下:

具体方法如下:

一、修改源代码

1、修改vlc-3.0.4/lib目录下的video.c文件中新增接口libvlc_video_toggle_record( libvlc_media_player_t *p_mi, const char *psz_filepath,  const char *psz_filename );建议放在libvlc_video_take_snapshot()这个函数后面

int libvlc_video_toggle_record( libvlc_media_player_t *p_mi,
								const char *psz_filepath, 
								const char *psz_filename )
{
	assert( psz_filepath );
	assert( psz_filename );

	input_thread_t *p_input = libvlc_get_input_thread( p_mi );
	if(p_input == NULL)
		return -1;	
	var_Create( p_input, "input-record-path", VLC_VAR_STRING );
	var_SetString( p_input, "input-record-path", psz_filepath );	
	var_Create( p_input, "record-video-name", VLC_VAR_STRING );
	var_SetString( p_input, "record-video-name", psz_filename );
	var_ToggleBool( p_input, "record");
	vlc_object_release(p_input);
	return 0;
}

然后,在vlc-3.0.4/vlc/libvlc_media_player.h中添加LIBVLC_API int libvlc_video_toggle_record( libvlc_media_player_t *p_mi, const char *psz_filepath,  const char *psz_filename );

最后,在vlc-3.0.4/lib/libvlc.sym文件中添加libvlc_video_toggle_record。建议放在libvlc_video_take_snapshot之后。这一步不能少,否则在libvlc.dll没有这个函数接口

2、第一,需要修改vlc-3.0.4/modules/stream_filter/record.c文件中Start().在start()中,

把psz_file = input_CreateFilename( s->p_input, psz_path, INPUT_RECORD_PREFIX, psz_extension );

替换为

char *psz_recordVideoFileName = var_CreateGetNonEmptyString( s->p_input, "record-video-name" );
psz_file = input_CreateFilename( s->p_input, psz_path, psz_recordVideoFileName, psz_extension );

------------------------------------------------------

第二,修改vlc-3.0.4/input/es_out.c中EsOutSetRecord()函数,把

char *psz_file = input_CreateFilename( p_input, psz_path, INPUT_RECORD_PREFIX, NULL );

替换为

 char *psz_recordVideoFileName = var_CreateGetNonEmptyString( p_input, "record-video-name" );
 char *psz_file = input_CreateFilename( p_input, psz_path, psz_recordVideoFileName, NULL );

若想任意设置录像文件的名称,这一步必须做。若用libvlc默认录像文件名称,这一步可省略。

二、编译源代码:

基于已经编译过的环境(偶的编译环境:win10,虚拟机下安装ubutnu 16.04LTS,编译win32 libvlc),切换到vlc-3.0.4/win32目录下,

执行sudo make,

然后打包生成windows相关文件的操作:make package-win-common

在win32下面生成vlc-3.0.4文件夹,然后

cd vlc-3.0.4
find  .  -name  "*.dll"  -type  f  |  xargs  -i  strip  --strip-all  {} 去掉调试信息

win32/vlc-3.0.4文件夹即是我们需要的内容

写在最后:

关于libvlc3.0.4源码编译步骤,传送门:https://blog.csdn.net/zhuquanfu/article/details/83505531   

非常感谢@凭栏望月的【vlc3.0.4在ubuntu16.04x64上的交叉编译全过程记录】这边文章,在libvlc源码编译路上畅通无阻

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值