From f8024f072f360d5672cf7674c6516aa032dd225c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 15 Dec 2022 17:44:03 +0200 Subject: [PATCH] mp4mux: Don't write empty chunks at the end if the last buffer of a stream started a new chunk and happened to be a from a gap event Empty chunks are not valid in MP4. Part-of: --- mux/mp4/src/mp4mux/imp.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mux/mp4/src/mp4mux/imp.rs b/mux/mp4/src/mp4mux/imp.rs index 96d6b912..68c62540 100644 --- a/mux/mp4/src/mp4mux/imp.rs +++ b/mux/mp4/src/mp4mux/imp.rs @@ -779,6 +779,16 @@ impl MP4Mux { && buffer.buffer.size() == 0 { gst::trace!(CAT, obj: stream.sinkpad, "Skipping gap buffer {buffer:?}"); + + // If a new chunk was just started for the gap buffer, don't bother and get rid + // of this chunk again for now and search for the next stream. + if let Some(chunk) = stream.chunks.last() { + if chunk.samples.is_empty() { + let _ = stream.chunks.pop(); + state.current_stream_idx = None; + } + } + continue; }