# mpegtsmux

mpegtsmux muxes different streams into an MPEG Transport stream

SI sections can be specified through a custom event:

    #include <gst/gst.h>
    #include <gst/mpegts/mpegts.h>

    #define PIPELINE_STR "videotestsrc num-buffers=100 ! x264enc ! queue ! mpegtsmux name=mux ! fakesink"

    static void
    _on_bus_message (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
    {
      switch (GST_MESSAGE_TYPE (message)) {
        case GST_MESSAGE_ERROR:
        case GST_MESSAGE_EOS:
          g_main_loop_quit (mainloop);
          break;
        default:
          break;
      }
    }

    static void
    advertise_service (GstElement * mux)
    {
      GstMpegtsSDTService *service;
      GstMpegtsSDT *sdt;
      GstMpegtsDescriptor *desc;
      GstMpegtsSection *section;

      sdt = gst_mpegts_sdt_new ();

      sdt->actual_ts = TRUE;
      sdt->transport_stream_id = 42;

      service = gst_mpegts_sdt_service_new ();
      service->service_id = 42;
      service->running_status =
          GST_MPEGTS_RUNNING_STATUS_RUNNING + service->service_id;
      service->EIT_schedule_flag = FALSE;
      service->EIT_present_following_flag = FALSE;
      service->free_CA_mode = FALSE;

      desc = gst_mpegts_descriptor_from_dvb_service
          (GST_DVB_SERVICE_DIGITAL_TELEVISION, "some-service", NULL);

      g_ptr_array_add (service->descriptors, desc);
      g_ptr_array_add (sdt->services, service);

      section = gst_mpegts_section_from_sdt (sdt);
      gst_mpegts_section_send_event (section, mux);
      gst_mpegts_section_unref (section);
    }

    int
    main (int argc, char **argv)
    {
      GstElement *pipeline = NULL;
      GError *error = NULL;
      GstBus *bus;
      GMainLoop *mainloop;
      GstElement *mux;

      gst_init (&argc, &argv);

      pipeline = gst_parse_launch (PIPELINE_STR, &error);
      if (error) {
        g_print ("pipeline could not be constructed: %s\n", error->message);
        g_clear_error (&error);
        return 1;
      }

      mainloop = g_main_loop_new (NULL, FALSE);

      mux = gst_bin_get_by_name (GST_BIN (pipeline), "mux");
      advertise_service (mux);
      gst_object_unref (mux);

      /* Put a bus handler */
      bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
      gst_bus_add_signal_watch (bus);
      g_signal_connect (bus, "message", (GCallback) _on_bus_message, mainloop);

      /* Start pipeline */
      gst_element_set_state (pipeline, GST_STATE_PLAYING);
      g_main_loop_run (mainloop);

      gst_element_set_state (pipeline, GST_STATE_NULL);

      gst_object_unref (pipeline);
      gst_object_unref (bus);

      return 0;
    }

## Hierarchy

    GObject
        ╰──GInitiallyUnowned
            ╰──GstObject
                ╰──GstElement
                    ╰──GstAggregator
                        ╰──GstBaseTsMux
                            ╰──mpegtsmux

## Factory details

Authors: – Fluendo <contact></contact>

Classification: – `Codec/Muxer`

Rank – primary

Plugin – mpegtsmux

Package – GStreamer Bad Plug-ins

## Pad Templates

### `sink_%d`

    video/mpeg:
             parsed: true
        mpegversion: { (int)1, (int)2, (int)4 }
       systemstream: false
    video/x-dirac:
    image/x-jpc:
          alignment: frame
    video/x-av1:
      stream-format: obu-stream
          alignment: frame
    video/x-h264:
      stream-format: byte-stream
          alignment: { (string)au, (string)nal }
    video/x-h265:
      stream-format: byte-stream
          alignment: { (string)au, (string)nal }
    video/x-h266:
      stream-format: byte-stream
          alignment: { (string)au, (string)nal }
    audio/mpeg:
             parsed: true
        mpegversion: 1
    audio/mpeg:
             framed: true
        mpegversion: { (int)2, (int)4 }
      stream-format: { (string)adts, (string)raw }
    audio/x-lpcm:
              width: { (int)16, (int)20, (int)24 }
               rate: { (int)48000, (int)96000 }
           channels: [ 1, 8 ]
      dynamic_range: [ 0, 255 ]
           emphasis: { (boolean)false, (boolean)true }
               mute: { (boolean)false, (boolean)true }
    audio/x-ac3:
             framed: true
    audio/x-dts:
             framed: true
    audio/x-opus:
           channels: [ 1, 255 ]
    audio/x-smpte-302m:
    subpicture/x-dvb:
    application/x-teletext:
    meta/x-klv:
             parsed: true
    meta/x-id3:
             parsed: true
    meta/x-st-2038:
          alignment: line
    video/x-vp9:
    image/x-jpc:
          alignment: frame
            profile: [ 0, 49151 ]
    image/x-jxsc:
          alignment: frame
           sampling: { (string)YCbCr-4:2:2, (string)YCbCr-4:4:4 }
     interlace-mode: progressive
    image/x-jxsc:
          alignment: frame
           sampling: { (string)YCbCr-4:2:2, (string)YCbCr-4:4:4 }
     interlace-mode: fields
        field-order: { (string)top-field-first, (string)bottom-field-first }

Presence – request

Direction – sink

Object type – GstBaseTsMuxPad

### `src`

    video/mpegts:
       systemstream: true
         packetsize: { (int)188, (int)192 }

Presence – always

Direction – src

Object type – GstAggregatorPad

## Properties

### m2ts-mode

    “m2ts-mode” gboolean

Set to TRUE to output Blu-Ray disc format with 192 byte packets. FALSE for standard TS format with 188 byte packets.

Flags : Read / Write

Default value : false

The results of the search are