1.回调函数sourceFun
查看上一篇。5.5第一节
2.摄像头视频流数据推送udp
bool videoEncode_pushToUDP(void *sourceFun, char *sink, unsigned int udpPort, unsigned int outPutWidth, unsigned int outPutHeight, unsigned int bitrate)
{
GstBus *bus;
GstElement *pipeline, *et_source, *et_sink, *et_videoparse, *et_omxh264enc, *et_queue, *et_h264parse, *et_mp4mux, *et_videoconvert;
GstElement *et_rtph264pay;
/* create loop */
GMainLoop *myloop = g_main_loop_new(NULL, FALSE);
/* create pipe */
pipeline = gst_pipeline_new("video-encode");
/* create source-link element */
et_source = gst_element_factory_make("appsrc", "source");
et_sink = gst_element_factory_make("udpsink", "rtp-sink");
/* create videoparse element */
et_videoparse = gst_element_factory_make("videoparse", "work-videoparse");
/* create videoparse element */
et_videoconvert = gst_element_factory_make("videoconvert", "work-videoconvert");
/* create encode element */
et_omxh264enc = gst_element_factory_make("x264enc", "work-omxh264enc");//this is diffent with zynq
et_queue = gst_element_factory_make("queue", "work-queue");
et_h264parse = gst_element_factory_make("h264parse", "work-h264parse");
et_mp4mux = gst_element_factory_make("mp4mux", "work-mp4mux");
et_rtph264pay = gst_element_factory_make("rtph264pay", "work-rtph264pay");
if(!et_source ||
!et_videoparse ||
!et_videoconvert ||
!et_omxh264enc || !et_queue || !et_h264parse || !et_mp4mux)
{
printf("error One element could not be created\n");
return false;
}
if(!et_rtph264pay)
{
printf("et_flvmux element could not be created\n");
return false;
}
if(!et_sink)
{
printf("et_sink element could not be created\n");
return false;
}
g_object_set(G_OBJECT(et_sink), "host", sink, "port", udpPort, NULL);
/* set videoparse */
g_object_set(et_videoparse, "format", 4, "width", outPutWidth, "height", outPutHeight, "framerate", "byte-stream", NULL);// "nv12" = 23, yuy2 = 4 ,
/* set videoparse todo*/
g_object_set(et_omxh264enc, "bitrate", bitrate, NULL);
/* get bus */
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_watch(bus, bus_call, myloop);
gst_object_unref(bus);
/* put all elements in a bin */
gst_bin_add_many(GST_BIN(pipeline), et_source, et_videoparse, et_queue, et_videoconvert, et_omxh264enc, et_rtph264pay, et_sink, NULL);
/* link element */
gst_element_link_many(et_source, et_videoparse, et_queue, et_videoconvert, et_omxh264enc, et_rtph264pay, et_sink, NULL);
/* setup appsrc */
g_object_set (G_OBJECT (et_source),
"stream-type", 0,NULL);
g_signal_connect(et_source, "need-data", G_CALLBACK(sourceFun), NULL);
printf("start to videoEncode test\n");
/* Now set to playing and iterate. */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_main_loop_run(myloop);
/* clean up nicely */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return true;
}
3.接收端
编写 videoAddress.sdp
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264
可利用VLC media player 播放器进行播放