ffmpeg transcode to live stream

佐手、 提交于 2019-12-04 01:55:51

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/39431714/ffmpeg-transcode-to-live-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!