get RTP timestamp
Jek_point
lazarev at tcobdd.ru
Fri May 6 10:09:15 UTC 2016
Hello! I'm trying to get the RTP timestamp of the subsequent output to a
video file. How can I do that?
Code for write video:
#include <gst/gst.h>
#include <glib.h>
#include <gst/gst.h>
#include <gst/gstbufferpool.h>
#include <gst/gstelement.h>
#include <gst/app/gstappsink.h>
#include <gst/gstbuffer.h>
#include <gst/rtp/gstrtpbuffer.h>
#include <gst/rtp/gstrtpbasedepayload.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define CHUNK_SIZE 1024
typedef struct _CustomData {
GstElement *pipeline;
GstElement *source;
GstElement *queue;
GstElement *depayer;
GstElement *muxer;
GstElement *sink;
GstElement *rtpbin;
guint64 num_samples; /* Number of samples generated so far (for timestamp
generation) */
gfloat a, b, c, d; /* For waveform generation */
guint sourceid; /* To control the GSource */
GMainLoop *main_loop; /* GLib's Main Loop */
} CustomData;
static void on_pad_added(GstElement *element, GstPad *pad, gpointer data)
{
GstPad *sinkpad;
GstElement *queue = (GstElement *) data;
g_print("Dynamic pad created, linking source and queue.\n");
sinkpad = gst_element_get_static_pad(queue, "sink");
gst_pad_link(pad, sinkpad);
gst_object_unref(sinkpad);
}
static gboolean cb_print_position(GstElement *pipeline)
{
gint64 pos, len;
gint64 time;
guint8 pay;
bool status;
if (gst_element_query_position(pipeline, GST_FORMAT_TIME, &pos) &&
gst_element_query_duration(pipeline, GST_FORMAT_TIME, &len))
{
g_print("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "type %i \r",
GST_TIME_ARGS(pos), GST_TIME_ARGS(len), status);
}
return TRUE;
}
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
//g_print("Got %s message\n", GST_MESSAGE_TYPE_NAME(msg));
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *error;
gst_message_parse_error(msg, &error, &debug);
g_free(debug);
g_printerr("Error: %s\n", error->message);
g_error_free(error);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc,char *argv[])
{
CustomData data;
GError *error;
GstBus *bus;
guint bus_watch_id;
memset(&data, 0, sizeof(data));
gst_init(&argc, &argv);
data.main_loop = g_main_loop_new(NULL, FALSE);
/* Working command line example: gst-launch-1.0 rtspsrc
location='rtsp://192.168.3.8/axis-media/media.amp' ! rtph264depay !
mpegtsmux ! filesink location=file.mp4 */
data.pipeline = gst_pipeline_new("rtsp_capture");
data.source = gst_element_factory_make("rtspsrc", "rtsp-source");
data.rtpbin = gst_element_factory_make("rtpsession", "rtp");
data.queue = gst_element_factory_make("queue", "queue"); // Do we need
it?
data.depayer = gst_element_factory_make("rtph264depay", "h264-depay");
data.muxer = gst_element_factory_make("mpegtsmux", "mpeg-ts-muxer");
data.sink = gst_element_factory_make("filesink", "file-output");
if (!data.pipeline || !data.source || !data.queue || !data.depayer ||
!data.muxer || !data.sink || !data.rtpbin)
{
g_printerr("One element could not be created. Exiting.\n");
return -1;
}
g_object_set(data.source, "location",
"rtsp://192.168.3.8/axis-media/media.amp", NULL);
g_object_set(data.source, "ntp-sync", true, NULL);
g_object_set(data.source, "debug", true, NULL);
g_object_set(data.sink, "location", "file.mp4", NULL);
bus = gst_pipeline_get_bus(GST_PIPELINE(data.pipeline));
bus_watch_id = gst_bus_add_watch(bus, bus_call, data.main_loop);
gst_object_unref(bus);
gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.rtpbin,
data.queue, data.depayer, data.muxer, data.sink, NULL);
g_signal_connect(data.source, "pad-added", G_CALLBACK(on_pad_added),
data.queue);
g_signal_connect(data.queue, "pad-added", G_CALLBACK(on_pad_added),
data.queue);
gst_element_link(data.queue, data.depayer);
gst_element_link(data.depayer, data.muxer);
gst_element_link(data.muxer, data.sink);
g_print("Now playing: %s\n", argv[1]);
gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
g_print("Running...\n");
g_timeout_add(100, (GSourceFunc) cb_print_position, data.pipeline);
g_main_loop_run(data.main_loop);
/* Out of the main loop, clean up nicely */
g_print("Returned, stopping playback\n");
gst_element_set_state(data.pipeline, GST_STATE_NULL);
g_print("Deleting pipeline\n");
gst_object_unref(GST_OBJECT(data.pipeline));
g_source_remove(bus_watch_id);
g_main_loop_unref(data.main_loop);
return 0;
}
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/get-RTP-timestamp-tp4677371.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list