Streaming to HLS server with ffmpeg and nginx-rtmp-module

10,111

No. In fact, you should stream to nginx-rtmp via RTMP protocol.

ffmpeg -f x11grab -i :0.0 -vcodec libx264 -b:v 1024k -an -f flv rtmp:/192.168.1.68/live/test

And you should add something like this to nginx.conf

http {
...
server {
    ...
    location /hls {
        types {
            application/vnd.apple.mpegurl m3u8;
        }
        root /tmp;
        add_header Cache-Control no-cache;
    }
}
...
}

Then configure your player to stream source url http://192.168.1.68/hls/test.m3u8

Good luck.

Share:
10,111

Related videos on Youtube

Adam Chance
Author by

Adam Chance

Updated on September 18, 2022

Comments

  • Adam Chance
    Adam Chance almost 2 years

    I am trying to stream my desktop screen to a HLS server (nginx RTMP module), but I don't know how to go about this. I have tried

    ffmpeg -f x11grab -i :0.0 -f hls http://192.168.1.68/tmp/hls
    

    but this returns

    ffmpeg version N-60313-g6d7119d Copyright (c) 2000-2014 the FFmpeg developers
    built on Feb  2 2014 16:01:55 with gcc 4.7 (Debian 4.7.3-4)
    configuration: --enable-indev=alsa --enable-gpl --enable-x11grab --enable-libpulse --enable-libopus --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-pthreads
    libavutil      52. 63.100 / 52. 63.100
    libavcodec     55. 49.101 / 55. 49.101
    libavformat    55. 29.100 / 55. 29.100
    libavdevice    55.  7.100 / 55.  7.100
    libavfilter     4.  1.102 /  4.  1.102
    libswscale      2.  5.101 /  2.  5.101
    libswresample   0. 17.104 /  0. 17.104
    libpostproc    52.  3.100 / 52.  3.100
    [x11grab @ 0x2823900] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 640 height: 480
    [x11grab @ 0x2823900] shared memory extension found
    Input #0, x11grab, from ':0.0':
    Duration: N/A, start: 1391370026.581568, bitrate: 294617 kb/s
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 294617 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
    [tcp @ 0x28854c0] Failed to resolve hostname 192.168.10.ts: Name or service not known
    Output #0, hls, to 'http://192.168.1.68/tmp/hls':
    Metadata:
    encoder         : Lavf55.29.100
    Stream #0:0: Video: mpeg2video, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
    Stream mapping:
    Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
    Could not write header for output file #0 (incorrect codec parameters ?): Input/output error
    

    My nginx.conf contains:

    rtmp {
        server {
                listen 1935;
                chunk_size 4096;
    
                application live
        {
            live on;
                        record off;
    
            hls on;
            hls_path /tmp/hls;
            hls_fragment 12s;
        }
        }
    }
    
    • Elisa Cha Cha
      Elisa Cha Cha over 10 years
      Please include the complete ffmpeg console output.
    • Adam Chance
      Adam Chance over 10 years
      @LordNeckbeard Full output added
    • Elisa Cha Cha
      Elisa Cha Cha over 10 years
      [tcp @ 0x28854c0] Failed to resolve hostname 192.168.10.ts: Name or service not known looks suspect. Also, does it work if you output to a local file (output.m3u8)?
    • Adam Chance
      Adam Chance over 10 years
      @LordNeckbeard Outputting to a local file appears to be fine
  • chovy
    chovy over 8 years
    can you paste more of your nginx config?