- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.6k
 
Description
When pushing RTMP to nginx-rtmp-module using FFmpeg and generate HLS, the first .ts segment has audio shorter (~3.84 s) than video (~4.0 s) even though fragments are configured as 4 s and video keyframes are aligned to 4 s. This creates a small A/V duration mismatch in the first segment (and sometimes subsequent ones), which can cause offset mismatch in player when there is DISCONTINUITY
Envirnoment
OS: Ubuntu 22.04
Nginx Version: nginx/1.21.6
built by gcc 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04.2)
built with OpenSSL 3.0.2 15 Mar 2022
TLS SNI support enabled
configure arguments: --add-module=../nginx-rtmp-module --with-http_ssl_module --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/run/nginx.pid --sbin-path=/usr/sbin/nginx --with-debug
FFmpeg Version: 4.4.5
Player: Videojs
nginx-rtmp config
user root;
worker_processes auto;
error_log /var/log/nginx/error.log debug;
pid /run/nginx.pid;
events {
worker_connections  1024;
use epoll;
multi_accept on;
}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4096;;
application live {
live on;
on_publish http://127.0.0.1:8000/event/;
on_publish_done http://127.0.0.1:8000/event/;
# HLS
hls on;
hls_cleanup off;
hls_fragment_slicing aligned;
hls_fragment_naming sequential;
        hls_path /usr/local/nginx/html/stream/live/hls;
        hls_fragment 4;
        hls_sync 1ms;
        hls_playlist_length 1800;
        hls_nested on;
        # MPEG-DASH
        dash on;
        dash_cleanup on;
        dash_path /usr/local/nginx/html/stream/live/dash;
        dash_fragment 4;
        dash_playlist_length 1800;
        dash_nested on;
        # disable consuming the stream from nginx as rtmp
        deny play all;
    }
}
}
}
FFmpeg command
ffmpeg -re -i tears0fsteel.mxf \ -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text='%{pts\\:hms}':x=80:y=80:fontsize=24:fontcolor=white:borderw=2" \ -c:v libx264 -profile:v main -level 3.0 -preset ultrafast -tune zerolatency \ -r 25 -g 100 -keyint_min 100 -sc_threshold 0 \ -force_key_frames "expr:gte(t,n_forced*4)" \ -c:a aac -ar 64000 \ -pix_fmt yuv420p -b:v 2000k -maxrate 2000k -bufsize 4000k \ -f flv rtmp://localhost:1935/live/test
As using audio sample rate as 64kHz and 4 sec GOP each chunk should have exactly both audio and video duration of 4sec but Audio is ~3.84.
Please let me know any more info/file required.