mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-01 13:42:21 +00:00
mp4mux: Adjust durations and possibly stream start time on encountering a gap buffer
If there was a previous sample in this stream then its duration needs to be extended by the gap position, and if there was none then the start time of the whole stream has to be shifted by the duration. Not doing so causes timestamps to be offset wrongly by the duration of the gap. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1015>
This commit is contained in:
parent
9307acf7fa
commit
e344585d99
1 changed files with 19 additions and 0 deletions
|
@ -786,9 +786,28 @@ impl MP4Mux {
|
|||
if chunk.samples.is_empty() {
|
||||
let _ = stream.chunks.pop();
|
||||
state.current_stream_idx = None;
|
||||
} else {
|
||||
// Add duration of the gap to the current chunk
|
||||
stream.queued_chunk_time += buffer.duration.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the duration of the gap buffer to the previously written out sample.
|
||||
if let Some(previous_sample) =
|
||||
stream.chunks.last_mut().and_then(|c| c.samples.last_mut())
|
||||
{
|
||||
gst::trace!(CAT, obj: stream.sinkpad, "Adding gap duration {} to previous sample", buffer.duration.unwrap());
|
||||
previous_sample.duration += buffer.duration.unwrap();
|
||||
} else {
|
||||
gst::trace!(CAT, obj: stream.sinkpad, "Resetting stream start time because it started with a gap");
|
||||
// If there was no previous sample yet then the next sample needs to start
|
||||
// earlier or alternatively we change the start PTS. We do the latter here
|
||||
// as otherwise the first sample would be displayed too early.
|
||||
stream.earliest_pts = None;
|
||||
stream.start_dts = None;
|
||||
stream.end_pts = None;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue