arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.42k stars 3.51k forks source link

Audio latency for HLS, any way to fix or detect latency? #774

Open AVasic opened 8 years ago

AVasic commented 8 years ago

Hi I'm trying to stream live video on mobile by slicing input to jpegs, and playing audio from HLS, this all works, but problem is that audio is 15-30 seconds late. Do you notice from my config that I'm doing something wrong? Is there an option to detect how late audio is so that I can somehow sync images with sound? Thanks in advance!

My config:

 http {
        server {
         listen       8081;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /hls {
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        alias /dev/shm/hls;
    add_header Cache-Control no-cache;
    }

    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
    }

    location /stat.xsl {
        root /usr/local/src/nginx-1.6.2/nginx-rtmp-module;
}
}
rtmp {
    server {
        listen 1935;
        application live {
            live on;
            wait_video on;
            wait_key on;

            exec_push mkdir -p /dev/shm/feeds/$name;

        exec_push /usr/bin/ffmpeg -i rtmp://127.0.0.1/live/$name -vf fps=120/60 /dev/shm/feeds/$name/$name_%08d.jpg;
            exec_push /usr/bin/ffmpeg -i rtmp://127.0.0.1/live/$name -vn -acodec libfdk_aac -vcodec copy -tune zerolatency -analyzeduration 0 -f flv rtmp://127.0.0.1/hls/$name;
        }
        application hls {
            live on;
            hls on;
            hls_path /dev/shm/hls;
            hls_fragment 2s;
            hls_playlist_length 8s;
            hls_sync 300ms;
      }
        application audio {
            live on;
        }
    }
 }
GraphicSound commented 8 years ago

@AVasic Hi, I have the same request, have you figured out how to achieve that? Thx!

sergey-dryabzhinsky commented 8 years ago

Try tune ffmpeg input params for images: exec_push /usr/bin/ffmpeg -i "rtmp://127.0.0.1/live/$name live=1 buffer=8000" ... and for audio: exec_push /usr/bin/ffmpeg -i "rtmp://127.0.0.1/live/$name live=1 buffer=300" ...