2

I need to display a ip camera stream in an html video tag, i have figured out how to transcode to a file from the rtsp stream like this

ffmpeg -i "rtsp://user:password@ip" -s 640x480 /tmp/output.mp4

now i need to be able to be able to live stream the rtsp input in a video tag like this

<video id="video" src="http://domain:port/output.mp4" autoplay="autoplay" />

I was trying to do something like this in my server (an ubuntu micro instance on amazon) in order to reproduce the video in the video tag but didn't work

ffmpeg -i "rtsp://user:password@ip" -s 640x480 http://localhost:8080/stream.mp4

instead i got this log

[tcp @ 0x747b40] Connection to tcp://localhost:8080 failed: Connection refused http://localhost:8080/stream.mp4: Connection refused

i don't really understand what's happening, not sure if it's sending the output to that url or serving the output there and this, i've been checking the ffmpeg man docs but i didn't find any example related to this use case and also other questiones like this one FFmpeg Stream Transcoding which is similar to my last try without success

btw, this is the camera i'm using DS-2CD2020F-I(W) - http://www.hikvision.com/en/Products_accessries_157_i5847.html they offer an httppreview but it's just an img tag source which updates but appears to be unstable

This is my first time trying to do something like this so any insight about how to achieve it will be really usefull and appreciated

Community
  • 1
  • 1
brayancastrop
  • 381
  • 5
  • 17
  • see http://stackoverflow.com/questions/26999595/what-steps-are-needed-to-stream-rtsp-from-ffmpeg, you need to combine ffserver and ffmpeg. Also there are a couple of non open source products that can do this under a free license (that would save you the hassle). – Rudolfs Bundulis Sep 12 '16 at 10:07
  • @Rudolfs These days FFMPEG does support HTTP Live Streaming without any need for FFServer. The main drawback is higher latency. – GroovyDotCom Sep 14 '16 at 18:58

1 Answers1

2

Something like this should work to create a live HLS stream from a video camera but the latency will not be good. If latency is important, you may want to look at WebRTC.

ffmpeg -i "rtsp://user:password@ip" -s 640x480 -c:v libx264 -f ssegment -hls_flags delete_segments -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 10 -segment_list_flags +live -segment_time 10 out_%6d.ts

You need to locate the output for the generated ts and m3u8 files behind an HTTP server and then you can use this test page to check that it's working.

GroovyDotCom
  • 1,304
  • 2
  • 15
  • 29
  • It is not a live stream if you must manually copy the segments and the playlist to an HTTP server. – Rudolfs Bundulis Sep 12 '16 at 21:11
  • @Rudolfs You don't need to manually copy them, just create them directly on the HTTP server. Apple seems to think it IS live streaming given that HLS stands for HTTP Live Streaming. Making this clearer in my answer. – GroovyDotCom Sep 14 '16 at 18:54
  • 1
    yeah, i ended up using kurento with webrtc http://www.kurento.org/blog/interoperating-webrtc-and-ip-cameras this is the perfect example of what i needed, given a rtsp://ip stream it in a video tag :) – brayancastrop Sep 15 '16 at 04:18