简体   繁体   中英

How to play avi video using GStreamer

I am trying to play my first video in GSTreamer, by using GstElement, without pre-configured things like gst_parse_launch etc

  • I dont understand why my pipeline cant be linked and I get an error "unable to set the pipeline to playing state" ?
  • How can I fix it? What is missed?
#include <iostream>
#include <gst/gst.h>

int main(int   argc,    char *argv[])
{
    GstElement *pipeline;
    GstElement *source, *sink;

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

    pipeline = gst_pipeline_new("my-pipeline"); //! Creating pipeline

    source = gst_element_factory_make("filesrc", "file-source"); //! Creating source
    g_object_set(G_OBJECT(source), "location", "file:///D:/workspace/rocket.mp4", NULL);

    sink = gst_element_factory_make("autovideosink", "sink"); //! Creating sink
    if (sink == NULL) 
    {
        g_error("Could not create neither 'autovideosink' element");
    }

    gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL); //! Adding elements to pipeline container

    
    if (!gst_element_link_many(source, sink, NULL))  //! Linking all elements together
    {
        g_warning("Unable to link elements!");
    }

    auto ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); //! Turning pipeline in PLAYING STATE

    if (ret == GST_STATE_CHANGE_FAILURE) 
    {
        g_printerr("unable to set the pipeline to playing state");
        gst_object_unref(pipeline);
        return -1;
    }
    
    return 0;
}

Thanks in advance!

Try to change "file:///D:/workspace/rocket.mp4" to "D:/workspace/rocket.mp4". And also maybe you need to change gst_element_link_many(source, sink, NULL) to gst_element_link(source, sink).

Here is an answer

First of all, here is github link to my solution with comments.


Explanation:

If you want to play video file, without predefined pipelines, like playbin , gst_parse_launch etc, you have two options

  1. Dynamically link uridecodebin with 2 pipeline sleeves (one for audio and second for video)
  2. Dynamically link by using avidemux and make it on 'atomic' level. Its very complicated, and there is no working help in net. Maybe I will update this branch later with working solution.

In my github link, you will find first solution with 2 pipelines and uridecodebin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM