bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
11.64k stars 1.47k forks source link

WebRTC doesn't support H264 streams with B-frames #1317

Closed iesv closed 1 year ago

iesv commented 1 year ago

Which version are you using?

v0.21.0

Which operating system are you using?

Describe the issue

WebRTC doesn't support H264 streams with B-frames by using OBS steam.

Describe how to replicate the issue

  1. start the server
  2. publish with OBS
  3. read with http://localhost:8889/stream

Did you attach the server logs?

yes / no

Did you attach a network dump?

yes / no

instinctualjealousy commented 1 year ago

Set Max B-Frames to 0, and if using NVENC, disable Look-Ahead. It's simply not supported by WebRTC as stated.

iesv commented 1 year ago

Thank you!

instinctualjealousy commented 1 year ago

Also, if you get no audio over WebRTC, that's because it can't handle AAC. You'll need to script over Opus conversion to ffmpeg and remux the stream. You can probably do this with runOnReady in rtsp-simple-server but I haven't got it to work for me yet. Probably misunderstanding it, myself. Anyway, you're welcome! You could of course use ffmpeg custom output in OBS with Opus audio, but this'll give you less fine-grained control over the NVENC encoder compared to the built-in settings. Then you'd have to use a stream format that can carry Opus over to rtsp-simple-server, as rtmp cannot. It's kind of a mess. :P

t3therdev commented 1 year ago

I was able to get it working with this in runonready:

runOnReady: ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -vcodec copy -c:a libopus -f rtsp rtsp://localhost:$RTSP_PORT/compressed

aler9 commented 1 year ago

Hello all, I was never able to make a video with B-frames work with WebRTC, so i'm assuming that it is not supported at all, but i may be wrong, and if someone finds a technique or a software that supports it i'm ready to upgrade the server.

Anyway, videos with B-frames work correctly with Low-Latency HLS, therefore you can achieve a latency lower than 1s by using a different protocol.

saket424 commented 1 year ago

Set Max B-Frames to 0, and if using NVENC, disable Look-Ahead. It's simply not supported by WebRTC as stated.

Is there an explicit setting in OBS for these two? Can you send me a screenshot as it was not obvious to me where this needs to be set

saket424 commented 1 year ago

Also, another pion-based project called broadcast-box is able to handle/decode obs whip input just fine and has a whep player. How are they handling the B-Frames?

https://github.com/Glimesh/broadcast-box https://github.com/obsproject/obs-studio/commit/851a8c216e14617fb523951839f3bdb240e85141

aler9 commented 1 year ago

@saket424 you're referring to the latest OBS code that allows to publish with WebRTC, while this issue is related to publishing with RTMP. In OBS, when WebRTC is used in place of RTMP, B-Frames are automatically disabled, take a look at this line:

https://github.com/obsproject/obs-studio/blob/851a8c216e14617fb523951839f3bdb240e85141/plugins/obs-webrtc/whip-service.cpp#L34

Therefore broadcast-box doesn't handle B-frames at all.

pedrohba1 commented 11 months ago

I just wanted to add that if you are using local development and just want to remove B-frames from a video, you can do:

ffmpeg -i sp1.mp4 -c:v libx264 -bf 0  sp1_no_bf.mp4
github-actions[bot] commented 5 months ago

This issue is being locked automatically because it has been closed for more than 6 months. Please open a new issue in case you encounter a similar problem.