Cpp Gstreamer, filesink not working, crash when using GST_STATE_PLAYING

Hello everyone,
I want to store data in a file using gstreamer but the filesink property is making my app crash, to show you, i tried to create the simplest example i could:

#include <chrono>
#include <iostream>
#include <thread>

#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
int main(int argc, char* argv[])
{
    GstElement* pipeline, * source, * sink;
    GMainLoop* loop;

    // Initialize GStreamer
    gst_init(&argc, &argv);

    // Create elements
    source = gst_element_factory_make("videotestsrc", "source");
    sink = gst_element_factory_make("filesink", "sink");

    if (!source || !sink) {
        printf("Not all elements could be created.\n");
        return -1;
    }

    // Set filesink properties
    g_object_set(sink, "location", "test_output.raw", NULL);

    // Create the empty pipeline
    pipeline = gst_pipeline_new("test-pipeline");

    if (!pipeline) {
        printf("Pipeline could not be created.\n");
        return -1;
    }

    // Build the pipeline
    gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL);
    if (gst_element_link(source, sink) != TRUE) {
        printf("Elements could not be linked.\n");
        gst_object_unref(pipeline);
        return -1;
    }

    // Start playing
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    // Wait until error or EOS
    loop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(loop);

    // Free resources
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);
    return 0;
}

With this example we just open a file, that’s it, my main use case transform jpg to buffer and add in need-data callback, but it’s the same problem here. The line: gst_element_set_state(pipeline, GST_STATE_PLAYING); will explode, the error is (visual studio): Unhandled exception at 0x00007FFE8B0FDF28 (ucrtbase.dll) in gstreamer_example.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.

The file is “created”, as it’s an empty folder, but the crash make it impossible to go further (like adding data to it).

I have to say that I did most of the gstreamer tutoriel (without problem), so it’s either the initialisation is wrong or I don’t have the necessary DLL, I suppose.

For my configuration, windows, visual studio 2022, gstreamer from msi installer (both install same folder gstreamer-1.0-msvc-x86_64-1.24.1.msi , gstreamer-1.0-devel-msvc-x86_64-1.24.1.msi) C++ - Additional include directory:

H:\gstreamer\1.0\msvc_x86_64/include
H:\gstreamer\1.0\msvc_x86_64/include/gstreamer-1.0
H:\gstreamer\1.0\msvc_x86_64/include/glib-2.0
H:\gstreamer\1.0\msvc_x86_64/lib/glib-2.0/include
H:\gstreamer\1.0\msvc_x86_64/lib
%(AdditionalIncludeDirectories)

Linker - General

H:\gstreamer\1.0\msvc_x86_64/lib
H:\gstreamer\1.0\msvc_x86_64/lib/gstreamer-1.0
%(AdditionalLibraryDirectories)

Linker - input

gobject-2.0.lib
glib-2.0.lib
gstreamer-1.0.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib
gstapp-1.0.lib
jpeg.lib
mpg123.lib
png16.lib
gstaudio-1.0.lib
openjp2.lib
turbojpeg.lib
%(AdditionalDependencies)

My PATH environment variable contain both the **bin ** and **lib ** path. Using the command line does not crash

$ gst-launch-1.0 videotestsrc ! filesink location=test_output.raw
Use Windows high-resolution clock, precision: 1 ms
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
Redistribute latency…
New clock: GstSystemClock
handling interrupt.
Interrupt: Stopping pipeline …
Execution ended after 0:00:09.041954200
Setting pipeline to NULL …
Freeing pipeline …

I’m stuck, i don’t understand what is (could be) wrong, any help is appreciated, even if it’s “I tested on my side and had no problem”. Thank you in advance.

Any chance you could get a stack trace?

Of course, sorry for the late reply, the image is the visual studio callstack.

I wanted to share with you the output exe with GST_DEBUG=6, but the log is 37 000 line long and 6million character, and i don’t know how to share a text file here, and using a image file to hide a text is max 250 000 character.
So i’ll just share what seem to be the most important part.

Init:

0:00:00.000104800 2896 00000167E9951E40 INFO GST_INIT gst.c:574:init_pre: Initializing GStreamer Core Library version 1.24.1
0:00:00.000995800 2896 00000167E9951E40 INFO GST_INIT gst.c:575:init_pre: Using library installed in H:\gstreamer\1.0\msvc_x86_64\lib
0:00:00.001773200 2896 00000167E9951E40 DEBUG GST_MEMORY gstallocator.c:607:_priv_gst_allocator_initialize: memory alignment: 7
0:00:00.002503200 2896 00000167E9951E40 DEBUG GST_MEMORY gstallocator.c:583:gst_allocator_sysmem_init: init allocator 00000167E99641E0
0:00:00.003102700 2896 00000167E9951E40 DEBUG GST_MEMORY gstallocator.c:233:gst_allocator_register: registering allocator 00000167E99641E0 with name “SystemMemory”
0:00:00.003659800 2896 00000167E9951E40 INFO GST_INIT gstmessage.c:129:_priv_gst_message_initialize: init messages
0:00:00.004112600 2896 00000167E9951E40 DEBUG GST_ELEMENT_PADS gstelement.c:316:gst_element_base_class_init: type GstElement : factory 0000000000000000
0:00:00.004628900 2896 00000167E9951E40 DEBUG GST_ELEMENT_PADS gstelement.c:316:gst_element_base_class_init: type GstBin : factory 0000000000000000
0:00:00.005371500 2896 00000167E9951E40 INFO GST_INIT gstcontext.c:86:_priv_gst_context_initialize: init contexts
0:00:00.007618700 2896 00000167E9951E40 INFO GST_PLUGIN_LOADING gstplugin.c:328:_priv_gst_plugin_initialize: registering 0 static plugins
0:00:00.007988700 2896 00000167E9951E40 LOG GST_PLUGIN_LOADING gstplugin.c:233:gst_plugin_register_static: attempting to load static plugin “staticelements” now…
0:00:00.008570600 2896 00000167E9951E40 LOG GST_PLUGIN_LOADING gstplugin.c:522:gst_plugin_register_func: plugin “(NULL)” looks good
0:00:00.009118800 2896 00000167E9951E40 LOG GST_ELEMENT_FACTORY gstelementfactory.c:241:gst_element_register: Created new elementfactory for type GstBin
0:00:00.009448500 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistry.c:593:gst_registry_add_feature: adding feature 00000167E993D490 (bin)
0:00:00.009763200 2896 00000167E9951E40 DEBUG GST_REFCOUNTING gstobject.c:711:gst_object_set_parent: set parent (ref and sink)
0:00:00.010079100 2896 00000167E9951E40 LOG GST_REGISTRY gstregistry.c:611:gst_registry_add_feature: emitting feature-added for bin
0:00:00.010413500 2896 00000167E9951E40 LOG GST_ELEMENT_FACTORY gstelementfactory.c:241:gst_element_register: Created new elementfactory for type GstPipeline
0:00:00.010733400 2896 00000167E9951E40 DEBUG GST_ELEMENT_PADS gstelement.c:316:gst_element_base_class_init: type GstPipeline : factory 00000167E99709E0
0:00:00.011078600 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistry.c:593:gst_registry_add_feature: adding feature 00000167E99709E0 (pipeline)
0:00:00.011411000 2896 00000167E9951E40 DEBUG GST_REFCOUNTING gstobject.c:711:gst_object_set_parent: set parent (ref and sink)
0:00:00.011730900 2896 00000167E9951E40 LOG GST_REGISTRY gstregistry.c:611:gst_registry_add_feature: emitting feature-added for pipeline
0:00:00.012047700 2896 00000167E9951E40 LOG GST_PLUGIN_LOADING gstplugin.c:549:gst_plugin_register_func: plugin “(NULL)” initialised
0:00:00.012364500 2896 00000167E9951E40 INFO GST_PLUGIN_LOADING gstplugin.c:236:gst_plugin_register_static: registered static plugin “staticelements”
0:00:00.012715600 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistry.c:477:gst_registry_add_plugin: adding plugin 00000167E996FD40 for filename “(NULL)”
0:00:00.013130500 2896 00000167E9951E40 LOG GST_REGISTRY gstregistry.c:490:gst_registry_add_plugin: emitting plugin-added for filename “(NULL)”
0:00:00.013504000 2896 00000167E9951E40 INFO GST_PLUGIN_LOADING gstplugin.c:238:gst_plugin_register_static: added static plugin “staticelements”, result: 1
0:00:00.016812700 2896 00000167E9951E40 INFO GST_REGISTRY gstregistry.c:1918:ensure_current_registry: reading registry cache: C:\Users\maxim\AppData\Local\Microsoft\Windows\INetCache\gstreamer-1.0\registry.x86_64-msvc.bin
0:00:00.017856300 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistrybinary.c:626:priv_gst_registry_binary_read_cache: File data at address 00000167EB760000
0:00:00.018359300 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistrybinary.c:535:gst_registry_binary_check_magic: Reading/casting for GstBinaryRegistryMagic at address 00000167EB760000
0:00:00.018967200 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:958:_priv_gst_registry_chunks_load_global_header: Reading/casting for GstRegistryChunkGlobalHeader at 00000167EB760048
0:00:00.019405500 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistrybinary.c:668:priv_gst_registry_binary_read_cache: reading binary registry 76(4c)/1473420
0:00:00.019722800 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:844:_priv_gst_registry_chunks_load_plugin: Reading/casting for GstRegistryChunkPluginElement at address 00000167EB760050
0:00:00.020056800 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:865:_priv_gst_registry_chunks_load_plugin: read strings for name=‘accurip’
0:00:00.020379100 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:866:_priv_gst_registry_chunks_load_plugin: desc.description=‘Computes an AccurateRip CRC’
0:00:00.020694800 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:867:_priv_gst_registry_chunks_load_plugin: filename=‘H:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstaccurip.dll’
0:00:00.021009400 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:868:_priv_gst_registry_chunks_load_plugin: desc.version=‘1.24.1’
0:00:00.021330400 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:869:_priv_gst_registry_chunks_load_plugin: desc.license=‘LGPL’
0:00:00.021643600 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:870:_priv_gst_registry_chunks_load_plugin: desc.source=‘gst-plugins-bad’
0:00:00.021959500 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:871:_priv_gst_registry_chunks_load_plugin: desc.package=‘GStreamer Bad Plug-ins source release’
0:00:00.022287400 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:872:_priv_gst_registry_chunks_load_plugin: desc.origin=‘Unknown package origin’
0:00:00.022600200 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:873:_priv_gst_registry_chunks_load_plugin: desc.datetime=2024-03-21
0:00:00.022918900 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistry.c:477:gst_registry_add_plugin: adding plugin 00000167E996F8C0 for filename “H:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstaccurip.dll”
0:00:00.023351700 2896 00000167E9951E40 LOG GST_REGISTRY gstregistry.c:490:gst_registry_add_plugin: emitting plugin-added for filename “H:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstaccurip.dll”
0:00:00.024001300 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistrychunks.c:899:_priv_gst_registry_chunks_load_plugin: Added plugin ‘accurip’ plugin with 1 features from binary registry
0:00:00.024399800 2896 00000167E9951E40 DEBUG GST_REGISTRY gstregistrychunks.c:589:gst_registry_chunks_load_feature: Plugin ‘accurip’ feature ‘accurip’ typename : ‘GstElementFactory’
0:00:00.024860300 2896 00000167E9951E40 LOG GST_REGISTRY gstregistrychunks.c:616:gst_registry_chunks_load_feature: Reading/casting for GstRegistryChunkElementFactory at address 00000167EB760148
0:00:00.025314300 2896 00000167E9951E40 DEBUG structure gststructure.c:2297:gst_structure_parse_field: trying field name ‘long-name’
0:00:00.025678600 2896 00000167E9951E40 DEBUG default gstvalue.c:2796:_priv_gst_value_parse_value: trying type name ‘string’
0:00:00.026035600 2896 00000167E9951E40 DEBUG structure gststructure.c:2297:gst_structure_parse_field: trying field name ‘klass’
0:00:00.026419100 2896 00000167E9951E40 DEBUG default gstvalue.c:2796:_priv_gst_value_parse_value: trying type name ‘string’
0:00:00.026773700 2896 00000167E9951E40 DEBUG structure gststructure.c:2297:gst_structure_parse_field: trying field name ‘description’
0:00:00.027127500 2896 00000167E9951E40 DEBUG default gstvalue.c:2796:_priv_gst_value_parse_value: trying type name ‘string’
0:00:00.027536300 2896 00000167E9951E40 DEBUG structure gststructure.c:2297:gst_structure_parse_field: trying field name ‘author’
0:00:00.027887600 2896 00000167E9951E40 DEBUG default gstvalue.c:2796:_priv_gst_value_parse_value: trying type name ‘string’

0:00:11.774846900 2896 00000167E9951E40 LOG GST_EVENT gstevent.c:252:_gst_event_free: freeing event 00000167E9946B00 type reconfigure
0:00:11.775136600 2896 00000167E9951E40 LOG GST_MESSAGE gstmessage.c:306:gst_message_new_custom: source sink: creating new message 00000167EBC82660 structure-change
0:00:11.775451700 2896 00000167E9951E40 DEBUG GST_BUS gstbus.c:340:gst_bus_post: [msg 00000167EBC82660] posting on bus structure-change message: 00000167EBC82660, time 99:99:99.999999999, seq-num 3, element ‘sink’, GstMessageStructureChange, type=(GstStructureChangeType)link, owner=(GstElement)“(GstVideoTestSrc)\ source”, busy=(boolean)false;
0:00:11.775755200 2896 00000167E9951E40 DEBUG bin gstbin.c:3706:gst_bin_handle_message_func: [msg 00000167EBC82660] handling child sink message of type structure-change
0:00:11.776041200 2896 00000167E9951E40 LOG bin gstbin.c:860:message_check: looking at message 00000167EBC82DE0: 1
0:00:11.776395400 2896 00000167E9951E40 DEBUG bin gstbin.c:958:bin_remove_messages:sink:sink deleting message 00000167EBC82DE0 of type structure-change (types 0x00001000)
0:00:11.776677300 2896 00000167E9951E40 LOG GST_MESSAGE gstmessage.c:210:_gst_message_free: finalize message 00000167EBC82DE0, structure-change from sink
0:00:11.776960200 2896 00000167E9951E40 LOG GST_MESSAGE gstmessage.c:210:_gst_message_free: finalize message 00000167EBC82660, structure-change from sink
0:00:11.777241600 2896 00000167E9951E40 DEBUG GST_BUS gstbus.c:381:gst_bus_post: [msg 00000167EBC82660] dropped
0:00:11.777524200 2896 00000167E9951E40 DEBUG GST_ELEMENT_PADS gstutils.c:1951:gst_element_link_pads_full: linked pad source:src to pad sink:sink
start playing
0:00:11.777846500 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:2976:gst_element_set_state_func: set_state to PLAYING
0:00:11.778126800 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3001:gst_element_set_state_func: setting target state to PLAYING
0:00:11.778476800 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3014:gst_element_set_state_func: current NULL, old_pending VOID_PENDING, next VOID_PENDING, old return SUCCESS
0:00:11.778758100 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3048:gst_element_set_state_func: intermediate: setting state from NULL to READY
0:00:11.779037400 2896 00000167E9951E40 DEBUG GST_BUS gstbus.c:505:gst_bus_set_flushing: unset bus flushing
0:00:11.779323100 2896 00000167E9951E40 DEBUG GST_STATES gstbin.c:2839:gst_bin_change_state_func: changing state of children from NULL to READY
0:00:11.779602000 2896 00000167E9951E40 DEBUG bin gstbin.c:2876:gst_bin_change_state_func: clearing all cached messages
0:00:11.779884700 2896 00000167E9951E40 DEBUG bin gstbin.c:2366:gst_bin_sort_iterator_resync: resync
0:00:11.780164400 2896 00000167E9951E40 DEBUG bin gstbin.c:2146:add_to_queue: adding ‘sink’ to queue
0:00:11.780585600 2896 00000167E9951E40 DEBUG bin gstbin.c:882:find_message: no message found matching types 00001000
0:00:11.780866300 2896 00000167E9951E40 DEBUG bin gstbin.c:889:find_message: structure-change
0:00:11.781147900 2896 00000167E9951E40 DEBUG bin gstbin.c:2263:update_degree: change element source, degree 0->1, linked to sink
0:00:11.781430100 2896 00000167E9951E40 DEBUG bin gstbin.c:2286:update_degree: element source not linked on any sinkpads
0:00:11.781711700 2896 00000167E9951E40 DEBUG bin gstbin.c:2353:gst_bin_sort_iterator_next: queue head gives sink
0:00:11.781993400 2896 00000167E9951E40 DEBUG bin gstbin.c:882:find_message: no message found matching types 00001000
0:00:11.782275000 2896 00000167E9951E40 DEBUG bin gstbin.c:889:find_message: structure-change
0:00:11.782556900 2896 00000167E9951E40 DEBUG bin gstbin.c:2263:update_degree: change element source, degree 1->0, linked to sink
0:00:11.782853100 2896 00000167E9951E40 DEBUG bin gstbin.c:2146:add_to_queue: adding ‘source’ to queue
0:00:11.783189700 2896 00000167E9951E40 INFO GST_STATES gstbin.c:2484:gst_bin_element_set_state: current NULL pending VOID_PENDING, desired next READY
0:00:11.783470100 2896 00000167E9951E40 DEBUG bin gstbin.c:882:find_message: no message found matching types 00100000
0:00:11.783749900 2896 00000167E9951E40 DEBUG bin gstbin.c:889:find_message: async-start
0:00:11.784132400 2896 00000167E9951E40 DEBUG bin gstbin.c:2579:gst_bin_element_set_state: setting element sink to READY, base_time 0:00:00.000000000
0:00:11.784517000 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:2976:gst_element_set_state_func: set_state to READY
0:00:11.784799200 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3001:gst_element_set_state_func: setting target state to READY
0:00:11.785111300 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3014:gst_element_set_state_func: current NULL, old_pending VOID_PENDING, next VOID_PENDING, old return SUCCESS
0:00:11.785394400 2896 00000167E9951E40 DEBUG GST_STATES gstelement.c:3048:gst_element_set_state_func: final: setting state from NULL to READY
0:00:11.785854900 2896 00000167E9951E40 DEBUG filesink gstfilesink.c:608:gst_file_sink_do_seek: Seeking to offset 0 using lseek
0:00:11.786246000 2896 00000167E9951E40 DEBUG filesink gstfilesink.c:806:gst_file_sink_flush_buffer: Flushing out buffer of size 0

If you need anything else, just ask. Thank you for your help.

Hello, sorry to be a bother, i don’t need someone to solve this for me, just to know if it’s worth it to continue searching in this direction.

So a simple " I tested and have or do not have the same behavior" would be a great help. Thank you.