Win10はNginx-1.19.6の詳細な構成とプッシュストリームをコンパイルします


最近、FFMPEGのストリーミング関連情報を読みましたが、少し面倒で少し古いので、まずは関連ツールを用意しましょう。Nginxは、Linux側の構成では大きな問題にはならないはずです。Windows側でのコンパイルは少し面倒かもしれないので、Windowsでテストしてください。

成功スタイル

ここに画像の説明を挿入

前提条件

ディレクトリパスに中国語を含めないでください。そうしないと、特にprefixパス設定中国語なしで定義されている場合に、コンパイルで問題が発生します。

必要なライブラリをダウンロードする

FFMPEG4.2.3ライブラリファイルとNginx1.19.6ソースコードおよびコンパイル済みファイルをパッケージ化してダウンロードします。Baidu
検索では、対応するダウンロードアドレスを見つけることができます。ダウンロード速度が遅い場合は、githubにアクセスして検索してダウンロードできます。

Nginx1.19.6

ダウンロードリンク

openssl-1.1.1g

ダウンロードリンク

pcre-8.44

ダウンロードリンク

zlib-1.2.11

下取地址
nginx-http-flv-moduleにはnginx-rtmp-moduleが提供するすべての機能があるため、nginx-http-flv-moduleをnginx-rtmp-moduleと一緒にコンパイルしないでください。

nginx-http-flv-module

ダウンロードはソースディレクトリで
開きMSYS、次の手順を実行するか、手動でJiekeを抽出します

mkdir -p objs/lib
cd objs/lib
tar -xf ../../pcre-8.44.tar.bz2
tar -xf ../../zlib-1.2.11.tar.gz
tar -xf ../../openssl-1.1.1g.tar.gz

依存ライブラリファイルをコンパイルする

関連ツールをインストールする

VisualStudioをインストールする

ダウンロードリンク
統合ツールの場合、一部のMakefileはnmakeでコンパイルされ、MicrosoftのツールはWindows側で使用されるため、多くのエラーを減らすことができます。

perlをインストールする


問題のダウンロードケース: @INCでWin32 / Console.pmが見つかりません(Win32 ::コンソールモジュールをインストールする必要がある場合があります)
リファレンス
ここに画像の説明を挿入

Windows用のsedをインストールする

URLのダウンロード
インストール後にC:\Program Files (x86)\GnuWin32\bin
環境変数Pathにパス追加します

Nginxをコンパイルする

MSYS次のコマンドを開いて実行し、Nginxソースコードディレクトリに入ります。

auto/configure --with-cc=cl --with-debug --prefix=install_dir --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs/lib/pcre-8.44 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-1.1.1g --with-openssl-opt=no-asm --with-http_ssl_module --with-http_sub_module --add-module=objs/lib/nginx-http-flv-module-1.2.8

Makefileを生成した後、vsのコマンドラインツールを開き、Nginxディレクトリに再度入力して、次のコンパイルコマンドを実行します。

nmake

vs.のコマンドラインツールを開き、
ここに画像の説明を挿入
64ビットを選択し、次のようにpowershell入力してPowerShellツール入力します。コマンドはLinuxターミナルのように使用できます。Makefile
ファイルがあるディレクトリを入力して実行します。

nmake

自動的にコンパイルされopenssl zlib pcre、静的にリンクされ、Nginxターゲットが生成されます。

インストール

ビルドスクリプトはinstall.bashobjsディレクトリに配置されます

#!/bin/bash
mkdir -p install_dir
mkdir -p .\install_dir\conf
mkdir -p .\install_dir\logs

cp .\nginx.exe .\install_dir\
cp ..\conf\koi-win .\install_dir\conf\
cp ..\conf\koi-utf .\install_dir\conf\
cp ..\conf\win-utf .\install_dir\conf\
cp ..\conf\mime.types .\install_dir\conf\
cp ..\conf\fastcgi.conf .\install_dir\conf\
cp ..\conf\fastcgi_params .\install_dir\conf\
cp ..\conf\uwsgi_params .\install_dir\conf\
cp ..\conf\scgi_params .\install_dir\conf\
cp ..\conf\nginx.conf .\install_dir\conf\
cp -R ..\docs\html .\install_dir\

MSYSを開いて、このスクリプトを実行します

テストを実行する

./nginx -t

ここに画像の説明を挿入
考えられる問題、ポートの占有、チェックを外すことを確認すると、IISサービスは一時的にポート80を使用し、起動エラーを引き起こします。
処理については
ここに画像の説明を挿入
ブラウザの入力をlocalhost参照してください。起動が成功したことを示すには、次のページを参照してください。
ここに画像の説明を挿入

nmakeコンパイルオプション

nmake /?

nmakeコンパイルエラー処理

こちらをご覧ください

ストリーミングテストを再投稿する

Nginxを構成する

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;
}


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   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;
    #    }
    #}
	
    server {
    
    
        listen       8080;
        server_name	 localhost;
		
		location /live {
    
    
			flv_live on; #打开 HTTP 播放 FLV 直播流功能
            chunked_transfer_encoding  on; #支持 'Transfer-Encoding: chunked' 方式回复
			add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头
			add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头
			add_header Access-Control-Allow-Headers X-Requested-With;
			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
			add_header 'Cache-Control' 'no-cache';
        }
	}
}

rtmp {
    
    
    out_queue           4096;
    out_cork            8;
    max_streams         128;
    timeout             15s;
    drop_idle_publisher 15s;

    log_interval 5s; #log 模块在 access.log 中记录日志的间隔时间,对调试非常有用
    log_size     1m; #log 模块用来记录日志的缓冲区大小
	
    server {
    
    
        listen 1985;
		server_name aron566; #用于虚拟主机名后缀通配
        application live {
    
      
            live on;
        }
	}
}

Nginxを再起動します

./nginx.exe -s reload

FFMPEGをインストールし、次のコマンドを実行します

ffmpeg -i rtmp://58.200.131.2:1935/livetv/jstv -vcodec copy -acodec copy -f flv rtmp://localhost:1985/live/mystream

VLCプレーヤーを使用して、再生するストリーミングアドレスを入力します

http://192.168.50.61:8080/live?port=1985&app=live&stream=mystream
192.168.50.61はサーバーIPです
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_42892101/article/details/111468465