简体   繁体   English

如何在h264中流式传输视频?

[英]how to stream a video in h264?

I'm trying to stream my video into h264 , so I can play it on a html5 page through video tag. 我正在尝试将视频流式传输到h264 ,因此我可以通过video标签在html5页面上播放它。 I have found a lot of examples showing how to stream a video file to rtmp stream. 我发现了很多示例,这些示例显示了如何将视频文件流传输到rtmp流。 but I can barely find a example for h264 . 但是我几乎找不到h264的示例。

Here is the only example I can find: 这是我可以找到的唯一示例:

ffmpeg -f dshow -i video="Virtual-Camera" -preset ultrafast -vcodec libx264 -tune zerolatency -b 900k -f mpegts udp://10.1.0.102:1234

This seems fits to my need. 这似乎符合我的需求。 But I don't know what kind of server udp://10.1.0.102:1234 is. 但是我不知道哪种服务器udp://10.1.0.102:1234

If it starts with rtmp://10.1.0.102 , then I know it's a rtmp server, and I have to setup a nginx and a rtmp module. 如果它以rtmp://10.1.0.102 ,那么我知道它是rtmp服务器,并且我必须设置nginxrtmp模块。 But what's a udp server? 但是什么是udp服务器? What do I have to do to setup one? 我需要做什么来设置一个?

Thanks a lot. 非常感谢。

UDP:// is not a streaming format as such, but tells you it's serving the stream over UDP (instead of TCP). UDP://不是这样的流格式,而是告诉您它通过UDP(而不是TCP)提供流。 The format is actually MPEG-TS (which you can see from -f mpegts ) 格式实际上是MPEG-TS(您可以从-f mpegts看到)

If you want to play it in a normal browser, you will need to provide it in a different format. 如果要在普通浏览器中播放,则需要以其他格式提供。 for live video, there isn't really a universally supported format that you can just use with the tag. 对于实时视频,实际上并没有一种可以与标记一起使用的普遍支持的格式。 Microsoft Edge and Apple Safari both support HLS natively, but both Chrome and Firefox lack any native support for a live streaming format. Microsoft Edge和Apple Safari均原生支持HLS,但Chrome和Firefox均缺乏对实时流格式的任何原生支持。

With HLS, you can use hls.js and get playback in pretty much all browsers. 使用HLS,您可以使用hls.js并在几乎所有浏览器中进行播放。 ffmpeg can natively output HLS , you would just need a web server as well then. ffmpeg可以本地输出HLS ,那么您也只需要一个Web服务器。

This ffmpeg command line allows streaming over MPEG2-TS over UDP. 此ffmpeg命令行允许通过UDP的MPEG2-TS进行流传输。 So it acts as a live encoder, and that's not a bad choice for live encoder. 因此,它充当实时编码器,对于实时编码器来说,这不是一个坏选择。

So you have a live encoder in place, but to stream to a web page, you also need a streaming server software, that will ingest (receive) this live stream, and will convert it to a format playable by HTML5 video tag. 因此,您有一个实时编码器,但是要流式传输到网页,您还需要一个流式服务器软件,该服务器将提取(接收)该实时流,并将其转换为HTML5视频标签可播放的格式。 The format is likely to be WebRTC. 该格式可能是WebRTC。

You can use Wowza or Unreal Media Server - they will ingest your MPEG2-TS stream and output to webpage as WebRTC stream. 您可以使用Wowza或Unreal Media Server-它们将摄取您的MPEG2-TS流并作为WebRTC流输出到网页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM