<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div style="" class="" dir="ltr" id="yiv1078033849yui_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="" clear="none"><div style="" class="" dir="ltr" id="yiv1078033849yui_3_16_0_1_1427636432843_9283">In
the following code there is a simple example using just one image.</div><div style="" class="" dir="ltr" id="yiv1078033849yui_3_16_0_1_1427636432843_9950"><div id="yui_3_16_0_1_1429507315156_8301" dir="ltr">Anybody know how to deal with this issue?</div><div id="yui_3_16_0_1_1429507315156_8302" dir="ltr">Thanks,<br style="" class="" clear="none"></div></div><div style="" class="" dir="ltr" id="yiv1078033849yui_3_16_0_1_1427636432843_9951">Andrea<br style="" class="" clear="none"></div><div style="" class="" dir="ltr" id="yiv1078033849yui_3_16_0_1_1427636432843_9574"><br style="" class="" clear="none"></div><div style="" class="" id="yiv1078033849yui_3_16_0_1_1427636432843_9284"><span style="" class="" id="yiv1078033849yui_3_16_0_1_1427636432843_9384">#include <gst/gst.h><br class="" style="" clear="none">#include <cv.h><br class="" style="" clear="none">#include <highgui.h><br class="" style="" clear="none"><br class="" style="" clear="none">static GMainLoop *loop;<br class="" style="" clear="none"><br class="" style="" clear="none">static void<br class="" style="" clear="none">cb_need_data (GstElement *appsrc,<br class="" style="" clear="none"> guint unused_size,<br class="" style="" clear="none"> gpointer user_data)<br class="" style="" clear="none">{<br class="" style="" clear="none"> static gboolean white = FALSE;<br class="" style="" clear="none"> static GstClockTime timestamp = 0;<br class="" style="" clear="none"> GstBuffer *buffer;<br class="" style="" clear="none"> guint size,depth,height,width,step,channels;<br class="" style="" clear="none"> GstFlowReturn ret;<br class="" style="" clear="none"> IplImage* img;<br class="" style="" clear="none"> guchar *data1;<br class="" style="" clear="none"> GstMapInfo map;<br class="" style="" clear="none"> g_print("image buffered");<br class="" style="" clear="none"> img=cvLoadImage("frame1.jpg",CV_LOAD_IMAGE_COLOR); <br class="" style="" clear="none"> height = img->height; <br class="" style="" clear="none"> width = img->width;<br class="" style="" clear="none"> step = img->widthStep;<br class="" style="" clear="none"> channels = img->nChannels;<br class="" style="" clear="none"> depth = img->depth;<br class="" style="" clear="none"> data1 = (guchar *)img->imageData;<br class="" style="" clear="none"> size = height*width*channels;<br class="" style="" clear="none"><br class="" style="" clear="none"> buffer = gst_buffer_new_allocate (NULL, size, NULL);<br class="" style="" clear="none"> gst_buffer_map (buffer, &map, GST_MAP_WRITE);<br class="" style="" clear="none"> memcpy( (guchar *)map.data, data1, gst_buffer_get_size( buffer ) );<br class="" style="" clear="none"><br class="" style="" clear="none"> GST_BUFFER_PTS (buffer) = timestamp;<br class="" style="" clear="none"> GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 2);<br class="" style="" clear="none"><br class="" style="" clear="none"> timestamp += GST_BUFFER_DURATION (buffer);<br class="" style="" clear="none"><br class="" style="" clear="none"> g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);<br class="" style="" clear="none"><br class="" style="" clear="none"> if (ret != GST_FLOW_OK) {<br class="" style="" clear="none"> /* something wrong, stop pushing */<br class="" style="" clear="none"> g_main_loop_quit (loop);<br class="" style="" clear="none"> }<br class="" style="" clear="none">}<br class="" style="" clear="none"><br class="" style="" clear="none">gint<br class="" style="" clear="none">main (gint argc,<br class="" style="" clear="none"> gchar *argv[])<br class="" style="" clear="none">{<br class="" style="" clear="none"> GstElement *pipeline, *appsrc, *conv, *videosink;<br class="" style="" clear="none"><br class="" style="" clear="none"> /* init GStreamer */<br class="" style="" clear="none"> gst_init (&argc, &argv);<br class="" style="" clear="none"> loop = g_main_loop_new (NULL, FALSE);<br class="" style="" clear="none"><br class="" style="" clear="none"> /* setup pipeline */<br class="" style="" clear="none"> pipeline = gst_pipeline_new ("pipeline");<br class="" style="" clear="none"> appsrc = gst_element_factory_make ("appsrc", "source");<br class="" style="" clear="none"> conv = gst_element_factory_make ("videoconvert", "conv");<br class="" style="" clear="none"> videosink = gst_element_factory_make ("v4l2sink", "videosink");<br class="" style="" clear="none"><br class="" style="" clear="none"> /* setup */<br class="" style="" clear="none"> g_object_set (G_OBJECT (appsrc), "caps",<br class="" style="" clear="none"> gst_caps_new_simple ("video/x-raw",<br class="" style="" clear="none"> "format", G_TYPE_STRING, "RGB",<br class="" style="" clear="none"> "width", G_TYPE_INT, 640,<br class="" style="" clear="none"> "height", G_TYPE_INT, 360,<br class="" style="" clear="none"> "framerate", GST_TYPE_FRACTION, 1, 1,<br class="" style="" clear="none"> NULL), NULL);<br class="" style="" clear="none"> gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);<br class="" style="" clear="none"> gst_element_link_many (appsrc,conv, videosink, NULL);<br class="" style="" clear="none"> g_object_set (videosink, "device", "/dev/video0", NULL);<br class="" style="" clear="none"> //g_object_set (videosink, "flags", 0x00000002, NULL);<br class="" style="" clear="none"> //g_object_set (videosink, "io-mode", 4, NULL);<br class="" style="" clear="none"> <br class="" style="" clear="none"> /* setup appsrc */<br class="" style="" clear="none"> g_object_set (G_OBJECT (appsrc),<br class="" style="" clear="none"> "stream-type", 0,<br class="" style="" clear="none"> "format", GST_FORMAT_TIME, NULL);<br class="" style="" clear="none"> g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);<br class="" style="" clear="none"><br class="" style="" clear="none"> /* play */<br class="" style="" clear="none"> gst_element_set_state (pipeline, GST_STATE_PLAYING);<br class="" style="" clear="none"> g_main_loop_run (loop);<br class="" style="" clear="none"><br class="" style="" clear="none"> /* clean up */<br class="" style="" clear="none"> gst_element_set_state (pipeline, GST_STATE_NULL);<br class="" style="" clear="none"> gst_object_unref (GST_OBJECT (pipeline));<br class="" style="" clear="none"> g_main_loop_unref (loop);<br class="" style="" clear="none"><br class="" style="" clear="none"> return 0;<br class="" style="" clear="none"> }</span></div><div style="" class="" id="yui_3_16_0_1_1429507315156_8096"><br style="" class=""></div></div></body></html>