FFMPEG+Nginx搭建视频推流

FFMPEG+Nginx搭建视频推流

下载ffmpeg

在这里插入图片描述
在这里插入图片描述
启动start.bat完成本地摄像头转码

ffmpeg -f dshow -i video="Integrated Camera" -c:v libx264 -an -f flv rtmp://127.0.0.1:1935/live/222

Integrated Camera 是我本地摄像头名称,可根据需求修改
查询本机设备列表命令如下:

ffmpeg -list_devices true -f dshow -i dummy

Nginx配置

Window 需下载nginx-1.7.11.3-Gryphon 版本支持推流
Linux可任意版本但需单独安装组件

Nginx配置项如下:

#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 1935;
		chunk_size 4096;
		application live {
			live on;
            gop_cache on;
		}
		
		application hls {
			live on;
			gop_cache on; 
			hls on;
			hls_path temp/hls;
			hls_fragment 8s;
			hls_playlist_length 30s;
			
		}
		

	}
}


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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   dist;
        }

        #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;
        }
		
		location /source {
			proxy_pass http://127.0.0.1:15000/;
		}

        # 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;
    #    }
    #}
	
	server {
		listen	9990;
		server_name localhost;
		
		
		location / {
			root html;
			index index.html index.htm;
		}
	
		
		location /hls {
			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
			alias temp/hls;
			add_header 'Access-Control-Allow-Credentials' 'true';
			add_header 'Access-Control-Allow-Origin' '*';
			add_header Access-Control-Allow-Headers X-Requested-With;
			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
			add_header 'Cache-Control' 'no-cache';
			add_header 'Cache-Control' 'no-cache';
		}
		
		
        location /live {
            flv_live on;
            chunked_transfer_encoding on;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
        }

	}
	
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ffmpeg是一个用于处理多媒体数据的开源软件,可以进行音视频的录制、转码、处理和推流等操作。而Nginx是一个轻量级的Web服务器和反向代理服务器,可以用于搭建RTMP服务器来进行视频推流。 要使用ffmpeg进行推流,首先需要安装ffmpeg软件,并且确保摄像头设备已连接到计算机上。然后通过执行推流命令,指定输入的视频设备、编码方式、推流地址等参数,即可将视频数据推送到指定的RTMP服务器。 在Linux系统下,可以使用以下命令将本地视频文件推流到RTMP服务器: ffmpeg -i /dev/video0 -codec libx264 -g 10 -f flv rtmp://192.168.137.9:1935/live/stream0 这个命令中,/dev/video0代表输入的视频设备,-codec libx264指定使用libx264编码器,-g 10表示每10帧进行一次关键帧的设置,-f flv指定输出格式为FLV,而rtmp://192.168.137.9:1935/live/stream0则是指定的RTMP服务器地址和推流路径。 如果希望通过ffplay来拉流播放,可以使用以下命令: ffplay rtmp://192.168.137.9:1935/live/stream0 这个命令中,rtmp://192.168.137.9:1935/live/stream0是指定的RTMP服务器地址和推流路径。 同时,为了在Nginx中配置RTMP服务器,需要编辑Nginx的配置文件,在其中添加RTMP服务器的相关配置。具体操作如下: 1. 打开Nginx的配置文件:vi /usr/local/nginx/conf/nginx.conf 2. 在对应位置添加如下内容: rtmp { server { listen 1935; #监听的端口(默认) chunk_size 4096; #数据传输块的大小(默认) application video { play /opt/nginx/video; #视频文件存放的位置,访问方式: rtmp://localhost:1935/video } } } 以上就是使用ffmpegNginx进行推流的方法。如果还有其他问题,请随时提出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值