Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

RTMP streaming with FFmpeg QSV

Dmitry Rogozhkin edited this page Oct 7, 2020 · 1 revision

This documentation was tested under clear Ubuntu 18.04 and Ubuntu 19.04 but it should work on another OS distributions.

Prepare environment and dependencies

Install all required common packages:

  • Complete guide "Build and use ffmpeg with MediaSDK".

  • Install packages for create local server

    sudo apt install nginx libnginx-mod-rtmp
    
  • Configure nginx server for use with ffmpeg:

    • Open config file:

      nano /etc/nginx/nginx.conf
      
    • Add to config file next content:

      rtmp {
              server {
                      listen 1935;
                      chunk_size 4096;
      
                      application live {
                              live on;
                              record off;
                              meta copy;
                              exec /usr/local/bin/ffmpeg -hwaccel qsv 
                              -hwaccel_device /dev/dri/renderD128
                              -c:v h264_qsv -i rtmp://localhost:1935/$app/$name
                              -map 0 -c:v h264_qsv -profile:v baseline
                              -preset medium -g 50 -bf 1 -async_depth 1
                              -b:v 1000K -maxrate 1000K -minrate 1000K -f flv
                              -c:a copy -f flv rtmp://localhost:1935/$app_output/$name_1000
                              -map 0 -c:v h264_qsv -profile:v baseline
                              -preset medium -g 50 -bf 1 -async_depth 1
                              -b:v 2000K -maxrate 2000K -minrate 2000K -f flv
                              -c:a copy -f flv rtmp://localhost:1935/$app_output/$name_2000;
                      }
      
                      application live_output
                      {
                              live on;
                              record off;
                      }
              }
      }
      
    • Add nginx user to video group

      usermod -aG video www-data
      
    • Restart nginx server

      systemctl restart nginx.service
      

Usage examples

Use x11grab device as input.

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw        \
   -video_size 1920x1080 -f x11grab -framerate 30         \
   -i :0.0+0,0 -vf hwupload=extra_hw_frames=64,format=qsv \
   -c:v h264_qsv -f flv rtmp://localhost/live/msdk

This grab the image from desktop with 1920x1080 width and height and transcode in way which specified in config file. You can also specify upper-left corner from which x11 grabs image by x and y in cmd, like:

-i :0.0+x,y

You can check stream by ffplay (which installed with ffmpeg)

ffplay rtmp://localhost:1935/live_output/msdk_2000

ffplay window opens and cmd output shall be like:

Input #0, flv, from 'rtmp://localhost:1935/live_output/msdk_2000':  
 Metadata:
   Server          : NGINX RTMP (github.com/arut/nginx-rtmp-module)

Also you can use local stream as input instead of x11grab like:

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw     \
   -video_size 1920x1080 -i local_stream -framerate 30 \
   -vf hwupload=extra_hw_frames=64,format=qsv          \
   -c:v h264_qsv -f flv rtmp://localhost/live/msdk

Useful links

Clone this wiki locally