Is it possible to set initial index of splitmuxsink?

I have setup gstreamer with few pipes (with help of RidgRun GSTd & gst-interpipe). First pipe realize snapshots with multifilesink with max-files and could setup starting index=start_index. Second pipe realize record with splitmuxsink and max-files & max-size-time

GStreamer 1.10.4

gstd v.0.7.0

multifilesink name=snapshot_sink index=${start_index} max-files=20 location=pic_%04d.jpg

splitmuxsink name=rec_file_sink location=rec_%03d.mpg max-size-time=60000000000 send-keyframe-requests=true max-files=5 muxer=mpegtsmux

The problem is that if I restart gstreamer (respectively gstd) the indexes are reset. If I start recording in second pipe index begins from 000. I could setup starting index in multifilesink pipe I couldn't find same for splitmuxsink. Any ideas ?


I just ran into this issue myself and I am afraid there is no way to do that using command line parameters only.

However, for those who are not afraid of diving into the API and create a gstreamer application, it is achievable using the 'format-location' signal (see the splitmuxsink documentation).

In C/C++, you may define the signal handler as follows:

static gchar* cb_FormatLocation(GstElement* splitmux, guint fragment_id, const int* offset)
{
    char* location;
    g_object_get(splitmux, "location", &location, nullptr);
    gchar* fileName = g_strdup_printf(location, fragment_id + *offset);
    g_free(location);
    return fileName;
}

and, in the pipeline definition, all you need to do is to compute an offset and pass it to g_signal_connect:

#include <filesystem>

...

GstElement* sink = gst_element_factory_make("splitmuxsink", "sink");

...

std::filesystem::path fileTemplate = "/path/to/folder/%04d.mp4";

int offset = 0;
while (std::filesystem::exists(g_strdup_printf(fileTemplate.c_str(), offset))) offset++;
g_object_set(sink, "location", fileTemplate.c_str(), nullptr);
g_signal_connect (sink, "format-location", G_CALLBACK(cb_FormatLocation), &offset);

Side note: make sure the offset variable is not destroyed before the application terminates.

It should be possible to achieve the same behaviour with the Python API.


How about the start-index property

https://gstreamer.freedesktop.org/documentation/multifile/splitmuxsink.html?gi-language=c#splitmuxsink:start-index