MP4 playback starts ahead when dynamically added to running pipeline

Dear GStreamer community,

I’m trying to play a local MP4 video that is added to a pipeline after the pipeline has already started.

The main pipeline starts by playing an SRT stream, which is linked to a compositor element. After about 10 seconds, the compositor “squeezes” the SRT stream to make room for the MP4 video in part of the screen.

At that moment, I dynamically add a new branch to the pipeline to play the MP4 video. The branch looks like this:

filesrc → qtdemux → decodebin → identity → compositor sink pad

The issue is that the MP4 starts according to the pipeline clock. So if the new branch is added 10 seconds after the pipeline starts, the MP4 begins playback 10 seconds ahead of its start time, effectively skipping the first 10 seconds of the video.

I’ve tried the following, but none had the desired effect:

  • Setting the ts-offset property on the identity element

  • Sending a segment event to the MP4 branch with a start time of 0

  • Sending a seek event to the MP4 branch

I suspect the solution involves one of the above approaches, but I’m not using them correctly. I’d really appreciate any guidance or examples on how to make the MP4 start from timestamp 0, independent of the main pipeline’s running time.

Thank you in advance,
Gabriele

Try querying the current position on the compositor and setting that as pad offset with gst_pad_set_offset() on a source pad before the compositor, e.g. the identity’s source pad.

Or alternatively set the current pipeline running time (gst_element_get_current_running_time()) as pad offset on the source pad that is linked to the compositor.

The reason why what you observe is happening is because non-live sources like files always start at running time 0, so adding them to a pipeline that was already running for e.g. 10s will make the first 10s of the source “too late” and skipped, so effectively you will see it starting at 10s.

By setting the pad offset you’re offsetting the running time accordingly. The same can also be used to already add an input to the compositor and “schedule” it to start a couple of seconds into the future.

Setting the offset on the identity source pad did the job! Thank you immensely for the help Tim & Seb!