diff --git a/subprojects/gst-plugins-good/gst/matroska/matroska-mux.c b/subprojects/gst-plugins-good/gst/matroska/matroska-mux.c index f6f49a44ba..8f1435983b 100644 --- a/subprojects/gst-plugins-good/gst/matroska/matroska-mux.c +++ b/subprojects/gst-plugins-good/gst/matroska/matroska-mux.c @@ -4203,6 +4203,15 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad, } } + if (!strcmp (collect_pad->track->codec_id, GST_MATROSKA_CODEC_ID_AUDIO_OPUS)) { + cmeta = gst_buffer_get_audio_clipping_meta (buf); + g_assert (!cmeta || cmeta->format == GST_FORMAT_DEFAULT); + + /* Start clipping is done via header and CodecDelay */ + if (cmeta && !cmeta->end) + cmeta = NULL; + } + /* Check if the duration differs from the default duration. */ write_duration = FALSE; block_duration = 0; @@ -4210,6 +4219,15 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad, block_duration = GST_BUFFER_DURATION (buf) + duration_diff; block_duration = gst_util_uint64_scale (block_duration, 1, mux->time_scale); + /* Padding should be considered in the block duration and is clipped off + * again during playback. Specifically, firefox considers it a fatal error + * if there is more padding than the block duration */ + if (cmeta) { + guint64 end = gst_util_uint64_scale_round (cmeta->end, GST_SECOND, 48000); + end = gst_util_uint64_scale (end, 1, mux->time_scale); + block_duration += end; + } + /* small difference should be ok. */ if (block_duration > collect_pad->default_duration_scaled + 1 || block_duration < collect_pad->default_duration_scaled - 1) { @@ -4237,15 +4255,6 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad, if (is_video_invisible) flags |= 0x08; - if (!strcmp (collect_pad->track->codec_id, GST_MATROSKA_CODEC_ID_AUDIO_OPUS)) { - cmeta = gst_buffer_get_audio_clipping_meta (buf); - g_assert (!cmeta || cmeta->format == GST_FORMAT_DEFAULT); - - /* Start clipping is done via header and CodecDelay */ - if (cmeta && !cmeta->end) - cmeta = NULL; - } - if (mux->doctype_version > 1 && !write_duration && !cmeta) { if (is_video_keyframe) flags |= 0x80;