视频拉流 Linux安装FFmpeg

 

1 下载最新源码包并解压

$ wget http://ffmpeg.org/releases/ffmpeg-3.1.3.tar.bz2
$ tar jxvf ffmpeg-3.1.3.tar.bz2

2安装yasm

$ yum install gcc 
$ yum install yasm

3安装ffmpeg

$ cd ffmpeg-3.1.3
$ ./configure
$ make
$ make install

4安装成功

输入ffmpeg打印了相关信息,表示安装成功

# ffmpeg 
ffmpeg version 3.1.3 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11)
  configuration: 
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

安装nginx-rtmp

1下载nginx-rtmp-module

yum install git

git clone https://github.com/arut/nginx-rtmp-module.git  

2下载编译nginx

yum -y install pcre-devel
yum -y install openssl openssl-devel
yum install gcc gcc-c++ 
wget http:
//nginx.org/download/nginx-1.8.1.tar.gz tar -zxvf nginx-1.8.1.tar.gz cd nginx-1.8.1 ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module make && make install

修改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 {
    worker_connections  1024;
}
rtmp {
 
    server {
 
        listen 28099;
 
        chunk_size 4000;
 
        # TV mode: one publisher, many subscribers
        application mylive {
 
            # enable live streaming
            live on;
 
        }
    }
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       28088;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

执行拉流

ffmpeg -re  -rtsp_transport tcp -i 'rtsp://11*.10:9090/dss/monitor/params?cameraid=1000118$0&substream=1' -vcodec copy -vprofile baseline   -strict -2  -f flv -s 1280x720 -q 10 'rtmp://15*2:28099/mylive/wangyong'

拉流保持文件

ffmpeg -re  -rtsp_transport tcp -i "rtsp://IP:9090/dss/monitor/params?cameraid=1000101$0&substream=1" -vcodec copy D:\out.avi

拉流提取图片

ffmpeg -re  -rtsp_transport tcp -i "rtsp://IP:9090/dss/monitor/params?cameraid=1000102$0&substream=1" -r 1 -f image2 "D:\wy1111.jpg"

ffmpeg -i "D:\out.avi" -r 1 -f image2 "D:\wy.jpg"

根据时间提取文件

ffmpeg.exe -ss 0:0:05 -t 0:0:10 -i "D:\out.avi" -vcodec copy -acodec copy "D:\out-wy.avi"

 

你可能感兴趣的:(视频拉流 Linux安装FFmpeg)