无法使用FFMPEG将流重新传输到MP4 HTML5视频 [英] can't re-stream using FFMPEG to MP4 HTML5 video

查看:51
本文介绍了无法使用FFMPEG将流重新传输到MP4 HTML5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使FFMPEG提供实时流式传输工作,所以举起了白旗,并在这里寻求帮助.

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

我的情况是我有一个IP安全摄像机,可以通过RTSP(h.264)成功连接并将视频保存为文件段,并且可以通过VLC等独立应用程序或通过node.js正常播放发送视频/mp4"和视频的网络服务器应用keep-alive标头,并将先前由FFMPEG保存的mp4文件流式传输到HTML5视频客户端.

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.

但是,我想获取相同的RTSP流并将其重新流传输到HTML5客户端.我知道HTML5客户端位和FFMPEG重混合为MP4可以像MP4录制/流媒体一样工作.

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.

我尝试了以下操作:

1)将输出设置为HTTP字符串.我不认为FFMPEG支持此功能,因为出现输入/输出错误",并且FFMPEG文档谈论了另一个名为FFSERVER的应用程序,而Windows上不支持该应用程序

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)由于ffmpeg在node.js中作为衍生运行,因此我尝试将STDOUT用管道传输到节点http服务器,并使用与记录回放流相同的标头.我可以在VLC中查看此流,这是一个好兆头,但我无法让HTML客户端识别该流,并且该流显示空白,或者偶尔显示该流的静态图像.

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);
    }
}

我已经尝试了IE11和Chrome HTML5客户端.

I have tried both IE11 and Chrome HTML5 clients.

我怀疑正在发送的流的格式有些不正确,该格式停止了HTML5视频客户端,但不足以阻止VLC.令人烦恼的是,上面的代码对于回放已记录的MP4流恰好起作用.

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.

有什么想法可以通过FFMPEG进行实时重播吗?谢谢.

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

推荐答案

很好奇,您解决了吗?除了屏幕投射外,我基本上都在做同样的事情....我已切换为使用可完美播放的webm格式...但是视频又会滞后"几秒钟.对我不利,但可能对您有用

Just curious have you solved it ? I'm doing basically the same thing except for it being screen cast.... I've switched to using webm format which plays perfectly...however the video will "lag" behind by an additional few seconds more... Which is bad for me, but might work for you

这篇关于无法使用FFMPEG将流重新传输到MP4 HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆