NGINX RTMP Live Streaming Input/output error using on_publish to access external microservice

Viewed 1701

Nginx.conf

rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        application stream {
            live on;
            #exec ffmpeg -i rtmp://localhost:1935/stream/$name -codec copy -f flv rtmp://$name-live-encoder/play;
            on_publish http://<hostName>:<port>/auth/validate;
            exec ffmpeg -re -i rtmp://localhost:1935/stream/$name -codec copy -bsf:v h264_mp4toannexb -f mpegts udp://live-${name}-udp-encoder-service.rtmp-live-test:3555;
        }
    }
}

Incoming RTMP stream : rtmp://host:port/stream/ksptv?secret=234rfghi4e

Microservice : http://HOSTNAME/auth/validate?name=ksptv&secret=234rfghi4e ==> will return 201 if the secret Key matches with channel or 403 if it doesnt match ..

when the RTMP is getting streamed , the stream is exited with I/O error input rtmp stream logs

rtmp://rtmpHOST/stream/qptv-ind1?secret=hYn4cyWW56WdAhLussHkUw==: Input/output error [AVIOContext @ 0x2291f00] Statistics: 199663 bytes read, 0 seeks

The on_publish is not processing or hitting the microservice when using as below

        on_publish http://<hostName>:<port>/auth/validate;

But when I implement on_publish with localhost/auth and have server block defined in nginx.conf with location /auth {return 201} , rtmp streaming is successful

Can you please help me to understand why on_publish is not working with external url/api.

0 Answers
Related