@rg070836rg
2017-02-12T09:55:36.000000Z
字数 6230
阅读 1794
未分类
sudo apt-get update目的是为了 保持ubuntu的依赖正确
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-devsudo apt-get install gcc make automake bzip2 unzip patch subversion libjpeg62-dev
cd ~mkdir workingwget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gztar zxvf yasm-1.2.0.tar.gzcd yasm-1.2.0./configuremake && make installcd ~/working如果遇到权限不够 切换root chmod 777 加权限保证下面的安装都在 working目录下
apt-get remove ffmpeg x264
wget -c http://www2.mplayerhq.hu/MPlayer/releases/codecs/essential-amd64-20071007.tar.bz2tar xvjf essential-amd64-20071007.tar.bz2mkdir /usr/local/lib/codecscp -Rvp essential-amd64-20071007/* /usr/local/lib/codecs/编辑下面文件vim /etc/ld.so.conf添加以下两行到上面的文件里/usr/lib/usr/local/lib
sudo apt-get install make automake g++ bzip2 python unzip patch subversion ruby build-essential git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvdpau-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
sudo git clone git://git.videolan.org/x264.gitcd x264sudo ./configure --enable-shared --prefix=/usr/localsudo makesudo make installcd ~/working
cd ~/working下载 libvpx-1.4.0,http://download.csdn.net/download/lsc1818/8929949tar xvjf libvpx-1.4.0.tar.bz2cd libvpx-1.4.0sudo ./configure --enable-shared --prefix=/usr/localmake && make installcd ~/working
cd ~/workingwget http://ffmpeg.org/releases/ffmpeg-2.7.2.tar.bz2tar xvjf ffmpeg-2.7.2.tar.bz2cd ffmpeg-2.7.2./configure --enable-gpl --enable-version3 --enable-shared --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/libmake && make installcd ~/working让动态链接库被系统共享ldconfig
apt-get install libmp3lame-devsvn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayercd mplayer/./configuremake && make install
sudo apt-get install rubygem install flvtool2
sudo apt-get install mencoder查看所有所支持的音频编码mencoder -oac help查看所有所支持的视频编码mencoder -ovc help
先安装各种依赖(nginx需要pcre支持,yamdi用来为flv创建关键帧才能随意拖动)
sudo apt-get install gcc g++ libssl-dev zlib1g-dev libpcre3-dev yamdi
下载所需的nginx模块
第一个是nginx_mod_h264_streaming,让nginx支持flv/mp4流播放
wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gztar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz注意:先要修改一下源码,注释掉nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c的158到161行sudo gedit nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c/* TODO: Win32 *///if (r->zero_in_uri)// {// return NGX_DECLINED;// }第二个是nginx-rtmp-module,让nginx支持rtmp/hls协议wget -O nginx-rtmp-module.zip https://github.com/arut/nginx-rtmp-module/archive/master.zipunzip nginx-rtmp-module.zip下载清缓存的模块wget -O ngx_cache_purge.zip https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zipunzip ngx_cache_purge.zip下载安装nginx:wget http://nginx.org/download/nginx-1.8.0.tar.gztar zxvf nginx-1.8.0.tar.gzcd nginx-1.8.0./configure --user=daemon --group=daemon --prefix=/usr/local/nginx/ --add-module=../nginx-rtmp-module-master --add-module=../ngx_cache_purge-master --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_flv_modulemake && make install
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginxsudo chmod +x /etc/init.d/nginxsudo update-rc.d nginx defaultssudo service nginx start//开启sudo service nginx stop //停止,列出开启后,浏览localhost
编辑/usr/local/nginx/conf/nginx.conf文件
sudo gedit /usr/local/nginx/conf/nginx.conf#user nobody;worker_processes 1;error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid logs/nginx.pid;events {use epoll;worker_connections 1024;}rtmp {server {listen 1935;chunk_size 4000;# video on demandapplication vod {play /mnt/media/vod;}# HLS# HLS requires libavformat & should be configured as a separate# NGINX module in addition to nginx-rtmp-module:# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …# For HLS to work please create a directory in tmpfs (/tmp/app here)# for the fragments. The directory contents is served via HTTP (see# http{} section in config)## Incoming stream must be in H264/AAC/MP3. For iPhones use baseline H264# profile (see ffmpeg example).# This example creates RTMP stream from movie ready for HLS:## ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1# -f flv rtmp://localhost:1935/hls/movie## If you need to transcode live stream use ‘exec’ feature.#application hls {hls on;hls_path /mnt/media/app;hls_fragment 10s;}}}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;gzip on;#log formatlog_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘‘$status $body_bytes_sent “$http_referer” ‘‘”$http_user_agent” $http_x_forwarded_for’;#定义一个名为addr的limit_zone,大小10M内存来存储sessionlimit_conn_zone $binary_remote_addr zone=addr:10m;server {listen 8080;server_name localhost;# HTTP can be used for accessing RTMP stats# This URL provides RTMP statistics in XMLlocation /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /mnt/soft/nginx-rtmp-module-master;}location /control {rtmp_control all;}location / {root /mnt/soft/nginx-rtmp-module-master/test/rtmp-publisher;}}server {listen 80;server_name localhost;location / {root /mnt/wwwroot;index index.html;}location ~ \.flv$ {root /mnt/media/vod;flv;limit_conn addr 20;limit_rate 200k;}location ~ \.mp4$ {root /mnt/media/video;mp4;limit_conn addr 20;limit_rate 200k;}location /hls {# Serve HLS fragmentsalias /mnt/media/app;}access_log logs/nginxflv_access.log access;}}注意 如果启动不了,是文件权限错误。手动建立文件夹/mnt/media/video -> 存放原始视频/mnt/media/vod -> 存放转换后的flv和mp4视频,供http或rtmp访问
git clone https://github.com/johnf/m3u8-segmenter.git直接找到m3u8-segmenter.c 所在目录cd m3u8-segmenter/gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil拷贝至软件目录cp segmenter /usr/bin/切片势力 原文件为 vp5.flv 转换为vp5.tsffmpeg -i vp5.flv -acodec copy -vcodec libx264 vp5.tssegmenter 转换为m3u8 :segmenter -i vp5.ts -d 10 -p onedemo -m vp5.m3u8 -u http://localhost/videox/-p one demo 是分片的名字-u 是访问的链接 比如现在的网站ip是 192.168.2.107 那么填写 http://192.168.2.107/video/最后把ts文件与M3U8文件拷贝到网站对应的目录下 即可
未解决问题:
1 网页播放m3u8,原计划使用ckplayer 但是一直有错,没有成功
2 据观察,m3u8同样能够下载?