-Subproject commit 865aa20fe4b63fe6da45b1ac924c27f7ca16af13
+Subproject commit 865aa20fe4b63fe6da45b1ac924c27f7ca16af13-dirty
diff --git a/gst/matroska/matroska-mux.c b/gst/matroska/matroska-mux.c
index d535fd3..a9ca597 100644
--- a/gst/matroska/matroska-mux.c
+++ b/gst/matroska/matroska-mux.c
@@ -468,6 +468,7 @@ gst_matroska_mux_init (GstMatroskaMux * mux, gpointer g_class)
   mux->num_a_streams = 0;
   mux->num_t_streams = 0;
   mux->num_v_streams = 0;
+  mux->num_sink_pads = 0;
 
   /* initialize remaining variables */
   gst_matroska_mux_reset (GST_ELEMENT (mux));
@@ -3443,6 +3444,13 @@ gst_matroska_mux_handle_buffer (GstCollectPads * pads, GstCollectData * data,
 
   GST_DEBUG_OBJECT (mux, "Collected pads");
 
+  /* This is a hack so that a new header is generated every time */
+  /* a new sink pad is added or removed.                         */
+  if (mux->num_sink_pads != g_slist_length (mux->collect->data)) {
+    mux->num_sink_pads = g_slist_length (mux->collect->data);
+    mux->state = GST_MATROSKA_MUX_STATE_START;
+  }
+
   /* start with a header */
   if (mux->state == GST_MATROSKA_MUX_STATE_START) {
     if (mux->collect->data == NULL) {
diff --git a/gst/matroska/matroska-mux.h b/gst/matroska/matroska-mux.h
index 7fea78d..427a36c 100644
--- a/gst/matroska/matroska-mux.h
+++ b/gst/matroska/matroska-mux.h
@@ -129,6 +129,8 @@ typedef struct _GstMatroskaMux {
 
   /* GstForceKeyUnit event */
   GstEvent       *force_key_unit_event;
+
+  guint 	     num_sink_pads;
 } GstMatroskaMux;
 
 typedef struct _GstMatroskaMuxClass {
