htmlnginxffmpegrtsprtmp

How can I stream a rtsp ip camera to a website via nginx


I try to stream my RTSP-IP-Camera on a website. I use the Nginx webserver. My source in the html-code is:

  <source src=rtmp://ip-address:1935/live/ type="application/x-mpegURL" />

To convert the rtsp stream i use this ffmpeg code:

ffmpeg -rtsp_transport tcp -i rtsp://user:password@ip-camera:554/h264Preview_01_main -vcodec copy -acodec copy -f mp4 -y rtmp://ip-address:1935/live/

I get the error message "muxer does not support non seekable output Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument"

I also tried to convert the rtsp-camera into a mp4 file and then access the file as source in my html code, but i couldnt read the file while ffmpeg wrote in it.

If you need more information let me know.

Thank you and have a nice day.


Solution

  • First, you should use format flv, not mp4. More, you should specify a stream(StreamKey for obs) like livestream:

    ffmpeg -rtsp_transport tcp -i rtsp://user:password@ip-camera:554/h264Preview_01_main -c copy \
      -f flv -y rtmp://ip-address:1935/live/livestream
    

    Then you covert RTSP to RTMP, and you can use server to covert the RTMP to HLS, like what you did.

    The latency of HLS is large, about 5~10s, if you want to get lower latency, please use HTTP-FLV or WebRTC, see link here