Want some guide about how to use shmsink and shmsrc


I’d like to know how I can switch appsink into shmsink from the pipe below:

nvv4l2camerasrc device=/dev/video0 ! video/x-raw(memory:NVMM),format=UYVY,width=1920,height=1080,framerate=30/1 ! 
nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1

I’d like to receive the passed data from the shmsrc from another process. Then I’d like to pass the data into appsink in the process.

How can I do this?

Thank you very much in advance!

You may try:

nvv4l2camerasrc device=/dev/video0 ! video/x-raw(memory:NVMM),format=UYVY,width=1920,height=1080,framerate=30/1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! queue ! shmsink socket-path=my.socket

And check reading with:

gst-launch-1.0 shmsrc socket-path=my.socket ! queue ! video/x-raw,format=BGR,width=1920,height=1080,framerate=30/1 ! videoconvert ! xvimagesink

Note that :

  • the pseudo file my.socket would be required to reside into a directory where your user has write permission for being successfully created.
  • shmsink will create the named socket, and it will delete it on closing only if the receiver is no longer listening. In latter case being false, you may have to delete it by yourself.
  • shmsink/src may result in significant CPU usage. Maybe using a network streaming protocol into localhost could save more resources, but I haven’t really profiled that.
1 Like

Hello @Honey_Patouceul ,

I tested your pipes and it works well.

But I’d like to ask one question.

Order matters in my tests. Output to shmsink should be preceded. And only then can I get data from shmsrc.

I wish this be more flexible so that getting the data from the shmsrc can be preceded and after this outputting into shmsink follows.

Can I make this possible?

Thank you very much in advance!

For this case, shmsrc may not be the good candidate.

You may try:

# Create a named pipe
mkfifo test.pipe

# Receiver 
gst-launch-1.0 filesrc location=test.pipe blocksize=$(expr 640 \* 480 \* 3) ! queue ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! videoconvert ! xvimagesink

# Sender (to be launched from another terminal)
gst-launch-1.0 videotestsrc ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! queue ! filesink location=test.pipe blocksize=$(expr 640 \* 480 \* 3)

Or try :

# Receiver:
gst-launch-1.0 tcpserversrc host= port=4953 ! queue ! matroskademux ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! videoconvert ! xvimagesink

# Sender:
gst-launch-1.0 videotestsrc ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! matroskamux streamable=1 ! queue ! tcpclientsink host= port=4953

Hi @Honey_Patouceul ,

I am trying to find way to wait on the creation of SENDER pipe (pipe with shmsink) from the RECEIVER pipe (pipe with shmsrc). And if this is possible the RECEIVER pipe can safely start it’s pipe after the creation of the SENDER pipe.

I wonder if I can do this with inotify-tools(inotifywait) library on the control socket file or if there exists any nicer method to do this.

And I think shm would be better than tcpsocket or pipe because shm reduces number of data copy.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.