nginx + ffmpeg搭建音视频直播/点播系统

nginx

  1. 配置

    rtmp {
           
        server {
           
            listen      1935;
            # 点播服务vod
            application svod {
           
                play /opt/video/vod;  #点播视频存放位置
            }
            application live {
           
                live on;
                meta copy;
                hls on;
                hls_path /home/neil/suheng/living/hls;
            }
        }
    }
    
    
  2. ffempeg桌面视频录制

    ffmpeg -f x11grab -i :0.0 -vcodec libx264 -an desktop.mp4
    
  3. ffempeg + rtmp 点播
    需要在nginx.conf增加对应的点播服务配置,服务根据application name作为路由,去访问设置的视频存储位置;配置好后reload nginx,然后访问对应路由即可播放点播视频
    nginx + ffmpeg搭建音视频直播/点播系统_第1张图片

    如上点播服务名称为svod时,拉流访问地址为rtmp://localhost/svod/xxx.mp4;

  4. ffmpege + rtmp直播

    ffmpeg -f v4l2 -i /dev/video0 -vcodec libx264 -an -f flv rtmp://localhost/live/demo (电脑摄像头设备作为输入)
    
    ffmpeg -stream-loop -1 -i /home/neil/suheng/living/hls/logo.mp4 -vcodec libx264 -an -f flv rtmp://192.168.118.131/live/demo(以本地视频无限循环作为直播流)
    

    使用vlc播放器或者ffplay访问网络流rtmp://localhost/live/demo可以接收直播流

    nginx + ffmpeg搭建音视频直播/点播系统_第2张图片

查看目录/home/neil/suheng/living/hls下的文件:

在这里插入图片描述


neil@ubuntu:~/suheng/living/hls$ ffmpeg -stream_loop -1 -i /home/neil/suheng/living/hls/logo.mp4 -vcodec libx264 -c:a copy -f flv rtmp://localhost/live/demo
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/neil/suheng/living/hls/logo.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2020-11-25T17:44:37.000000Z
  Duration: 00:00:44.91, start: 0.000000, bitrate: 680 kb/s
    Stream #0:0(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      creation_time   : 2020-11-25T17:44:37.000000Z
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 544x960, 612 kb/s, 28.77 fps, 28.75 tbr, 90k tbn, 58 tbc (default)
    Metadata:
      creation_time   : 2020-11-25T17:44:37.000000Z
      encoder         : JVT/AVC Coding
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 @ 0x55cb1bb9f900] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55cb1bb9f900] profile High, level 3.1
[libx264 @ 0x55cb1bb9f900] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://localhost/live/demo':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 544x960, q=-1--1, 28.75 fps, 1k tbn, 28.75 tbc (default)
    Metadata:
      creation_time   : 2020-11-25T17:44:37.000000Z
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (HE-AAC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      creation_time   : 2020-11-25T17:44:37.000000Z
frame=11022 fps=116 q=29.0 size=   27621kB time=00:06:22.77 bitrate= 591.1kbits/s dup=0 drop=5 speed=4.03x    

主动结束播放后

nginx + ffmpeg搭建音视频直播/点播系统_第3张图片

Issues

  1. nginx编译构建失败问题:将所有的warning当作error
  2. ffmpeg推流成功,vlc无法播放;
  3. Cannot open connection tcp://localhost:1935

你可能感兴趣的:(视频编码,linux,直播,nginx,ffmpeg,rtmp直播,点播直播系统,ubuntu)