
Mplayer 安装编译过程
PS. 本次安装过程,假定 mplayer 的源码包存放于 /opt/mplayer/ 目录
1 .安装定点 mp3 解码库 libmad
由于 Loongson 1B 没有浮点运算单元,而 mplayer 的 mp3 解码默认使用 mp3 浮点解码库 mp3lib ,故而移植 mplayer 到 1B 上,需要编译一个定点 mp3 解码库 libmad :
首先请确保 1B 的交叉编译工具链已经安装到 PC 上,并将其加入到 PATH 环境变量中:
#export PATH=/home/cpu/gcc-3.4.6-2f/bin:$PATH
接下来进行 libmad 交叉编译过程:
# tar zxvf libmad-0.15-ls1b.tar.gz
# cd libmad-0.15-ls1b
# ./configure --enable-fpm=mips --host=mipsel-linux --disable-shared --disable-debugging --prefix=/opt/mplayer/install/libmad CC="mipsel-linux-gcc"
# make
# make install
执行以上步骤后,即可将 libmad 安装到 /opt/mplayer/install/libmad/
2.安装流媒体支持工具 live555
Live555 实现了对多种音视频编码格式的音视频数据的流化、接收和处理等支持,包括 MPEG 、 H.263+ 、 DV 、 JPEG 视频和多种音频编码 ,同时实现了对标准流媒体传输协议如 RTP/RTCP 、 RTSP 、 SIP 等的支持。
在 Mplayer 中 需要使用 live 选项进行编译,则需要 先安装 live555 库 ,下边是live555 库的安装过程:
# tar zxvf live555-ls1b.tar.gz
# cd live555-ls1b/live/
# cp config.armlinux config.mips
# chmod 777 config.mips
# vi config.mips
将: CROSS_COMPILE?= arm-elf-
修改为: CROSS_COMPILE?= mipsel-linux-
# ./genMakefiles mips
# make
这样就完成了对 live555 的编译,然后将整个工具包拷贝到指定位置:
# cp ../live/ /opt/mplayer/install/ -rf
3 .交叉编译Mplayer
首先确认一下定点 mp3 解码库 libmad 以及流媒体支持工具 live555 的安装路径为:/opt/mplayer/install/
由于需要将这两个插件一起编译到 mplayer 中,所以需要将这两个插件的相关头文件及链接库路径添加到 mplayer 的编译配置文件中,如下步骤:
# tar zxvf mplayer-ls1b-module.tar.gz
# cd mplayer-ls1b-module
# ./config.sh
以上命令为生成默认 mplayer 编译配置文件 config.mak 。
# vi config.mak
对 mplayer 编译配置文件作以下修改:
File : ./ config.mak |
# -------- Generated by configure ----------- LANG = C MAN_LANG = en TARGET_OS = Linux DESTDIR = # 设定 make install 后 mplayer 的安装路径,由于安装到本地目录,所以以下目录设定无关紧要 prefix = $(DESTDIR)/opt/mipsel/mplayer/ BINDIR = $(DESTDIR)/opt/mipsel/mplayer//bin DATADIR = $(DESTDIR)/opt/mipsel/mplayer//share/mplayer MANDIR = $(DESTDIR)/opt/mipsel/mplayer//share/man CONFDIR = $(DESTDIR)/opt/mipsel/mplayer//etc/mplayer LIBDIR = $(DESTDIR)/opt/mipsel/mplayer//lib # FFmpeg uses libdir instead of LIBDIR libdir = $(LIBDIR) AR = ar # 执行 config.sh 后此处可能被修改成为以下编译工具,但是 C++ 需要的编译工具为 g++ ,若不修改正确则编译出错提示很多未定义 #CC = mipsel-linux-gcc #CXX = mipsel-linux-gcc CC = mipsel-linux-gcc CXX = mipsel-linux-g++ HOST_CC = gcc RANLIB = true LDCONFIG = ldconfig INSTALL = install # 设定编译参数:头文件查找路径,设定出错则出现头文件未找到错误 #EXTRA_INC = #EXTRAXX_INC = EXTRA_INC =-I/opt/mplayer/install/libmad/include EXTRAXX_INC = \ -I/opt/mplayer/install/live/liveMedia/include \ -I/opt/mplayer/install/live/groupsock/include \ -I/opt/mplayer/install/live/UsageEnvironment/include \ -I/opt/mplayer/install/live/BasicUsageEnvironment/include OPTFLAGS = -I. -I.. -I../libavutil -Wall -Wno-switch -Wpointer-arith -Wredundant-decls -O4 -pipe -ffast-math -fomit-frame-pointer -D_REENTRANT -DHAVE_CONFIG_H $(EXTRA_INC) CXXFLAGS = -I. -I.. -I../libavutil -Wall -Wno-switch -Wpointer-arith -Wredundant-decls -O4 -pipe -ffast-math -fomit-frame-pointer -D_REENTRANT -DHAVE_CONFIG_H -D__STDC_LIMIT_MACROS $(EXTRAXX_INC) CFLAG_STACKREALIGN = INSTALLSTRIP = -s CHARSET = HELP_FILE = help/help_mp-en.h EXESUF = MPLAYER_NETWORK = yes FTP = yes STREAMING_LIVE555 = yes LIBNEMESI = no NATIVE_RTSP = yes VSTREAM = no STREAM_CACHE = yes DVBIN = no VIDIX = no VIDIX_INTERNAL = no VIDIX_EXTERNAL = no CONFIG_PP = yes MP3LAME = LIBMENU = no MP3LIB = no LIBWMA = yes LIBA52 = no LIBMPEG2 = no TREMOR_INTERNAL = yes TREMOR_LOW = no FAAD = yes SPEEX = no MUSEPACK = no UNRARLIB = no PNG = no JPEG = no GIF = no EXTRALIBS = # 添加链接库文件及其路径,设定出错则在连接库文件时出现许多函数提示未定义 #EXTRA_LIB = -lmad -ldl -lm EXTRA_LIB=\ -L/opt/mplayer/install/libmad/lib \ -L/opt/mplayer/install/live/liveMedia/ \ -L/opt/mplayer/install/live/groupsock/ \ -L/opt/mplayer/install/live/UsageEnvironment/ \ -L/opt/mplayer/install/live/BasicUsageEnvironment/ \ -lmad \ -lliveMedia -lgroupsock \ -lUsageEnvironment -lBasicUsageEnvironment \ -ldl -lm EXTRALIBS_MPLAYER = EXTRALIBS_MENCODER = ... ... |
#make
编译成功后,将会在目录下生成一个 mplayer 的二进制可执行文件,将其拷贝到开发板的文件系统 bin 目录,并将需要的链接库文件拷贝到开发板上文件系统的 lib 目录下就可以运行了。
Mplayer 的使用方法
1. Mplayer 的简单使用
首先看一下 mplayer 的参数格式:
mplayer [ 选项 ] [ 文件 |URL| 播放列表 | − ]
mplayer [ 选项 ] 文件 1 [ 分选项 ] [ 文件 2] [ 分选项 ]
mplayer [ 选项 ] { 文件和选项组 } [ 组专用的分选项 ]
mplayer [dvd|dvdnav]://[ 标题 |[ 开始标题 ] −结束标题 ][/ 设备 ] [ 选项 ]
mplayer vcd:// 曲目 [/ 设备 ]
mplayer tv://[ 频道 ][/ 输入 ID] [ 选项 ]
mplayer radio://[ 频道 | 频率 ][/ 捕捉设备 ] [ 选项 ]
mplayer pvr:// [ 选项 ]
mplayer dvb://[ 卡号 @] 频道 [ 选项 ]
mplayer mf://[ 文件掩码 |@ 列表文件 ] [ − mf 选项 ] [ 选项 ]
mplayer [cdda|cddb]:// 曲目 [ −结束曲目 ][: 速度 ][/ 设备 ] [ 选项 ]
mplayer cue:// 文件 [: 曲目 ] [ 选项 ]
mplayer
[file|mms[t]|http|http_proxy|rt[s]p|ftp|udp|unsv|icyx|noicyx|smb]://
[ 用户名 : 密码 @]URL[: 端口 ] [ 选项 ]
mplayer sdp:// 文件 [ 选项 ]
mplayer mpst:// 主机 [: 端口 ]/URL [ 选项 ]
mplayer tivo:// 主机 /[list|llist|fsid] [ 选项 ]
mplayer最简单的方法就是 mplayer [文件名], 即 mplayer 后边直接传入需要播放的音频或者视频文件。而通过增加一些选项参数,可以设置播放的一些个性化参数,例如声音大小、字幕、循环播放等,这部分的设定,可以在网上很容易查找到资料,或者参考《 MPlayer 用户中文手册 .pdf 》。
2. Mplayer 的 slave 模式
默认 mplayer 是从键盘上获得控制信息 ,通过键盘按键,可以快捷控制 mplayer 的播放参数, mplayer 另外提供了一种更为灵活的控制方式,用来进行播放控制 ——slave 模式
在 slave 模式下, mplayer 为后台运行其他程序,不再截获键盘事件, mplayer 会从标准输入读一个换行符( \n )分隔开的命令。
执行如下命令:
#mplayer -slave -quiet <file>
然后就可以在控制台直接输入 slave 模式命令进行控制 mplayer 的播放。
我们也可以通过一个fifo 文件(命名管道) 进行传递 slave 命令:
#mkfifo </tmp/fifofile>
#mplayer -slave -input file=</tmp/fifofile> <file>
对于 slave 模式的命令这里不作详细说明,可以在《 MPlayer 用户中文手册 .pdf 》中查阅相关部分,也可以参考 mplayer 模块测试例子。
下边主要使用 mplayer 模块测试例子来介绍如何在程序中通过管道传递 slave 模式命令给 mplayer 后台程序:
File : mplayer_test.c |
/* * Copyright (c) 2012 ,广州龙芯中科技术科技有限公司 * All rights reserved. * * 文件名称: mplayer_test.c * 摘要: mplayer 模块测试及使用例子 * */ /* 当前版本: 0.0.1 * 作者: Ethan ,修改日期: 2012 年 06 月 18 日 */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/wait.h> #include <string.h> #include <pthread.h> #include <signal.h> #include "orders.h" #define MAXLEN 1024 #define IPR_FIFO "/tmp/mplayer-cmd" #define IPR_FIFO_PARAM "file=/tmp/mplayer-cmd" #define FILE_PATH "FirstLove.mp3" int fd_pipe[2]; // 管道文件描述符 /********************************************************************************** * Function( 功能 ) :获取 mplayer 后台程序的打印输出信息 * parameter( 参数 ) : * outout (返回值): ***********************************************************************************/ void *get_player_msg() { printf("Get_player_msg:\n"); char data[MAXLEN]; unsigned int datalen; while(1) { memset(data, 0, sizeof(data)); datalen = read(fd_pipe[0], data, sizeof(data)); printf("%s\n", data); } } /********************************************************************************** * Function( 功能 ) :通过管道传递命令给 mplayer * parameter( 参数 ) : cmd-slave 模式命令 * outout (返回值): ***********************************************************************************/ void mplayer_slave_cmd(char *cmd) { printf("Mplayer_slave_cmd:%s\n", cmd); char data[MAXLEN]; strcpy(data, cmd); int datalen = strlen(data); data[datalen++] = '\n'; data[datalen] = 0; int fp = 0; fp = open(IPR_FIFO, O_RDWR); write(fp, data, datalen); close(fp); } /********************************************************************************** * Function( 功能 ) : mplayer 模块测试及使用例子 * parameter( 参数 ) : * outout (返回值): ***********************************************************************************/ int main() { pid_t pid; pthread_t tid_msg; pthread_mutex_t pmutex;
// 建立命名管道 unlink(IPR_FIFO); mkfifo(IPR_FIFO, O_CREAT | 0666); // 建立无名管道用于重定向接收 mplayer 的后台打印信息 if(pipe(fd_pipe) < 0) { perror("pipe error\n"); unlink(IPR_FIFO); exit(0); } pid = fork(); if(pid < 0) { close(fd_pipe[0]); close(fd_pipe[1]); unlink(IPR_FIFO); perror("fork"); exit(0); } if(pid == 0) { // 标准输出重定向至管道 close(fd_pipe[0]); dup2(fd_pipe[1], 1); // 启动 mplayer 程序,为携带文件信息,处于等待命令状态 if(execlp("mplayer","mplayer", "-slave", "-nocache","-novideo", "-input", IPR_FIFO_PARAM, "-idle", "-srate" ,"48000", NULL) == -1) { printf("ERROR:Cannot start mplayer!!\n"); } printf("MPlayer progress exit!!\n"); exit(0); } else { // 创建线程用以接收 mplayer 的打印信息 if(!pthread_create(&tid_msg, NULL, get_player_msg,NULL)) { pthread_detach(tid_msg); } else { printf("ERROR:Cannot create thread get_msg_player\n"); } pthread_mutex_init(&pmutex, NULL); } sleep(5); // 测试 slave 模式 // 首先传入 mp3 文件路径,进行音频播放 char cmd[MAXLEN]; sprintf(cmd,"%s %s", ORDER_PLAY, FILE_PATH); mplayer_slave_cmd(cmd); sleep(10); // 暂停功能 mplayer_slave_cmd(ORDER_PAUSE); pthread_join(tid_msg, NULL); wait(NULL); return 0; } |


相关文章- 如何保留原提交记录迁移Git项目
- php中防止SQL注入的方法
- linux 安装之后无声音解决办法(一般是Realtek的卡,不知道是什么卡请lshw查看)
- 甲骨文ARM机 后续的优化修改(dd 新系统,ssh 修改,docker 安装, 基于docker安装其他插件等等)
- 为什么linux下的程序员都不用IDE (转)
- 2013年统计的部分社工库内容
- git error ------remote: error: refusing to update checked out branch: refs/heads/master
- 攻防之城 乌云首届安全峰会即将召开
- 小智音箱修复wifi链接(此方法适合一代 二代 智能管家等等android设备)
- 光猫G-140W 系列 频繁千兆口频繁掉线/网页不发访问 修复 后续
本文地址:https://blog.sxx1314.com/linux/309.html
版权声明:若无注明,本文皆为“unix 软硬件 技术宅 ”原创,转载请保留文章出处。百度已收录















