19,468
社区成员
发帖
与我相关
我的任务
分享
#include <gst/gst.h>
#define Device_path_1 "/dev/video0"
//#define Device_path_2 "/dev/video1"
#define Camera_caps "video/x-raw-yuv,width=(int)1920,height=(int)1080,framerate=(fraction)30/1"
int main(int argc, char *argv[])
{
GstElement *camera_source_1,*convert_1,*sink_1,*pipeline;
GMainLoop *loop;
//初始化GST
gst_init(&argc,&argv);
//创建需要的elements
camera_source_1 = gst_element_factory_make("v4l2src","camera_source_1");
convert_1 = gst_element_factory_make("ffmpegcolorspace","1_csp");
sink_1 = gst_element_factory_make("ximagesink","sink_1");
//创建pipeline
pipeline = gst_pipeline_new("camera_pipeline");
//出错处理
if(!pipeline || !camera_source_1 || !sink_1 || !convert_1){
g_printerr("Not all elements could be created !\n");
return -1;
}
//配置 elements
g_object_set(G_OBJECT(camera_source_1),"device",Device_path_1,NULL);
//link all elements
gst_bin_add_many(GST_BIN(pipeline),camera_source_1,convert_1,sink_1,NULL);
gst_element_link_many(camera_source_1,convert_1,sink_1,NULL);
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;
}