How to reset time in elements when pipeline is running ?
stic at free.fr
stic at free.fr
Fri Sep 12 05:47:58 PDT 2014
little mistake in the code I sent:
the line code "//GST_BUFFER_PTS (buffer) -= data->recordVideoBufferOffset;" is not commented.
----- Mail original -----
De: stic at free.fr
À: "Discussion of the development of and with GStreamer" <gstreamer-devel at lists.freedesktop.org>
Envoyé: Vendredi 12 Septembre 2014 13:42:02
Objet: How to reset time in elements when pipeline is running ?
Hello,
I am now able to dynamically add/remove elements to my pipeline on video and audio queues, this in order to add when needed recording of the running pipeline to a file.
But I am now facing the issue where I need to re timestamp the buffers, else the resulting recorded file (matroska format) doesn't start from 0, and is not well seekable.
I tried two following methods:
1 - I tried resetting buffer timestamp with buffer probe callback, one probe for video, another for audio:
I launch the buffer probe like this:
data->recordVideoBufferOffset = 0;
gst_pad_add_probe (videosrcpad, GST_PAD_PROBE_TYPE_BUFFER, record_video_buffer_pad_probe_cb, data, NULL);
And I do the same for the audio branch:
data->recordAudioBufferOffset = 0;
gst_pad_add_probe (audiosrcpad, GST_PAD_PROBE_TYPE_BUFFER, record_audio_buffer_pad_probe_cb, data, NULL);
Then the callback function are the following (The second callback function for audio is similar):
/* callback to modify buffers timestamp while recording */
static GstPadProbeReturn
record_video_buffer_pad_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
CustomData *data = (CustomData *)user_data;
GstBuffer *buffer;
GstBufferFlags flags;
buffer = GST_PAD_PROBE_INFO_BUFFER(info);
buffer = gst_buffer_make_writable(buffer);
flags = GST_BUFFER_FLAGS(buffer);
GST_PAD_PROBE_INFO_DATA(info) = buffer;
if (!(flags & GST_BUFFER_FLAG_DELTA_UNIT)) {
// save current buffer timestamp as reference
if (data->recordVideoBufferOffset == 0) {
data->recordVideoBufferOffset = GST_BUFFER_PTS (buffer);
}
}
//GST_BUFFER_PTS (buffer) -= data->recordVideoBufferOffset;
return GST_PAD_PROBE_PASS;
}
==> This works when I have only video in my stream (video time starts well from 0 now), but as soon as I have audio+video it doesn't work anymore, the resulting file is not properly playable or its playback time doesn't start from 0.
2 - I tried also to reset time using gst_pad_set_offset function, using elapsed time of pipeline as the offset:
// update pad offset to change its time
GstClock * elementClock = gst_element_get_clock (GST_ELEMENT(data->play_pipeline));
GstClockTime elementBaseTime = gst_element_get_base_time (GST_ELEMENT(data->play_pipeline));
// Calculate the elapsed time
GstClockTime diff = gst_clock_get_time(elementClock) - elementBaseTime;
// set it as offset
gst_pad_set_offset (videosrcpad, diff);
gst_pad_set_offset (audiosrcpad, diff);
==> But this doesn't seem to have any effect. Anyway it doesn't work as I want.
So can someone please give me some advices on how to achieve this ??? And can't find any information about this, mainly when we need to do this with audio+video.
I am really stuck with this and it seems my problem is with synchronising audio timestamps with video timestamps, as the first method works with video alone.
Any help would be really appreciated.
Thanks and regards.
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
More information about the gstreamer-devel
mailing list