get RTP timestamp

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

get RTP timestamp

Jek_point
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;
}
Reply | Threaded
Open this post in threaded view
|

Re: get RTP timestamp

Sebastian Dröge-3
On Fr, 2016-05-06 at 03:09 -0700, Jek_point wrote:
> Hello! I'm trying to get the RTP timestamp of the subsequent output to a
> video file. How can I do that?

Please describe more detailed what exactly you want to do and why. You
want to get the RTP timestamp that corresponds to a specific video
frame?

In general, if you're using rtspsrc you don't need to use the
rtpsession element (rtspsrc already contains an rtpbin), and you don't
need to use rtpsession usually but should rather use rtpbin instead.


To get the RTP timestamps directly on the buffers as timestamp, you can
set the buffer-mode=none property on rtpbin. It will then give you the
(wraparound-corrected) RTP timestamps as buffer timestamps. However
this won't work (depending on your setup) not very well for
playback/synchronization.

What's the bigger picture of what you want to achieve?

--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (968 bytes) Download Attachment