ffmpeg mp4 html5,html - can't re-stream using FFMPEG to MP4 HTML5 video - Stack Overflow

I have been struggling to get live streaming working from FFMPEG for many hours so raising the white flag and asking for help here.

My scenario is I have an IP security camera that I can successfully connect via RTSP (h.264) and save the video as file segments, and they play back fine either through a standalone app like VLC or via a node.js web server app that sends the 'video/mp4' & keep-alive header and streams the mp4 files previously saved by FFMPEG to a HTML5 video client.

However I want to take the same RTSP stream and re-stream it live to a HTML5 client. I know the HTML5 client bits and the FFMPEG remuxing to MP4 work as the MP4 recording/streaming works.

I have tried the following:

1) Set the output as a HTTP string. I don't think FFMPEG supports this as I get 'input/output error' and the FFMPEG documentation talks about another app called FFSERVER which isn't supported on Windows

ffmpeg -i rtsp://admin:12345@192.168.1.234:554 -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov http://127.0.0.1:8888

2) As ffmpeg runs as a spawn in node.js, I have tried piping the STDOUT to a node http server, using the same header I use for the recording playback stream. I can view this stream in VLC which is a good sign but I can't get the HTML client to recognize the stream and it shows blank, or occasionally a static image of the stream.

var liveServer = http.createServer(liveStream);

var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance

resp.writeHead(200, {"Content-Type": "video/mp4", "Connection": "keep-alive"});

var xffmpeg = child_process.spawn("ffmpeg", [

"-i", "rtsp://admin:12345@192.168.1.234:554" , "-vcodec", "copy", "-f", "mp4", "-movflags", "frag_keyframe+empty_moov", "-" // output to stdout

], {detached: false});

xffmpeg.stdout.pipe(resp);

xffmpeg.on("exit", function (code) {

console.log("Xffmpeg terminated with code " + code);

});

xffmpeg.on("error", function (e) {

console.log("Xsystem error: " + e);

});

xffmpeg.stdout.on("data",function(data) {

console.log('Xdata rcv ' + data);

});

xffmpeg.stderr.on("data", function (data) {

console.log("XFFMPEG -> " + data);

}

}

I have tried both IE11 and Chrome HTML5 clients.

I suspect there is something not quite right with the format of the stream being sent which stops the HTML5 video client but not enough to stop VLC. The irritating thing is that the code above works just fine for playing back MP4 streams that have been recorded.

Any ideas how to get live re-streaming via FFMPEG working? Thanks.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值