I'm using NGINX as a simple HLS live video server. Sending an rtmp stream into the server, transcoding it into three different resolutions for delivery using HLS to users with different bandwidth limits.
The problem I'm having is that when I take the 1080p 30fps input transcode it down to 480p and 720p then split it into chunks with HLS the segments from the two transcoded outputs are not in sync with the copied full resolution stream.
here is what I am doing now: exec FFmpeg on the source rtmp stream:
exec ffmpeg -i rtmp://127.0.0.1:1935/live/$name
-c:v libx264 -c:a aac -b:a 128k -vf "scale=-2:720" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 2096k -bufsize 4192k -threads 16 -f flv rtmp://localhost:1935/show/$name_720
-c:v libx264 -c:a aac -b:a 96k -vf "scale=-2:480" -vsync 1 -copyts -start_at_zero -sws_flags lanczos -r 30 -g 30 -keyint_min 30 -force_key_frames "expr:gte(t,n_forced*1)" -tune zerolatency -preset ultrafast -crf 28 -maxrate 1200k -bufsize 2400k -threads 16 -f flv rtmp://localhost:1935/show/$name_480
-c copy -vsync 1 -f flv rtmp://localhost:1935/show/$name_src;
Then take the results and segment them for HLS
hls on;
hls_path /var/www/live-adapt;
hls_nested on;
hls_fragment 1;
hls_playlist_length 30;
hls_fragment_naming system;
hls_variant _480 BANDWIDTH=1200000; # Medium bitrate, SD resolution
hls_variant _720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
This is working except the streams are not in sync which causes issues if the end-users need to (or choose to) switch between streams. Example:
Sequence number 510 was not everywhere in sync:
PTS 510.7 for https://fqdn/live-adapt/c5d7ddb2-5562-4bd3-9e06-df9fa6e8ff06_480/1589521352937.ts
PTS 510.7 for https://fqdn/live-adapt/c5d7ddb2-5562-4bd3-9e06-df9fa6e8ff06_720/1589521352933.ts
PTS 511.699 for https://fqdn/live-adapt/c5d7ddb2-5562-4bd3-9e06-df9fa6e8ff06_src/1589521353752.ts
I would love any advice or suggestions.