nginx - 如何 : stream with ffmpeg and nginx rtmp, Ubuntu

标签 nginx ffmpeg video-streaming ubuntu-18.04

安装了 https://nginx.org/en/linux_packages.html 的 nginx在 Ubuntu 18.04 中

sudo apt -y install curl gnupg2 ca-certificates lsb-release ;
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list ;
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - ;
sudo apt update ;
sudo apt install nginx ;
nginx 启动并运行
$ ps -aux | grep nginx
root      5602  0.0  0.0  33348   880 ?        Ss   17:03   0:00 nginx: master process nginx
nginx     5603  0.0  0.0  33744  2748 ?        S    17:03   0:00 nginx: worker process
/etc/nginx/nginx.conf
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
            allow publish 127.0.0.1;
            deny publish all;
        }
    }
}
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -f flv rtmp://localhost/live/test产量
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[tcp @ 0x5611668b8c00] Connection to tcp://localhost:1935 failed: Connection refused
[rtmp @ 0x5611668b8520] Cannot open connection tcp://localhost:1935
rtmp://localhost/live: Connection refused
线索:
1935 端口上似乎没有任何监听。netstat -tap | grep 1935一无所获
线索2:
尽管 ps显示应用程序正在运行,systemctl status nginx.service显示应用状态关闭
● nginx.service - nginx - high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2020-12-03 19:37:17 CET; 7min ago
     Docs: http://nginx.org/en/docs/
  Process: 5709 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
考虑到其他stackoverflow问题,检查的事情:
  • 试图连接到 rtmp://localhost/live/test在 nginx.conf 中,应用程序被正确命名为 live
  • nginx.conf 正确放置在/etc/nginx/,不存在其他 nginx.conf 文件,并且 nginx -s reload调用以确保已加载
  • 没有 localhost conf文件中的实例,全部重命名为127.0.0.1
  • 最佳答案

    安装支持rtmp的nginx sudo apt install nginx-core nginx-common libnginx-mod-rtmp而不是 sudo apt install nginx然后运行 ​​nginxsudo systemctl restart nginx

    关于nginx - 如何 : stream with ffmpeg and nginx rtmp, Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65131242/

    相关文章:

    c - FCGI 应用程序的问题

    ffmpeg - 如何让Gstreamer只返回关键帧?

    video - 我想将图像(3~4ea)和 mp3 转换为 mp4 文件

    android - Android 中同时播放多个视频文件

    ffmpeg 使用 -f 段选项时不尊重 FPS

    ssl - Nginx SSL 和 Wkhtmltopdf 的 "QSslSocket: cannot resolve SSLv2_client_method"错误

    php - Mysql 在 Docker 容器上退出

    post - 在 nginx 中是否可以将 POST 请求重写为 GET 请求?

    ffmpeg - GeForce 是否支持使用 FFmpeg 进行 GPU 加速的视频处理?

    objective-c - 如何在 ios 中将 y-planar、u-planar 和 uv-planar 与 yuv bi planar 分开?