Gstreamer v4l2 sink

There is the https://github.com/arturoc/ofxGstV4L2Sink but it is without an example.
In the void update(ofPixels & pixels); it takes an ofPixels but how can I get ofPixels Object from the whole screen of the main ofApp window?

Hi,

ofImage has a grabScreen(x,y,w,h) method that you can use. Or alternatively if you want a bit more control over what you are grabbing you can draw to an ofFbo and then use it’s readToPixels method to read that to some pixels you would pass along to ofxGstV4L2Sink

Thanks for that. Unfortunately i encountered the problem that this addon is really old and written for gstreamer 0.10 and of 0.9 uses the gstreamer 1.0. So I have to port the
GstBuffer * buffer; buffer = gst_app_buffer_new (pixels.getPixels(), width*height*3, NULL, pixels.getPixels()); GstFlowReturn flow_return = gst_app_src_push_buffer(gstSrc, buffer); if (flow_return != GST_FLOW_OK) { ofLog(OF_LOG_WARNING,"error pushing buffer"); }
gst_app_buffer_new
to something else and I don’t know anything about gstreamer :smile: . Let’s have a look…

I think a part of the work is done there : https://github.com/emmanuelgeoffray/ofxGstV4L2Sink.git, seems compliant with gstreamer1.0

but i can’t make it work either…

should be working from my fork : https://github.com/jamet/ofxGstV4L2Sink.git

Any chance that you could share an example of how to use the ofxGstV4L2sink?

you just have to call setup in your OF app setup with and then pass the new pixels for exemple with grabScreen() in the ofapp draw or update fonction, it should look like a bit like that :

setup() : will setup output_streamer which is an ofxGstV4l2sink object, streaming a 320x240 image on /dev/video5, and an ofImage where you save pixels you want to stream

output_streamer.setup(320,240,5));
stream_image.allocate(ofGetScreenWidth(), ofGetScreenHeight(), OF_IMAGE_COLOR);

draw/update () :

// grab the gl buffer to stream through v4l2
//grab only every 4frames to get perf
if (ofGetFrameNum() % refresh_rate == 0){  
    glReadBuffer(GL_FRONT);  //-> you will need this only if you have GL contents on the screen you want to grab
    stream_image.grabScreen(0,0,1024,768); //-> copy screen from 0x0 pixel to 1024x768 pixel
    stream_image.resize(320,240); //-> resize image to fit 320x240 stream
    }

output_streamer.update(stream_image.getPixels());  //-> pass the captured 320x240 ofImage to ofxGstv4l2sink

don’t know if it’s a understable example?

This is perfect! Thanks!

Hi,
I tried your fork @jamet but I’m unable to have a running proof of concept.

I take this error when I run an app (I’ve modified videoPlayerExample) :

make RunRelease
HOST_OS=Linux
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk+-3.0 libmpg123 
[notice ] ofGstUtils: setPipelineWithSink(): gstreamer pipeline: appsrc  name=video_src is-live=true do-timestamp=true ! video/x-raw,format=RGB,width=320,height=240,depth=24,bpp=24,framerate=30/1,endianness=4321,red_mask=16711680, green_mask=65280, blue_mask=255 ! queue !  videoconvert ! video/x-raw,format=YUY2,width=320,height=240 !  v4l2sink name=video_sink device=/dev/video0
[ error ] ofGstUtils: gstHandleMessage(): embedded video playback halted for plugin, module capsfilter1  reported: Filter caps do not completely specify the output format
[warning] error pushing buffer
[warning] error pushing buffer
[warning] error pushing buffer
[warning] error pushing buffer
[warning] error pushing buffer
[warning] error pushing buffer
[warning] error pushing buffer

I use ubuntu 16.04, kernel 4.7 , I tried with v4l2loopback maintstream and the latest from git.
It seems to be s=the same with my other ubuntu 15.10 kernel 4.2.
On both with of_v0.9.3.

Any idea ?

Thanks you.

Something seems incorrect in the gstreamer pipeline, might be an uncorrect colorspace issue.
name=video_src is-live=true do-timestamp=true ! video/x-raw,format=RGB,width=320,height=240,depth=24,bpp=24,framerate=30/1,endianness=4321,red_mask=16711680, green_mask=65280, blue_mask=255 ! queue ! videoconvert ! video/x-raw,format=YUY2,width=320,height=240 ! v4l2sink name=video_sink device=/dev/video0

From the pipeline that is produced, it seems that you are running gstreamer 1.X.

Could you try to use a verbose mode, using ofSetLogLevel(OF_LOG_VERBOSE)

could you also try to run the videoplayer example with this log level to compare the gstreamer pipeline from videoPlayer and v4l2 sink?

could you post your code as well?

I updated this addon to work on more recent systems:

I also created some new examples and updated the documentation