grijalvaromero
grijalvaromero

Reputation: 599

Play mp4 video with python and gstreamer

I'm trying to play video in mp4 format but not working.

In console I execute this line and it works:

gst-launch playbin uri=rtmp://localhost:1935/files/video.mp4

But if I change to version 1.0 only works the audio:

gst-launch-1.0 playbin uri=rtmp://localhost:1935/files/video.mp4 

in python I have the following code:

       self.player = Gst.Pipeline.new("player")
    source = Gst.ElementFactory.make("filesrc", "file-source")
    demuxer = Gst.ElementFactory.make("mp4mux", "demuxer")
    demuxer.connect("pad-added", self.demuxer_callback)
    self.video_decoder = Gst.ElementFactory.make("x264enc", "video-decoder")
    self.audio_decoder = Gst.ElementFactory.make("vorbisdec", "audio-decoder")
    audioconv = Gst.ElementFactory.make("audioconvert", "converter")
    audiosink = Gst.ElementFactory.make("autoaudiosink", "audio-output")
    videosink = Gst.ElementFactory.make("autovideosink", "video-output")
    self.queuea = Gst.ElementFactory.make("queue", "queuea")
    self.queuev = Gst.ElementFactory.make("queue", "queuev")
    colorspace = Gst.ElementFactory.make("videoconvert", "colorspace")

        self.player.add(source) 
        self.player.add(demuxer) 
        self.player.add(self.video_decoder) 
        self.player.add(self.audio_decoder) 
        self.player.add(audioconv) 
        self.player.add(audiosink) 
        self.player.add(videosink) 
        self.player.add(self.queuea) 
        self.player.add(self.queuev) 
        self.player.add(colorspace)

        source.link(demuxer)

        self.queuev.link(self.video_decoder)
        self.video_decoder.link(colorspace)
        colorspace.link(videosink)

        self.queuea.link(self.audio_decoder)
        self.audio_decoder.link(audioconv)
        audioconv.link(audiosink)

but I get this error: Error: Error in the internal data flow. gstbasesrc.c(2865): gst_base_src_loop (): /GstPipeline:player/GstFileSrc:file-source: streaming task paused, reason not-linked (-1)

What can be happening? think I am no good decoding

Upvotes: 0

Views: 2857

Answers (2)

Beirdo
Beirdo

Reputation: 424

You have in your code:

demuxer = Gst.ElementFactory.make("mp4mux", "demuxer")
demuxer.connect("pad-added", self.demuxer_callback)

I hope this is a cut/paste error, as demuxing with a mux will not work. I believe for an .mp4 file, the normal demuxer (if you are choosing one by hand) is qtdemux.

You could also use decodebin to decode the file for you.

Upvotes: 0

thiagoss
thiagoss

Reputation: 2094

You are missing linking the demuxer pads to your queues. Demuxers have 'sometimes' pads so you need to listen to the pad-added signal of them and link in this callback. Remember to check the pad caps once you get them and link to the appropriate branch of your pipeline.

You can read about dynamic pads here: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-pads.html#section-pads-dynamic

Upvotes: 1

Related Questions