Receiving H264 RTP stream from Unreal Engine 5 Pixel Streaming Plugin #1288
-
I need some advice on how I could go about receiving video streams from Unreal Engine 5's Pixel Streaming Plugin. The plugin uses a WebRTC connection to stream video/audio/controls to a web browser client, it also hosts its own signalling server. I need to receiving just the video streams in my C++ codebase for computer vision processing. To do this, I'm attempting to use libdatachannel's media tracks to get the H264 data and then eventually I'll use FFMPEG to decode the H264 data into something usable by OpenCV. I am currently able to connection to the signalling server through the websocket and I receive an SDP offer and send back an answer. After this the PeerConnection is made, a datachannel is opened, and I get a track through the This is my current
I don't know if this will help, but this is the data I get if I use no media handler:
This is the data I get if I use an RtpDepacketizer. It is consistently only 56 bytes, the first few of which are some sort of header I think:
This is the data I get if I use an H264RtpDepacketizer. It is consistently only 56 bytes, the first few of which are some sort of header I think:
Here's the SDP offer from the unreal engine signalling server if you're curious:
Link to my code: https://github.com/MissouriMRDT/Autonomy_Software/blob/topic/sim-cam/src/vision/cameras/sim/SIMZEDCam.cpp |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
You need to use |
Beta Was this translation helpful? Give feedback.
-
Ah, okay, that makes sense. I switched to using onFrame(), and I seem to be getting something that looks more like reconstructed H264 frame data now:
New OnTrack() callback
When I feed this binary data to an FFMPEG for decoding into something usable for OpenCV, I get an error from the decoder about SPS PPS missing for the frame data.
Does the H264RtpDepacketizer strip the SPS/PPS data off? Is there somewhere I can find it? I tried to append To try and debug it, I wrote one of the receiving frames to an ouput .bin file and then used
|
Beta Was this translation helpful? Give feedback.
-
I printed out the raw byte data to my console and noticed that the frame does actually have a NAL start unit, just no SPS or PPS units, which are needed by the ffmpeg decoder.
I did some more debugging and found that the first frame received seems to have the SPS (0x00 0x00 0x00 0x01 0x67) and PPS (0x00 0x00 0x00 0x01 0x68) data, and an IDR? (0x00 0x00 0x00 0x01 0x65)
The second frame then starts off with an IDR (0x00 0x00 0x00 0x01 0x65) followed by a bunch of data. And then, after the second frame, the rest of the frames always start with:
To me, this looks like a good H264 stream from libdatachannel's H264RtpDepacketizer, but FFMPEG doesn't seem to want to decode it. Any advice? |
Beta Was this translation helpful? Give feedback.
-
The H264 depacketizer works, it was just an issue with sending the data to the ffmpeg decoder. |
Beta Was this translation helpful? Give feedback.
The h264 frames look as expected. Depending of how the sender is implemented, it is possible that the first frame is not an IDR, in that case the decoder has to wait for an IDR to start decoding. However, if the decoder can't start decoding after the first IDR frame, something is probably wrong with the ffmpeg decoding code. In any case, you should not tinker with the frames.
After a quick look to your code, it looks like the whole logic in the
onFrame
callback is wrong and unnecessary. You must not try to parse NAL units, strip separators, or insert SPS/PPS. You should simply feedrtcBinaryMessage.data()
to the decoder.