基于libVLC的参数设置可视化视频播放器

使用libVLC开发的一个简单的图形界面的视频播放器。

程序主要运行代码如下:

void CplayerGUIDlg::OnBnClickedStart()
{
	CStringW cstr_url;

#ifdef _UNICODE
	m_url.GetWindowText(cstr_url);
#else
	USES_CONVERSION;
	CStringA cstr_urla;
	m_url.GetWindowText(cstr_urla);
	cstr_url.Format(L"%s",A2W(cstr_urla));
#endif

	std::string str_url;
	UNICODE_to_UTF8(cstr_url, str_url);
	const char *char_url=str_url.c_str();

	if(strcmp(char_url,"")==0){
		AfxMessageBox(_T("Input URL is NULL!"));
		return;
	}
	
	HWND screen_hwnd=NULL;
	screen_hwnd = this->GetDlgItem(IDC_SCREEN)->m_hWnd; 

	if(playerstate!=STATE_PREPARE){
		AfxMessageBox(_T("Media is playing now."));
		return;
	}


     /* Create a new item */
     //m = libvlc_media_new_location (libvlc_inst, "http://mycool.movie.com/test.mov");

     libvlc_m = libvlc_media_new_path (libvlc_inst, char_url);

     /* Create a media player playing environement */

	 libvlc_media_add_option(libvlc_m, "--avcodec-threads=124");
	 libvlc_media_add_option(libvlc_m, "--network-caching=500");
	 libvlc_media_add_option(libvlc_m, "--rtsp-frame-buffer-size=1000000");
	 libvlc_media_add_option(libvlc_m, "--rtsp-tcp");
	 libvlc_media_add_option(libvlc_m, "--advanced");
     libvlc_mp = libvlc_media_player_new_from_media (libvlc_m);
     
     /* No need to keep the media now */
     libvlc_media_release (libvlc_m);

    //on windows
     libvlc_media_player_set_hwnd (libvlc_mp,screen_hwnd);
 
     /* play the media_player */
     int x=libvlc_media_player_play (libvlc_mp);

	 m_play_duration = libvlc_media_player_get_length(libvlc_mp);

    
    //s _sleep (3000); /* Let it play a bit */
	/* AVOutputFormat *ofmt = NULL;
	 //Input AVFormatContext and Output AVFormatContext
	 AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
	 AVPacket pkt;
	 const char *in_filename, *out_filename;
	 int ret, i;
	 int videoindex = -1;
	 int frame_index = 0;
	 int64_t start_time = 0;
	 in_filename = char_url;
	 if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
		 printf("Could not open input file.");
	 }
	 for (i = 0; i<ifmt_ctx->nb_streams; i++)
		 if (ifmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO){
			 videoindex = i;
			 break;
	 }
	 if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
		 printf("Failed to retrieve input stream information");
	 }
	 av_dump_format(ifmt_ctx, 0, in_filename, 0);
	 AVStream *videoStream = ifmt_ctx->streams[videoindex];

	 m_play_duration = (int64_t)(videoStream->duration / AV_TIME_BASE)*-1;
	 //secs = duration / AV_TIME_BASE;
	// us = duration % AV_TIME_BASE;
	 avformat_close_input(&ifmt_ctx);
	 */
	playerstate=STATE_PLAY;
	SetBtn(STATE_PLAY);
	SetTimer(1,1000,NULL);
}

运行界面如下:


下面简要列出vlc参数用法

下面列出的参数可以在命令行中执行,也可以在VLC界面中填写。当然,更重要的是能在 
程序中调用。 
程序中调用的时候要注意,什么是全局参数,什么是会话参数。例如: 
RTP over TCP的选项,必须用冒号。用双减号则没有效果。 
正确写法:libvlc_media_add_option(m_media, “:rtsp-tcp”); 
错误写法:libvlc_media_add_option(m_media, “–rtsp-tcp”);

Usage: vlc [options] [stream] … 
You can specify multiple streams on the commandline. They will be enqueued in the playlist. 
The first item specified will be played first. 
Options-styles: 
–option A global option that is set for the duration of the program. 
-option A single letter version of a global –option. 
:option An option that only applies to the stream directly before it 
and that overrides previous settings. 
Stream MRL syntax: 
[[access][/demux]://]URL[@[title][:chapter][-[title][:chapter]]] [:option=value …] 
Many of the global –options can also be used as MRL specific :options. 
Multiple :option=value pairs can be specified. 
URL syntax: 
[file://]filename Plain media file 
http://ip:port/file HTTP URL 
ftp://ip:port/file FTP URL 
mms://ip:port/file MMS URL 
screen:// Screen capture 
[dvd://][device][@raw_device] DVD device 
[vcd://][device] VCD device 
[cdda://][device] Audio CD device 
udp://[[]@[][:]] 
UDP stream sent by a streaming server 
vlc://pause: Special item to pause the playlist for a certain time 
vlc://quit Special item to quit VLC 
未找到匹配的模块。使用 –list 或 –list-verbose 来列出可用模块。 
VBI 和 Teletext 解码器 
–vbi-page=<整数> Teletext 页 
打开可能的 Teletext 页。默认的页是索引 100 
–vbi-opaque, –no-vbi-opaque 
文本总是不透明 (默认开启) 
设置 vbi 不透明为否使得边框话的文本透明。 
(默认开启) 
–vbi-position={0 (居中), 1 (左), 2 (右), 4 (上), 8 (下), 5 (左上), 6 (右上), 9 (左下), 10 (右下)} 
Teletext 排列 
您可以强制指定 teletext 在视频上的位置 (0=居中、1=左 
、2=右、4=上、8=下,您也可以混合使用这些值,例如 
6 = 右上)。 
–vbi-text, –no-vbi-text Teletext 文本字幕 (默认关闭) 
将 teletext 字幕作为文本输出代替 RGBA (默认关闭) 
YUV 视频输出 
–yuv-file=<字串> 设备,先进先出队列或文件名 
写入 YUV 帧的目的设备、FIFO 队列或文件名。 
–yuv-chroma=<字串> 使用了色度 
强制为输出使用指定的色度。默认是 I420。 
–yuv-yuv4mpeg2, –no-yuv-yuv4mpeg2 
YUV4MPEG2 头部 (默认关闭) (默认关闭) 
mplayer yuv 视频输出兼容 YUV4MPEG2 头,要求 fourcc 为 
YV12/I420。vlc 默认将帧的 fourcc 写入输出处。 
(默认关闭) 
H.264/MPEG4 AVC 编码器 (x264) 
–sout-x264-keyint=<整数> 
最大 GOP 大小 
设置 IDR 帧之间的最大间隔。较大的帧将节省大小,巍 
¶改进在给予为率下的搜索精确性质量。 
–sout-x264-min-keyint=<整数> 
最小 GOP 大小 
设置 IDR 帧之间的最小间隔。在 H.264 中 I 帧没有必要勊 »‘定一个封闭的 GOP,因为它允许在它之前预测更多的㋊ ¸§ (也可以查看参考帧选项)。因此 I 帧没有搜索的必褍 
。IDR 帧将从任意参考帧之前限制之后的 P 
帧。 
如果场景出现在此间隔内,它们还是将会被编码 
为 I 帧,但是不启动一个新的 GOP。 
–sout-x264-scenecut=<整数 [-1 .. 100]> 

程序中设置参数的两种方法

1.

const char *vlc_args[] =
	{
		
		"--network-caching=500",
		"--rtsp-frame-buffer-size=1000000",
		"--rtsp-tcp",
		
		"--avcodec-threads=124",
		"--advanced",
	};
	//libvlc_media_add_option()
	libvlc_inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

初始化libvlc_instance_t *对象时传入相应的参数

2

  libvlc_m = libvlc_media_new_path (libvlc_inst, char_url);

     /* Create a media player playing environement */

	 libvlc_media_add_option(libvlc_m, "--avcodec-threads=124");
	 libvlc_media_add_option(libvlc_m, "--network-caching=500");
	 libvlc_media_add_option(libvlc_m, "--rtsp-frame-buffer-size=1000000");
	 libvlc_media_add_option(libvlc_m, "--rtsp-tcp");
	 libvlc_media_add_option(libvlc_m, "--advanced");

程序调用时设置libvlc_media_t *对象 libvlc_m的参数值

工程CDSN下载地址:https://download.csdn.net/download/tigerxuchuanli/10332399

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值