首页 关于 归档

直播预研

Table of Contents

nginx rtmp ffmpeg hls安装文档

准备工作

- yum install git  
- 并设置好gcc 如:  
export CC="gcc44"  
export CXX="g++44"

yasm

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz    
tar zxvf yasm-1.3.0.tar.gz  
./configure  
make  
make install

x264

git clone http://git.videolan.org/git/x264.git  
./configure --enable-shared  
make  
make install  
centos需要注意$PATH设置:  
sudo PATH=$PATH:/usr/local/bin ./configure --enable-shared

lame

wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz  
./configure --enable-nasm  
make  
make install

libogg

wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz  
./configure  
make  
make install

libvorbis

wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz  
./configure  
make  
make install  
备注:  
需先要安装libogg

libvpx

git clone https://github.com/webmproject/libvpx.git  
./configure --enable-shared  
make  
make install  
备注:  
centos需先安装  
yum install mesa-libGL  
yum install mesa-libGL-devel  
如果安装失败,请使用低版本安装包  
wget http://webm.googlecode.com/files/libvpx-v1.2.0.tar.bz2

nasm

sudo wget http://www.nasm.us/pub/nasm/releasebuilds/2.12.01/nasm-2.12.01.tar.xz  
./configure  
make  
make install

faad2

wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz  
./configure   
make   
make install

faac

wget http://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz  
./configure   
make   
make install  
备注:  
编译错误:  
mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)'  
解决方法:  
从123行开始修改此文件mpeg4ip.h,到129行结束。  
修改前:   
#ifdef __cplusplus  
extern "C" {  
#endif  
char *strcasestr(const char *haystack, const char *needle);  
#ifdef __cplusplus  
}  
#endif  
修改后:  
#ifdef __cplusplus  
extern "C++" {  
#endif  
const char *strcasestr(const char *haystack, const char *needle);  
#ifdef __cplusplus  
}  
#endif

xvidcore

wget http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz  
cd xvidcore/build/generic  
./configure   
make   
make install

ffmpeg

git clone git://source.ffmpeg.org/ffmpeg  
./configure --prefix=/usr/local/ffmpeg --enable-version3  --enable-libvpx --enable-libfaac --enable-libmp3lame  --enable-libvorbis --enable-libx264 --enable-libxvid --enable-shared --enable-gpl --enable-postproc --enable-nonfree  --enable-avfilter --enable-pthreads --enable-libfdk-aac  
make   
make install  
备注:  
/usr/local/ffmpeg/bin/ffmpeg --help  
error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory  
解决方法:  
vi /etc/ld.so.conf   
添加 /usr/local/ffmpeg/lib  
ldconfig

nginx

wget http://nginx.org/download/nginx-1.6.2.tar.gz  
tar xzvf nginx_1.6.2.tar.gz  
git clone git://github.com/arut/nginx-rtmp-module.git  
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_stub_status_module  
make  
make install

nginx.conf配置

#直供参考,以上线配置为准    
    rtmp_auto_push on;  
    rtmp_auto_push_reconnect 1s;  

    rtmp{  
        server {  
            listen 1935;  
            chunk_size 4096;  
            max_connections 100;  

            #live  
            application live {  
                live on;
                **** ffmpeg config
            }

            application play {
                live on;
                #pull rtmp://192.168.1.101:1935/live/live1;
            }

            #hls
            application hls {
                live on;

                hls on;
                hls_nested on;
                hls_fragment_naming system;
                hls_fragment_naming_granularity 500;
                hls_path /usr/local/nginx/html/hls;
                hls_fragment 1s;
                hls_playlist_length 10m;
            }

            application vod {
                play /usr/local/nginx/html/video_recordings;
            }
        }
    }

ffmpeg配置

     exec /usr/local/ffmpeg/bin/ffmpeg -i rtmp://192.168.1.101:1935/live/$name -async 1 -vsync -1 -threads 8 -c:a copy -c:v libx264 -x264-params deblock=2:-2 -b:v 256k -b:a 32k  -vf "scale=640:480" -tune zerolatency -preset veryfast -crf 20 -r 29.97 -f flv rtmp://localhost:1935/play/$name_low;
直供参考,以上线配置为准

控制权限

#配置
 rtmp{
     server {
          notify_method get;
          application live {
             live on;
             on_publish http://localhost/check.php;
          }
    }
 }

#测试
ffmpeg ..."rtmp://192.168.1.101:1935/live/name1123?user=admin&pass=123456&token=xfsfsfsdf"

#php代码
<?php
$user = isset($_GET['user']) ? $_GET['user'] : '';
$pass = isset($_GET['pass']) ? $_GET['pass'] : '';

if (empty($user) || empty($pass)) {
    echo "wrong query input";
    header('HTTP/1.0 404 Not Found');
    exit();
 }
...

Author: josephzeng

Last Updated 2016-08-02. Created by Emacs 24.5.1 (Org mode 8.2.10)

Validate