gstreamer flush filesink from c++

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

gstreamer flush filesink from c++

xargon
I have this gstreamer pipeline which works from the coomand line as:

gst-launch-1.0 autovideosrc ! tee name = t ! queue ! omxh264enc ! 'video/x-h264, stream-format=(string)byte-stream' ! h264parse ! qtmux ! filesink name=fileSink location=test.mp4 t. ! queue ! videoscale ! video/x-raw, width=480,height=270 ! xvimagesink name=displaySink -e

Now, I am replicating this on the C++ side as follows:

GstElement * pipeline = gst_parse_launch("autovideosrc ! tee name = t ! "
                        "queue ! omxh264enc ! video/x-h264, "
                        "stream-format=(string)byte-stream ! h264parse ! "
                        "qtmux ! filesink name=fileSink location=test.mp4 t. "
                        "! queue ! videoscale ! video/x-raw, width=480,height=270 ! "
                        "xvimagesink name=displaySink", &error);

I connect this to a QT window and play as follows:

    GstElement * displaySink = gst_bin_get_by_name (GST_BIN (pipeline), "displaySink");
    qDebug() << displaySink;
    // prepare the ui
    QWidget window;
    window.resize(480, 270);
    window.show();
    
    WId xwinid = window.winId();
    gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY(displaySink), xwinid);
    
    // run the pipeline
    qDebug() << "Calling run...";
    
    GstStateChangeReturn sret = gst_element_set_state (pipeline,
                                                       GST_STATE_PLAYING);
    if (sret == GST_STATE_CHANGE_FAILURE) {
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
        // Exit application
        QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
    }
    
    int ret = app.exec();
    
    window.hide();
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);

This starts displaying the video stream onto my Qt window and the file test.mp4 gets created and it starts to grow in size. However, when I quit the application, the file is not playable. I have a feeling this is because the last bits or some header information is not written due to me calling:

gst_element_set_state (pipeline, GST_STATE_NULL);

Is there a way to ensure that EOF or EOS is called on the pipeline before closing and ensuring that the file is written properly? This is also a speculation at the moment from my part but something else could be wrong...