欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

视频拉流 Linux安装FFmpeg

程序员文章站 2023-03-31 16:39:50
1 下载最新源码包并解压 2安装yasm 3安装ffmpeg 4安装成功 输入ffmpeg打印了相关信息,表示安装成功 安装nginx-rtmp 1下载nginx-rtmp-module 2下载编译nginx 执行拉流 ......

 

1 下载最新源码包并解压

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

2安装yasm

$ 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'