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.