<div dir="ltr"><div>I am trying to write individual elementary transport stream (.ts) chunks with exact number and presentation time audio and video frames using the mpegtsmux plugin. My pipeline appears to correctly demux, decode, process/convert, encode, and mux. However, I am having difficulty with seek and initial audio-video offset.</div><div><br></div><div>I currently use gst_element_seek() to define the segment and I use gst_pad_set_offset() to control the temporal relationship between the first video and audio frames.</div><div><br></div><div>The problems are as follows:</div><div>1. Output video is approximately 1.7 seconds shorter than the request. For example, seek from 2-4 seconds produces a video with duration 0.3 seconds. Or, seek from 2-14 seconds creates a video with duration 10.3 seconds.</div><div>2. Audio is always ending about 0.1 seconds before video which is almost 5 audio frames at 48KHz (21ms).</div><div><br></div><div>I have been applying the sink command to the pipeline as follows:</div><div>GstSeekType startType = GST_SEEK_TYPE_NONE;</div><div>GstSeekType stopType = GST_SEEK_TYPE_NONE;</div><div>gint64 start = GST_CLOCK_TIME_NONE;</div><div>gint64 stop = GST_CLOCK_TIME_NONE;</div><div>if (inTimeSec > 0.0) {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>startType = GST_SEEK_TYPE_SET;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>start = (gint64)(inTimeSec * GST_SECOND);</div><div>}</div><div>if (outTimeSec > 0.0) {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>stopType = GST_SEEK_TYPE_SET;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>stop = (gint64)(outTimeSec * GST_SECOND);</div><div>}</div><div>const GstSeekFlags flags = static_cast<GstSeekFlags>(</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>GST_SEEK_FLAG_FLUSH</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>| GST_SEEK_FLAG_ACCURATE</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">               </span>| GST_SEEK_FLAG_SEGMENT);</div><div>gst_element_seek(pipeline, 1.0, GST_FORMAT_TIME, flags, startType, start, stopType, stop); </div><div><br></div><div>I tried sending multiple simultaneous seeks on the videoencoder and audioencoder (before the muxer) instead of on the pipeline. I also added time to one or both of the stop values. This did not cause a change the output video durations.</div><div><br></div><div>I am also not convinced that gst_pad_set_offset() is the best way to offset the video and audio starts from each other. I am using the "src_0" pad of the decodebin.</div><div><br></div><div>Note: I am evaluating the video and audio frames with:</div><div>ffprobe -show_frames -print_format json /test_media/segment.ts</div><div><br></div></div>