0

Im currently working on linux. Im given a task to code in C using libuvc to stream a video from a USB camera to the window using GTK. I'm getting the out from the uvc_frame_t but I have a problem in streaming it in gtk window. Can someone help?

Madhu Soodhan
  • 160
  • 1
  • 10
  • 2
    What problem do you have? What doesn't work? What have you tried? Show code. – andlabs Jun 15 '17 at 06:32
  • I tried getting the frame in rgb by "uvc_any2rgb(frame,rgb);". Basically this rgb has the image data from the camera. How do I map it into the gtk window? Should I use GdkPixbuf? – Madhu Soodhan Jun 15 '17 at 06:39

1 Answers1

0

Use gdk_pixbuf_new_from_data to convert the data from uvc_any2rgb into a GdkPixbuf. A basic GTK UI would be a GtkWindow with a GtkImage in it.

To update the image, call gtk_image_set_from_pixbuf with a fresh new pixbuf you created. Don't forget to either reuse the pixbuf or destroy it after use, otherwise you'll face some massive memory leak. Oh, and you'll have to handle the framerate by yourself, and use a GLib event source to be notified when a new image is available from libuvc.

liberforce
  • 11,189
  • 37
  • 48
  • Thanks for the answer, and another thing is, since uvc_start_streaming() involves a callback function, Should I need to write all this in that? – Madhu Soodhan Jun 15 '17 at 12:02