Skip to content

Instantly share code, notes, and snippets.

@tetkuz
Last active March 26, 2020 07:02
Show Gist options
  • Save tetkuz/12e4152d195737842fec to your computer and use it in GitHub Desktop.
Save tetkuz/12e4152d195737842fec to your computer and use it in GitHub Desktop.
V4L2 Src => RTP
#!/bin/sh
gst-launch-1.0 -v \
rtpbin name=rtpbin \
udpsrc caps="application/x-rtp,media=video,clock-rate=90000,encoding-name=H264" port=5004 \
! rtpbin.recv_rtp_sink_0 \
rtpbin. \
! rtph264depay ! h264parse \
! avdec_h264 ! videoconvert \
! ximagesink
#include <stdio.h>
#include <gst/gst.h>
#define SOURCE "v4l2src !"
#define VIDEORATE "videorate ! capsfilter name=filter caps=video/x-raw,width=1280,height=720,framerate=30/1 !"
#define SINK "x264enc tune=zerolatency ! h264parse ! rtph264pay config-interval=3 ! udpsink force-ipv4=true host=127.0.0.1"
#define PIPELINE_STRING (SOURCE VIDEORATE SINK)
void pipeline_run(gpointer *user_data){
GstElement *pipeline = (GstElement *)user_data;
GstBus *bus;
GstMessage *msg;
gst_element_set_state(pipeline, GST_STATE_PLAYING);
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
if (msg != NULL)
gst_message_unref(msg);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
}
int main(int argc, char *argv[]) {
GstTask *task;
GRecMutex mutex;
GstElement *pipeline;
GstElement *filter;
gst_init(&argc, &argv);
pipeline = gst_parse_launch(PIPELINE_STRING, NULL);
filter = gst_bin_get_by_name(GST_BIN(pipeline), "filter");
(void)filter;
task = gst_task_new((GstTaskFunction)pipeline_run, (gpointer)pipeline, NULL);
g_rec_mutex_init(&mutex);
gst_task_set_lock(task, &mutex);
gst_task_start(task);
do {
int i;
scanf("%d", &i);
if (i == -1) {
break;
} else {
GstCaps *caps = NULL;
caps = gst_caps_new_simple("video/x-raw",
"framerate", GST_TYPE_FRACTION, i, 1,
NULL);
g_object_set(G_OBJECT(filter), "caps", caps, NULL);
}
} while (1);
gst_task_join(task);
gst_object_unref(pipeline);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment