Terminate pipeline after fixed time

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Terminate pipeline after fixed time

GStreamer-devel mailing list
I am trying to composite multiple videos and then filesink them in C application. I wanted to know how to terminate the pipeline after a fixed time (say 10s). I tried using the GST_MESSAGE_DURATION event and terminating from there, but the file is created but not written to. I think I need to somehow signal to the file sink element to flush the data before termination.

Any help would be appreciated. Thanks!

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Terminate pipeline after fixed time

GStreamer-devel mailing list
If you don’t need buffer-level precision, you can try using g_timeout_add_seconds. That will allow you to install a callback that will be invoked after N seconds. From there you can stop the pipeline.

Michael

> On 9 Jun 2021, at 02:40, Vinayak Agarwal via gstreamer-devel <[hidden email]> wrote:
>
> I am trying to composite multiple videos and then filesink them in C application. I wanted to know how to terminate the pipeline after a fixed time (say 10s). I tried using the GST_MESSAGE_DURATION event and terminating from there, but the file is created but not written to. I think I need to somehow signal to the file sink element to flush the data before termination.
>
> Any help would be appreciated. Thanks!
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Terminate pipeline after fixed time

GStreamer-devel mailing list
To be specific, I was looking for advice on how to stop the pipeline
correctly. If I directly set the pipeline state to null and then terminate,
the pipeline is set to null but the file size is still 0 bytes (I am trying
to filesink). Not sure what I'm doing wrong. For reference, here is the
relevant code:

msg = gst_bus_timed_pop_filtered (bus, 100000000 * GST_MSECOND,
        GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS |
GST_MESSAGE_DURATION);

switch (GST_MESSAGE_TYPE (msg)) {
        case GST_MESSAGE_DURATION:
            gst_element_set_state (videoCompositor.pipeline,
GST_STATE_NULL);
          break;
}

Full code: (used tutorial boilerplate code) https://pastebin.com/8uusk7q6




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Terminate pipeline after fixed time

GStreamer-devel mailing list
Try sending an EOS to the pipeline after your required timeout.

gst_element_send_event (pipeline, gst_event_new_eos ());

Wait for the EOS and then set the pipeline state to NULL.

On 21-06-09 12:27:20, va6996 via gstreamer-devel wrote:

> To be specific, I was looking for advice on how to stop the pipeline
> correctly. If I directly set the pipeline state to null and then terminate,
> the pipeline is set to null but the file size is still 0 bytes (I am trying
> to filesink). Not sure what I'm doing wrong. For reference, here is the
> relevant code:
>
> msg = gst_bus_timed_pop_filtered (bus, 100000000 * GST_MSECOND,
>         GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS |
> GST_MESSAGE_DURATION);
>
> switch (GST_MESSAGE_TYPE (msg)) {
>         case GST_MESSAGE_DURATION:
>             gst_element_set_state (videoCompositor.pipeline,
> GST_STATE_NULL);
>           break;
> }
>
> Full code: (used tutorial boilerplate code) https://pastebin.com/8uusk7q6
>
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

--
Regards,
Sanchayan.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Terminate pipeline after fixed time

GStreamer-devel mailing list


Here is my code. Even though I am sending an EOS and then setting the
pipeline to null, the file that is saved is not playable for some reason.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Terminate pipeline after fixed time

GStreamer-devel mailing list
Sorry the code was not posted in the last msg.

Code:
#include <stdio.h>
#include <string.h>
#include <gst/gst.h>
#include <glib.h>

gboolean callback(gpointer data)
{
    GstElement *pipeline = (GstElement *)data;
    GstElement *imagefreeze = gst_bin_get_by_name(GST_BIN(pipeline),
"imagefreeze");
    // send eos but doesnt work for some reason
    gst_element_send_event (pipeline, gst_event_new_eos ());

    // another version that works
    GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_post(bus, gst_message_new_eos(GST_OBJECT(imagefreeze)));
    gst_object_unref(bus);
    // // custom message is recieved
    // GstMessage *msg = gst_message_new_custom(GST_MESSAGE_ELEMENT,
GST_OBJECT(pipeline), NULL);
    // gst_element_post_message(GST_ELEMENT(pipeline), msg);
    return FALSE;
}

gboolean
bus_call(GstBus *bus, GstMessage *msg, gpointer data)
{
    gchar *debug = NULL;
    GError *err = NULL;

    switch (GST_MESSAGE_TYPE(msg))
    {
    case GST_MESSAGE_EOS:
        g_printerr("eos");
        g_main_loop_quit ((GMainLoop *) data);
        break;
    case GST_MESSAGE_ERROR:
        gst_message_parse_error(msg, &err, &debug);
        g_printerr("Error: %s\n", err->message);
        g_main_loop_quit((GMainLoop *)data);
        break;
    case GST_MESSAGE_STATE_CHANGED:
        break;
    case GST_MESSAGE_ELEMENT:
        g_main_loop_quit((GMainLoop *)data);
        break;
    default:
        g_printerr("Unexpected message type detected! %d %s\n",
GST_MESSAGE_TYPE(msg),gst_message_type_get_name(GST_MESSAGE_TYPE(msg)));
        break;
    }

    return TRUE;
}

int main(int argc, char *argv[])
{
    GMainLoop *loop = g_main_loop_new(NULL, FALSE);
    gst_init(&argc, &argv); // init gstreamer

    GError *err = NULL;
    GstBus *bus;
    GstMessage *msg;
    GstStateChangeReturn ret;
    gboolean terminate = FALSE;

    GstElement *pipeline = gst_parse_launch("filesrc
location=./resources/street.jpg ! decodebin ! imagefreeze
name=\"imagefreeze\" ! videoconvert  ! x264enc ! h264parse ! mp4mux
reserved-moov-update-period=100000 ! filesink location=./file.mp4", &err);

    bus = gst_element_get_bus(pipeline);
    gst_bus_add_watch(bus, bus_call, loop);
    gst_object_unref(bus);
   
    g_timeout_add_seconds(15, callback, pipeline);
   
    gst_element_set_state(pipeline, GST_STATE_PLAYING);
    g_print("run loop\n");
    g_main_loop_run(loop);
    gst_element_set_state(pipeline, GST_STATE_NULL);
    g_print("end loop\n");

    /* Free resources */
    gst_object_unref(pipeline);
    return 0;
}




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel