How can I make a GStreamer pipeline to read individual frames and publish stream?

I have an external system which sends individual H264 encoded frames one by one via TCP Socket. What I’m trying to do is getting these frames and publishing an RTSP stream to RTSP server that I have.

After getting frames (which is just reading TCP socket in chunks) my current approach is like this:

I read frames, then start a process with following command, and then write every frame to STDIN of the process.

gst-launch-1.0 -e fdsrc fd=0 ! 
                  h264parse ! 
                  avdec_h264 ! 
                  videoconvert ! 
                  videorate ! 
                  video/x-raw,framerate=25/1 ! 
                  avimux ! 
                  filesink location=gsvideo3.avi

I know that it writes stream to AVI file, but this is closest I was able to get to a normal video. And it is probably very inefficient and full of redundant pipeline steps.

I am also open to FFMPEG commands, but GStreamer is preferred as I will be able to embed it to my C# project via bindings and keep stuff in-process.

Any help is appreciated, thanks in advance!

Just to confirm: you want to pass these H.264 frames to a locally running gst-rtsp-server instance so that the video can be streamed out to clients via RTSP, right? (You don’t have an RTSP server somewhere that you want to send data via RTSP RECORD)

Also, do you want to decode the video and re-encode it server-side, or just pass through the H264 data as-is? Do you have keyframes reasonably often?

Hi. sorry for late response. I was stuck in a meeting.

I actually have a RTSP server running, locally, but that part is not GStreamer. I’m using the MediaMTX for that part.
And, yes, I have key frames fairly often, seems fine at least. If it is not much work, I would like to discover that approach too, the decoding/re-encoding.

Thanks!

So then the question is what mechanisms does this third party MediaMTX RTSP server support for passing data to it?

Can you elaborate more on this mechanisms? I once was able to publish to that server with gstreamer using rtspclientsink. But the issue was I had to skip intra frames because it was returning errors or something.

I apologize for the lack of understanding of terminology.

Ah ok, so you do want to send data to the server via the RTSP protocol (using the RECORD method).

In that case I would recommend to first try and make a test pipeline work, such as e.g.

gst-launch-1.0 videotestsrc is-live=true ! timeoverlay ! video/x-raw,format=I420 ! x264enc tune=zerolatency ! rtspclientsink

Just checked, I can see the stream nicely

How about something like this then?

gst-launch-1.0 -e fdsrc fd=0 ! 
                  h264parse ! 
                  avdec_h264 ! 
                  videoconvert ! 
                  videorate ! 
                  video/x-raw,framerate=25/1,format=I420 ! 
                  x264enc tune=zerolatency !
                  rtspclientsink location=...

Thank you a lot for the help. I really do appreciate this. The pipeline worked nicely.

This time I have a better stream, meaning GStreamer does it’s part correctly. The remaining issues are from my side.

Thanks again.
Also, this might be little bit irrelevant, but I have sent an email to centricular’s contact mail via @rahim.li email address. I would appreciate if you could check that.