# splitmuxsink

This element wraps a muxer and a sink, and starts a new file when the mux contents are about to cross a threshold of maximum size of maximum time, splitting at video keyframe boundaries. Exactly one input video stream can be muxed, with as many accompanying audio and subtitle streams as desired.

By default, it uses mp4mux and filesink, but they can be changed via the 'muxer' and 'sink' properties.

The minimum file size is 1 GOP, however - so limits may be overrun if the distance between any 2 keyframes is larger than the limits.

If a video stream is available, the splitting process is driven by the video stream contents, and the video stream must contain closed GOPs for the output file parts to be played individually correctly. In the absence of a video stream, the first available stream is used as reference for synchronization.

In the async-finalize mode, when the threshold is crossed, the old muxer and sink is disconnected from the pipeline and left to finish the file asynchronously, and a new muxer and sink is created to continue with the next fragment. For that reason, instead of muxer and sink objects, the muxer-factory and sink-factory properties are used to construct the new objects, together with muxer-properties and sink-properties.

## Example pipelines

     gst-launch-1.0 -e v4l2src num-buffers=500 ! video/x-raw,width=320,height=240 ! videoconvert ! queue ! timeoverlay ! x264enc key-int-max=10 ! h264parse ! splitmuxsink location=video%02d.mov max-size-time=10000000000 max-size-bytes=1000000

Records a video stream captured from a v4l2 device and muxes it into ISO mp4 files, splitting as needed to limit size/duration to 10 seconds and 1MB maximum size.

     gst-launch-1.0 -e v4l2src num-buffers=500 ! video/x-raw,width=320,height=240 ! videoconvert ! queue ! timeoverlay ! x264enc key-int-max=10 ! h264parse ! splitmuxsink location=video%02d.mkv max-size-time=10000000000 muxer-factory=matroskamux muxer-properties="properties,streamable=true"

Records a video stream captured from a v4l2 device and muxer it into streamable Matroska files, splitting as needed to limit size/duration to 10 seconds. Each file will finalize asynchronously.

     gst-launch-1.0 videotestsrc num-buffers=10 ! jpegenc ! .video splitmuxsink muxer=qtmux muxer-pad-map=x-pad-map,video=video_1 location=test%05d.mp4 -v

Records 10 frames to an mp4 file, using a muxer-pad-map to make explicit mappings between the splitmuxsink sink pad and the corresponding muxer pad it will deliver to.

## Hierarchy

    GObject
        ╰──GInitiallyUnowned
            ╰──GstObject
                ╰──GstElement
                    ╰──GstBin
                        ╰──splitmuxsink

## Implemented interfaces

    GstChildProxy

## Factory details

Authors: – Jan Schmidt

Classification: – `Generic/Bin/Muxer`

Rank – none

Plugin – multifile

Package – GStreamer Good Plug-ins

## Pad Templates

### `audio_%u`

    ANY

Presence – request

Direction – sink

Object type – GstPad

### `caption_%u`

    ANY

Presence – request

Direction – sink

Object type – GstPad

### `subtitle_%u`

    ANY

Presence – request

Direction – sink

Object type – GstPad

### `video`

    ANY

Presence – request

Direction – sink

Object type – GstPad

### `video_aux_%u`

    ANY

Presence – request

Direction – sink

Object type – GstPad

## Signals

### format-location

    gchararray
    format_location_callback (GstElement * splitmux,
                              guint fragment_id,
                              gpointer udata)

    def format_location_callback (splitmux, fragment_id, udata):
        #python callback for the 'format-location' signal

    function format_location_callback(splitmux: GstElement * splitmux, fragment_id: guint fragment_id, udata: gpointer udata): {
        // javascript callback for the 'format-location' signal
    }

Parameters:

`splitmux` –

the GstSplitMuxSink

`fragment_id` –

the sequence number of the file to be created

`udata` –
No description available
Returns ( gchararray ) –

the location to be used for the next output file. This must be a newly-allocated string which will be freed with g_free by the splitmuxsink element when it no longer needs it, so use g_strdup or g_strdup_printf or similar functions to allocate it.

Flags: Run Last

### format-location-full

    gchararray
    format_location_full_callback (GstElement * splitmux,
                                   guint fragment_id,
                                   GstSample * first_sample,
                                   gpointer udata)

    def format_location_full_callback (splitmux, fragment_id, first_sample, udata):
        #python callback for the 'format-location-full' signal

    function format_location_full_callback(splitmux: GstElement * splitmux, fragment_id: guint fragment_id, first_sample: GstSample * first_sample, udata: gpointer udata): {
        // javascript callback for the 'format-location-full' signal
    }

Parameters:

`splitmux` –

the GstSplitMuxSink

`fragment_id` –

the sequence number of the file to be created

`first_sample` –

A GstSample containing the first buffer from the reference stream in the new file

`udata` –
No description available
Returns ( gchararray ) –

the location to be used for the next output file. This must be a newly-allocated string which will be freed with g_free by the splitmuxsink element when it no longer needs it, so use g_strdup or g_strdup_printf or similar functions to allocate it.

Flags: Run Last

Since : 1.12

### muxer-added

    muxer_added_callback (GstElement * splitmux,
                          GstElement * muxer,
                          gpointer udata)

    def muxer_added_callback (splitmux, muxer, udata):
        #python callback for the 'muxer-added' signal

    function muxer_added_callback(splitmux: GstElement * splitmux, muxer: GstElement * muxer, udata: gpointer udata): {
        // javascript callback for the 'muxer-added' signal
    }

Parameters:

`splitmux` –

the GstSplitMuxSink

`muxer` –

the newly added muxer element

`udata` –
No description available

Flags: Run Last

Since : 1.14

### sink-added

    sink_added_callback (GstElement * splitmux,
                         GstElement * sink,
                         gpointer udata)

    def sink_added_callback (splitmux, sink, udata):
        #python callback for the 'sink-added' signal

    function sink_added_callback(splitmux: GstElement * splitmux, sink: GstElement * sink, udata: gpointer udata): {
        // javascript callback for the 'sink-added' signal
    }

Parameters:

`splitmux` –

the GstSplitMuxSink

`sink` –

the newly added sink element

`udata` –
No description available

Flags: Run Last

Since : 1.14

### split-after

    split_after_callback (GstElement * splitmux,
                          gpointer udata)

    def split_after_callback (splitmux, udata):
        #python callback for the 'split-after' signal

    function split_after_callback(splitmux: GstElement * splitmux, udata: gpointer udata): {
        // javascript callback for the 'split-after' signal
    }

When called by the user, this action signal splits the video file (and begins a new one) immediately. Unlike the 'split-now' signal, with 'split-after', the current GOP will be output to the old file.

Parameters:

`splitmux` –

the GstSplitMuxSink

`udata` –
No description available

Flags: Run Last / Action

Since : 1.16

### split-at-running-time

    split_at_running_time_callback (GstElement * splitmux,
                                    guint64 arg0,
                                    gpointer udata)

    def split_at_running_time_callback (splitmux, arg0, udata):
        #python callback for the 'split-at-running-time' signal

    function split_at_running_time_callback(splitmux: GstElement * splitmux, arg0: guint64 arg0, udata: gpointer udata): {
        // javascript callback for the 'split-at-running-time' signal
    }

When called by the user, this action signal splits the video file (and begins a new one) as soon as the given running time is reached. If this action signal is called multiple times, running times are queued up and processed in the order they were given.

Note that this is prone to race conditions, where said running time is reached and surpassed before we had a chance to split. The file will still split immediately, but in order to make sure that the split doesn't happen too late, it is recommended to call this action signal from something that will prevent further buffers from flowing into splitmuxsink before the split is completed, such as a pad probe before splitmuxsink.

Parameters:

`splitmux` –

the GstSplitMuxSink

`arg0` –
No description available
`udata` –
No description available

Flags: Run Last / Action

Since : 1.16

### split-now

    split_now_callback (GstElement * splitmux,
                        gpointer udata)

    def split_now_callback (splitmux, udata):
        #python callback for the 'split-now' signal

    function split_now_callback(splitmux: GstElement * splitmux, udata: gpointer udata): {
        // javascript callback for the 'split-now' signal
    }

When called by the user, this action signal splits the video file (and begins a new one) immediately. The current GOP will be output to the new file.

Parameters:

`splitmux` –

the GstSplitMuxSink

`udata` –
No description available

Flags: Run Last / Action

Since : 1.14

## Properties

### alignment-threshold

    “alignment-threshold” guint64

Allow non-reference streams to be that many ns before the reference stream

Flags : Read / Write

Default value : 0

### async-finalize

    “async-finalize” gboolean

Finalize each fragment asynchronously and start a new one

Flags : Read / Write

Default value : false

### location

    “location” gchararray

Format string pattern for the location of the files to write (e.g. video%%05d.mp4)

Flags : Read / Write

Default value : NULL

### max-files

    “max-files” guint

Maximum number of files to keep on disk. Once the maximum is reached,old files start to be deleted to make room for new ones.

Flags : Read / Write

Default value : 0

### max-size-bytes

    “max-size-bytes” guint64

Max. amount of data per file (in bytes, 0=disable)

Flags : Read / Write

Default value : 0

### max-size-time

    “max-size-time” guint64

Max. amount of time per file (in ns, 0=disable)

Flags : Read / Write

Default value : 0

### max-size-timecode

    “max-size-timecode” gchararray

Maximum difference in timecode between first and last frame. Separator is assumed to be ":" everywhere (e.g. 01:00:00:00). Will only be effective if a timecode track is present.

Flags : Read / Write

Default value : NULL

### mux-overhead

    “mux-overhead” gdouble

Extra size overhead of muxing (0.02 = 2%%)

Flags : Read / Write

Default value : 0.02

### muxer

    “muxer” GstElement *

The muxer element to use (NULL = default mp4mux). Valid only for async-finalize = FALSE

Flags : Read / Write

### muxer-factory

    “muxer-factory” gchararray

The muxer element factory to use (default = mp4mux). Valid only for async-finalize = TRUE

Flags : Read / Write

Default value : mp4mux

### muxer-pad-map

    “muxer-pad-map” GstStructure *

A GstStructure specifies the mapping from splitmuxsink sink pads to muxer pads

Flags : Read / Write

### muxer-preset

    “muxer-preset” gchararray

An optional GstPreset name to use for the muxer. This only has an effect in `async-finalize=TRUE` mode.

Flags : Read / Write

Default value : NULL

### muxer-properties

    “muxer-properties” GstStructure *

The muxer element properties to use. Example: {properties,boolean-prop=true,string-prop="hi"}. Valid only for async-finalize = TRUE

Flags : Read / Write

### reset-muxer

    “reset-muxer” gboolean

Reset the muxer after each segment. Disabling this will not work for most muxers.

Flags : Read / Write

Default value : true

### send-keyframe-requests

    “send-keyframe-requests” gboolean

Request a keyframe every max-size-time ns to try splitting at that point. Needs max-size-bytes to be 0 in order to be effective.

Flags : Read / Write

Default value : false

### sink

    “sink” GstElement *

The sink element (or element chain) to use (NULL = default filesink). Valid only for async-finalize = FALSE

Flags : Read / Write

### sink-factory

    “sink-factory” gchararray

The sink element factory to use (default = filesink). Valid only for async-finalize = TRUE

Flags : Read / Write

Default value : filesink

### sink-preset

    “sink-preset” gchararray

An optional GstPreset name to use for the sink. This only has an effect in `async-finalize=TRUE` mode.

Flags : Read / Write

Default value : NULL

### sink-properties

    “sink-properties” GstStructure *

The sink element properties to use. Example: {properties,boolean-prop=true,string-prop="hi"}. Valid only for async-finalize = TRUE

Flags : Read / Write

### start-index

    “start-index” gint

Start value of fragment index.

Flags : Read / Write

Default value : 0

### use-robust-muxing

    “use-robust-muxing” gboolean

Check if muxers support robust muxing via the reserved-max-duration and reserved-duration-remaining properties and use them if so. (Only present on qtmux and mp4mux for now). splitmuxsink may then also create new fragments if the reserved header space is about to overflow. Note that for mp4mux and qtmux, reserved-moov-update-period must be set manually by the app to a non-zero value for robust muxing to have an effect.

Flags : Read / Write

Default value : false

The results of the search are