TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to stream media using WebRTC and FFmpeg, and why it's a bad idea

127 点作者 dimes超过 4 年前

7 条评论

mandis超过 4 年前
&gt;And finally, we encounter a large issue without a good solution. In encoded videos, a key frame is a frame in the video that contains all the visual information needed to render itself without any additional metadata. These are much larger than normal frames, and contribute greatly to the bitrate. Ideally, there would be as a few keyframes as possible. However, when a new user starts consuming a stream, they need at least one keyframe to view the video. WebRTC solves this problem using the RTP Control Protocl (RTCP). When a new user consumes a stream, they send a Full Intra Request (FIR) to the producer. When a producer receives this request, they insert a keyframe into the stream. This keeps the bitrate low while ensuring all the users can view the stream. FFmpeg does not support RTCP. This means that the default FFmpeg settings will produce output that won’t be viewable if consumed mid-stream, at least until a key frame is received. Therefore, the parameter -force_key_frames expr:gte(t,n_forced*4) is needed, which produces a key frame every 4 seconds.<p>in case someone was wondering why it was a bad idea
评论 #25971605 未加载
评论 #25972300 未加载
评论 #25975210 未加载
评论 #25972377 未加载
评论 #25975214 未加载
评论 #25974633 未加载
评论 #25973554 未加载
评论 #25972100 未加载
Sean-Der超过 4 年前
To get it into the browser check out rtp-to-webrtc[0]<p>Another big piece missing here is congestion control. It isn’t just about keeping bitrate low, but figuring out what you can use. It is a really interesting topic to measure RTT&#x2F;Loss to figure out what is available. You don’t get that in ffmpeg or GStreamer yet. The best intro to this is the BBR IETF doc IMO [1]<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;pion&#x2F;webrtc&#x2F;tree&#x2F;master&#x2F;examples&#x2F;rtp-to-webrtc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pion&#x2F;webrtc&#x2F;tree&#x2F;master&#x2F;examples&#x2F;rtp-to-w...</a><p>[1] <a href="https:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;draft-cardwell-iccrg-bbr-congestion-control-00" rel="nofollow">https:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;draft-cardwell-iccrg-bbr-congest...</a>
j1elo超过 4 年前
Note that this post doesn&#x27;t really cover how to stream media using WebRTC. First and foremost, because WebRTC mandates the use of DTLS to encrypt the RTP flow, thus a plain RTP stream won&#x27;t work. A more apt title would be &quot;How to use FFmpeg to generate an encoded stream that happens to match the requirements for WebRTC&quot;.<p>Still, thanks for the article; it is always interesting to see specific applications of the FFmpeg command line, because in my opinion after having read them top to bottom, FFmpeg docs are <i>very</i> lacking in the department of explaining the <i>whys</i>.<p>Random example: You read the docs of <i>genpts</i> and it is something on the line of &quot;Enables generation of PTS timestamps&quot;. Well, thank you (&#x2F;s) But really, when should I use it? What does it actually change between using it or not? <i>What scenarios would benefit from using it?</i> Etc. Etc.
评论 #25976189 未加载
评论 #25975740 未加载
评论 #25978517 未加载
rlyshw超过 4 年前
What about the WebRTC part?<p>The post ends at RTP out from FFMPEG. Maybe I’m supposed to know how to consume that with WebRTC but in my investigation it’s not at all straightforward... the WebRTC consumer needs to become aware of the stream through a whole complicated signaling and negotiation process. How is that handled after the FFMPEG RTP stream is produced?
评论 #25975271 未加载
评论 #25971682 未加载
kuter超过 4 年前
For the purpose of one to many type of live streaming you would probably want to use HLS.<p>Twitch uses it&#x27;s own transcoding system. Here is a interesting read from their engineering blog [0]<p>[0] <a href="https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2017&#x2F;10&#x2F;10&#x2F;live-video-transmuxing-transcoding-f-fmpeg-vs-twitch-transcoder-part-i-489c1c125f28&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2017&#x2F;10&#x2F;10&#x2F;live-video-transmuxing-...</a>
评论 #25972793 未加载
_Gyan_超过 4 年前
&gt; -bsv:v h264_metadata=level=3.1<p>This should be `-bsf:v` and it&#x27;s not required since this command encodes and the encoder has been informed via `-level`.
评论 #25972120 未加载
doubleorseven超过 4 年前
Isn&#x27;t Opus the only codec WebRTC supports? If so, I think it&#x27;s another main parameter to note.
评论 #25973153 未加载
评论 #25973448 未加载