<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div class="qtdSeparateBR"><br><br></div><div style="display: block;" id="yui_3_16_0_1_1432880344773_5468" class="yahoo_quoted"><div id="yui_3_16_0_1_1432880344773_5467" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"><div id="yui_3_16_0_1_1432880344773_5466" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"><div id="yui_3_16_0_1_1432880344773_5465" class="y_msg_container"><div id="yiv3891390460"><div id="yui_3_16_0_1_1432880344773_5464"><div id="yui_3_16_0_1_1432880344773_5463" style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"><div style="" class="yiv3891390460" dir="ltr" id="yiv3891390460yui_3_16_0_1_1427636432843_7224">Hi,</div>I need to push open-cv images into a v4l2
device. After some googleing I found out that Gstreamer seems to be the
best choice to do this. I completed the tutorials and I tried to build a
pipeline made by appsrc, videoconvert and v4l2sink. The problem is
that I can not find enough documentation about v4l2sink so I cannot
understand how to make it work! I am able to obtain the stream
succesfully if I use a autovideosink element but when I switch to
v4l2sink the system stops to work.<br style="" class="yiv3891390460" clear="none"><div style="" class="yiv3891390460" dir="ltr" id="yiv3891390460yui_3_16_0_1_1427636432843_9283">In
the following code there is a simple example using just one image.</div><div style="" class="yiv3891390460" dir="ltr" id="yiv3891390460yui_3_16_0_1_1427636432843_9950"><div id="yiv3891390460yui_3_16_0_1_1429507315156_8301" dir="ltr">Anybody know how to deal with this issue?</div><div id="yiv3891390460yui_3_16_0_1_1429507315156_8302" dir="ltr">Thanks,<br style="" class="yiv3891390460" clear="none"></div></div><div style="" class="yiv3891390460" dir="ltr" id="yiv3891390460yui_3_16_0_1_1427636432843_9951">Andrea<br style="" class="yiv3891390460" clear="none"></div><div style="" class="yiv3891390460" dir="ltr" id="yiv3891390460yui_3_16_0_1_1427636432843_9574"><br style="" class="yiv3891390460" clear="none"></div><div style="" class="yiv3891390460" id="yiv3891390460yui_3_16_0_1_1427636432843_9284"><span style="" class="yiv3891390460" id="yiv3891390460yui_3_16_0_1_1427636432843_9384">#include <gst/gst.h><br class="yiv3891390460" style="" clear="none">#include <cv.h><br class="yiv3891390460" style="" clear="none">#include <highgui.h><br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none">static GMainLoop *loop;<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none">static void<br class="yiv3891390460" style="" clear="none">cb_need_data (GstElement *appsrc,<br class="yiv3891390460" style="" clear="none"> guint unused_size,<br class="yiv3891390460" style="" clear="none"> gpointer user_data)<br class="yiv3891390460" style="" clear="none">{<br class="yiv3891390460" style="" clear="none"> static gboolean white = FALSE;<br class="yiv3891390460" style="" clear="none"> static GstClockTime timestamp = 0;<br class="yiv3891390460" style="" clear="none"> GstBuffer *buffer;<br class="yiv3891390460" style="" clear="none"> guint size,depth,height,width,step,channels;<br class="yiv3891390460" style="" clear="none"> GstFlowReturn ret;<br class="yiv3891390460" style="" clear="none"> IplImage* img;<br class="yiv3891390460" style="" clear="none"> guchar *data1;<br class="yiv3891390460" style="" clear="none"> GstMapInfo map;<br class="yiv3891390460" style="" clear="none"> g_print("image buffered");<br class="yiv3891390460" style="" clear="none"> img=cvLoadImage("frame1.jpg",CV_LOAD_IMAGE_COLOR); <br class="yiv3891390460" style="" clear="none"> height = img->height; <br class="yiv3891390460" style="" clear="none"> width = img->width;<br class="yiv3891390460" style="" clear="none"> step = img->widthStep;<br class="yiv3891390460" style="" clear="none"> channels = img->nChannels;<br class="yiv3891390460" style="" clear="none"> depth = img->depth;<br class="yiv3891390460" style="" clear="none"> data1 = (guchar *)img->imageData;<br class="yiv3891390460" style="" clear="none"> size = height*width*channels;<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> buffer = gst_buffer_new_allocate (NULL, size, NULL);<br class="yiv3891390460" style="" clear="none"> gst_buffer_map (buffer, &map, GST_MAP_WRITE);<br class="yiv3891390460" style="" clear="none"> memcpy( (guchar *)map.data, data1, gst_buffer_get_size( buffer ) );<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> GST_BUFFER_PTS (buffer) = timestamp;<br class="yiv3891390460" style="" clear="none"> GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 2);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> timestamp += GST_BUFFER_DURATION (buffer);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> if (ret != GST_FLOW_OK) {<br class="yiv3891390460" style="" clear="none"> /* something wrong, stop pushing */<br class="yiv3891390460" style="" clear="none"> g_main_loop_quit (loop);<br class="yiv3891390460" style="" clear="none"> }<br class="yiv3891390460" style="" clear="none">}<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none">gint<br class="yiv3891390460" style="" clear="none">main (gint argc,<br class="yiv3891390460" style="" clear="none"> gchar *argv[])<br class="yiv3891390460" style="" clear="none">{<br class="yiv3891390460" style="" clear="none"> GstElement *pipeline, *appsrc, *conv, *videosink;<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> /* init GStreamer */<br class="yiv3891390460" style="" clear="none"> gst_init (&argc, &argv);<br class="yiv3891390460" style="" clear="none"> loop = g_main_loop_new (NULL, FALSE);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> /* setup pipeline */<br class="yiv3891390460" style="" clear="none"> pipeline = gst_pipeline_new ("pipeline");<br class="yiv3891390460" style="" clear="none"> appsrc = gst_element_factory_make ("appsrc", "source");<br class="yiv3891390460" style="" clear="none"> conv = gst_element_factory_make ("videoconvert", "conv");<br class="yiv3891390460" style="" clear="none"> videosink = gst_element_factory_make ("v4l2sink", "videosink");<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> /* setup */<br class="yiv3891390460" style="" clear="none"> g_object_set (G_OBJECT (appsrc), "caps",<br class="yiv3891390460" style="" clear="none"> gst_caps_new_simple ("video/x-raw",<br class="yiv3891390460" style="" clear="none"> "format", G_TYPE_STRING, "RGB",<br class="yiv3891390460" style="" clear="none"> "width", G_TYPE_INT, 640,<br class="yiv3891390460" style="" clear="none"> "height", G_TYPE_INT, 360,<br class="yiv3891390460" style="" clear="none"> "framerate", GST_TYPE_FRACTION, 1, 1,<br class="yiv3891390460" style="" clear="none"> NULL), NULL);<br class="yiv3891390460" style="" clear="none"> gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);<br class="yiv3891390460" style="" clear="none"> gst_element_link_many (appsrc,conv, videosink, NULL);<br class="yiv3891390460" style="" clear="none"> g_object_set (videosink, "device", "/dev/video0", NULL);<br class="yiv3891390460" style="" clear="none"> //g_object_set (videosink, "flags", 0x00000002, NULL);<br class="yiv3891390460" style="" clear="none"> //g_object_set (videosink, "io-mode", 4, NULL);<br class="yiv3891390460" style="" clear="none"> <br class="yiv3891390460" style="" clear="none"> /* setup appsrc */<br class="yiv3891390460" style="" clear="none"> g_object_set (G_OBJECT (appsrc),<br class="yiv3891390460" style="" clear="none"> "stream-type", 0,<br class="yiv3891390460" style="" clear="none"> "format", GST_FORMAT_TIME, NULL);<br class="yiv3891390460" style="" clear="none"> g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> /* play */<br class="yiv3891390460" style="" clear="none"> gst_element_set_state (pipeline, GST_STATE_PLAYING);<br class="yiv3891390460" style="" clear="none"> g_main_loop_run (loop);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> /* clean up */<br class="yiv3891390460" style="" clear="none"> gst_element_set_state (pipeline, GST_STATE_NULL);<br class="yiv3891390460" style="" clear="none"> gst_object_unref (GST_OBJECT (pipeline));<br class="yiv3891390460" style="" clear="none"> g_main_loop_unref (loop);<br class="yiv3891390460" style="" clear="none"><br class="yiv3891390460" style="" clear="none"> return 0;<br class="yiv3891390460" style="" clear="none"> }</span></div><div style="" class="yiv3891390460" id="yiv3891390460yui_3_16_0_1_1429507315156_8096"><br style="" class="yiv3891390460"></div></div></div></div><br><br></div> </div> </div> </div> </div></body></html>