Gstreamer supports remote acquisition and UDP transmission of cameras. It is locally displayed and saved as the AVI file sender.

Source: Internet
Author: User
Tags gstreamer

After two weeks of efforts, gstreamer has finally completed remote camera acquisition, UDP transmission, local display and storage as AVI files, and now I will share with you the C language program. Thank you for your comments.

This program has the problem of short recording time but long playback length saved as a file. I hope you can learn how to solve it. Thank you !!!!

Send:

Gst-launch-0.10-V gstrtpbin name = rtpbin v4l2src device =/dev/video0! Videorate! Videoscale! Ffmpegcolorspace! 'Video/X-raw-YUV, width = (INT) 320, Height = (INT) 240, framerate = (fraction) 100 '! Rtpvrawpay! Rtpbin. send_rtp_sink_0 rtpbin. send_rtp_src_0!
Multiudpsink clients = "127.0.0.1: 9996" rtpbin. send_rtcp_src_0! Multiudpsink clients = "127.0.0.1: 9997" Sync = false async = false udpsrc Port = 10000! Rtpbin. recv_rtcp_sink_0

C code:

#include <string.h>#include <math.h>#include <gst/gst.h>#define HOST_IP "127.0.0.1"#define PORT 9996#define Video_dev "/dev/video0"#define Video_Caps "video/x-raw-yuv, width=(int)320, height=(int)240, framerate=(fraction)30/1"int main(int argc,char *argv[]){GstElement *vsource,*vrate,*vscale,*vconvert;GstElement *vrtpbin,*vrtpsink,*vrtppay;GstElement *pipeline;GMainLoop *loop;GstCaps *caps;GstPad *srcpad,*sinkpad;gst_init(&argc,&argv);pipeline=gst_pipeline_new(NULL);g_assert(pipeline);vsource=gst_element_factory_make("v4l2src","vsource");g_assert(vsource);vrate=gst_element_factory_make("videorate","vrate");g_assert(vrate);vscale=gst_element_factory_make("videoscale","vscal");g_assert(vscale);vconvert=gst_element_factory_make("ffmpegcolorspace","vconvert");g_assert(vconvert);vrtppay=gst_element_factory_make("rtpvrawpay","vrtppay");g_assert(vrtppay);g_object_set(G_OBJECT(vsource),"device", Video_dev, NULL);gst_bin_add_many(GST_BIN(pipeline),vsource,vrate,vscale,vconvert,vrtppay,NULL);caps=gst_caps_from_string(Video_Caps);if(!gst_element_link_many(vsource,vrate,vscale,vconvert,NULL)){g_error("Failed to link ");}if(!gst_element_link_filtered(vconvert,vrtppay,caps)){g_error("Failed to link caps");} gst_caps_unref(caps);vrtpbin=gst_element_factory_make("gstrtpbin","vrtpbin");g_assert(vrtpbin);gst_bin_add(GST_BIN(pipeline),vrtpbin);vrtpsink=gst_element_factory_make("udpsink","vrtpsink");g_assert(vrtpsink);g_object_set(vrtpsink,"port",PORT,"host",HOST_IP,NULL);gst_bin_add_many(GST_BIN(pipeline),vrtpsink,NULL);sinkpad=gst_element_get_request_pad(vrtpbin,"send_rtp_sink_0");srcpad=gst_element_get_static_pad(vrtppay,"src");if(gst_pad_link(srcpad,sinkpad)!=GST_PAD_LINK_OK)g_error("Failed to link video payloader to vrtpbin");gst_object_unref(srcpad);srcpad=gst_element_get_static_pad(vrtpbin,"send_rtp_src_0");sinkpad=gst_element_get_static_pad(vrtpsink,"sink");if(gst_pad_link(srcpad,sinkpad)!=GST_PAD_LINK_OK)g_error("Failed to link vrtpbin to vrtpsink");gst_object_unref(srcpad);gst_object_unref(sinkpad);g_print("starting sender pipeline\n");//gst_element_set_state(pipeline,SGT_STATE_PLAYING);gst_element_set_state (pipeline, GST_STATE_PLAYING);loop=g_main_loop_new(NULL,FALSE);g_main_loop_run(loop);g_print("stopping sender pipeline\n");gst_element_set_state(pipeline,GST_STATE_NULL);return 0;}

I hope you can point out the imperfections. Thank you !!

The acceptor is welcome to visit the next blog. Http://blog.csdn.net/zhujinghao09/article/details/8528879

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.