Search code examples
streamgstreamertee

How to record a stream into a file while using appsink using GStreamer


I am using the following command to receive "frame event" in my C++ code and from GStreamer:

gst-launch-1.0.exe -vv udpsrc port=5000 ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! rtph264depay ! decodebin ! videoconvert ! video/x-raw,format=BGR ! videoconvert ! appsink name=sink

And it works fine.

Now I am trying to add a recording using tee. I tried:

gst-launch-1.0.exe -vv udpsrc port=5000 ! tee name=t t. ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! queue ! rtph264depay ! decodebin ! videoconvert ! appsink ! t. ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location=test.mp4

for example, but I get this error:

WARNING: erroneous pipeline: syntax error

I don't get how to use the tee. Each part works fine alone, but when I am using the tee it doesn't work.

What is the correct syntax?

(In my code, instead of using gstlaunch-1.0.exe, I am using gst_parse_launch.)


Solution

  • In your pipe there is a ! between appsink and t (tee) elements. This connects the them. You want the branches to be separate.

    gst-launch-1.0.exe -vv udpsrc port=5000 ! tee name=t t. ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! queue ! rtph264depay ! decodebin ! videoconvert ! appsink   t. ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location=test.mp4
    

    A small note: Adding caps before tee would be more practical, so that you wouldn't need to write it twice.

    gst-launch-1.0 -vv udpsrc port=5000 ! application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96 ! tee name=t t. ! queue ! rtph264depay ! decodebin ! videoconvert ! appsink  t. ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location=test.mp4