h264 encoder problems
hi guys, I'm using h264 encoder plugin for video encoding and sending it via rtp to client.
Sometimes video play on client speeds up or speeds down.
How to debug such cases and what could be a reason of such lagging video? Network issues?
input for encoder is coming from webrtc source
4 Replies
I tried to put RealTimer before SessioBin, but it doesn't help
I have the following pipeline part for it
full logic of my pipeline is the following:
webrtc subscription for video from janus gateway -> vp8 decode -> h264 encode -> rtp output to sip client
I implemented vp8 encoder/decoder plugin (https://github.com/spscream/membrane_vp8_ffmpeg_plugin it is in WIP state now) for membrane to decode vp8, using membrane_h264_ffmpeg_plugin as an example, it makes decoding and encoding of vp8 for my case.
Is it reason could be in non-monotonically growing pts in incoming buffers?
I have subscriber connection to janus, which is calling "switch" to janus on on "talking" events from janus, to switch video to new speaker if it is talking right now.
I added sink to debug buffers and it is showing, what pts isn't monotonically increased, in log diff is the prev buffer pts - current pts
also I see what for first video stream is coming with full vp8 frame per packet, after switch is coming splitted, timestamps on incoming rtp from subscriber stream:
may be different frame rates in incoming videos could be the reason...
I set zerolatency tune for h264 encoder and framerate to {0,1} for vp8 decoder and now it looks good
problem is solved, thanks 😄
zerolatency mode basically removes B-frames which should not be used for rtp/webrtc stuff (b-frames can have pts going back in time)
Hi @spscream , some insights that may be helpful
- If PTS are not monotonic, that means they're either broken or you have B-frames in the stream. As @Qizot said, they shouldn't be used for real-time streaming as they introduce latency, and due to that they're sometimes not properly handled by endpoints. Normally, you set the H264 encoder profile to
baseline
or constrained baseline
for live streaming. These profiles don't include B-frames.
- Don't rely on framerate, as it may change at any moment. Rely on timestamps
- Generally, media servers usually don't apply pacing (like realtimer), they just forward media and the pacing is the job of the player
- Congrats for creating the VP8 plugin, though it seems it's not public as your link doesn't work 😉thank you for insights, I moved repo in public
I also should mention, what i'm using swscale directly on decoder output in c code.
I have a special case with switch stream on janus subscription - frame size could be different for published videos, so I had to add it in decoder.
I tried to use swscale plugin in pipeline with no success and faster for my case was to implement it in decoder. In future I'll move this logic to separate membrane element, but I have deadlines now and it works for me now - decoder gives me constant frame format for outputs.