nareix / joy4

Golang audio/video library and streaming server
MIT License
2.68k stars 500 forks source link

use a 10mb chunk size #88

Open iameli opened 5 years ago

iameli commented 5 years ago

nginx-rtmp in its push mode doesn't play very nicely with joy4. I believe this to be because joy4 signals its chunk size as 128mb, which exceeds the 10mb limit hardcoded in nginx-rtmp; nginx-rtmp shuts down the connection in response.

I don't know the full implications of this change, but here's @j0sh's comment from an internal Livepeer repo:

RTMP chunks are rarely larger than one frame (and can actually be interleaved with audio, eg by emitting a chunk per NALU; this in itself causes problems with some RTMP implementations).

The only potential issue I can think of is with really high bit rate content, eg 4K intra, paired with a RTMP implementation that doesn't actually chunk its frames (which is admittedly most of them). The size of a chunk (frame) could exceed 10MB in that case. Technically the protocol is supposed to renegotiate the chunk size if that happens, but most implementations aren't sophisticated enough to accommodate this.

Short of actually checking the frame sizes of such content myself, I'd say it's safe for now.

iameli commented 5 years ago

Here's an example nginx.conf I was using:

worker_processes auto;
# rtmp_auto_push on;
error_log /proc/1/fd/1 info;
events {}
rtmp {
    access_log /proc/1/fd/1;
    # wait_key on;
    # interleave on;
    max_message 10M;
    chunk_size 16384;
    max_streams 128;
    server {
        listen 1935;
        listen [::]:1935 ipv6only=on;

        application live {
            live on;
            record off;
            push rtmp://10.9.168.68:1936; # <-- This was my joy4 server
        }
    }
}

Which I ran with docker run --rm -p 1935:1935 --name nginx-rtmp -v (realpath nginx.conf):/etc/nginx/nginx.conf tiangolo/nginx-rtmp.