gstreamer appsrc works for xvimagesink but no in theoraenc ! oggmux

北城以北 提交于 2019-12-02 09:44:01

问题


I am trying to stream cast a computer generated video using gstreamer and icecast, but I cannot get gstreamer appsrc to work. My app works as expected if I use xvimagesink as the sink(see commented code below). But once I pipe it to theoraenc it does not run.

I exchanged shout2send with filesink to check if the problem was icecast, the result is that no data is written to the file. Substituting appsrc with testvideosrc works as expected. Any suggestion?

#!/usr/bin/env python
import sys, os, pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst
import numpy as np

class GTK_Main:
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.connect("destroy", gtk.main_quit, "WM destroy")
        vbox = gtk.VBox()
        window.add(vbox)
        self.button = gtk.Button("Start")
        self.button.connect("clicked", self.start_stop)
        vbox.add(self.button)
        window.show_all()

        self.player = gst.Pipeline("player")
        source = gst.element_factory_make("appsrc", "source")
        caps = gst.Caps("video/x-raw-gray,bpp=16,endianness=1234,width=320,height=240,framerate=(fraction)10/1")
        source.set_property('caps',caps)
        source.set_property('blocksize',320*240*2)
        source.connect('need-data', self.needdata)
        colorspace = gst.element_factory_make('ffmpegcolorspace')
        enc = gst.element_factory_make('theoraenc')
        mux = gst.element_factory_make('oggmux')
        shout = gst.element_factory_make('shout2send')
        shout.set_property("ip","localhost")
        shout.set_property("password","hackme")
        shout.set_property("mount","/stream")
        caps = gst.Caps("video/x-raw-yuv,width=320,height=240,framerate=(fraction)10/1,format=(fourcc)I420")
        enc.caps = caps
        videosink = gst.element_factory_make('xvimagesink')
        videosink.caps = caps

        self.player.add(source, colorspace, enc, mux, shout)
        gst.element_link_many(source, colorspace, enc, mux, shout)
        #self.player.add(source, colorspace, videosink)
        #gst.element_link_many(source, colorspace, videosink)

    def start_stop(self, w):
        if self.button.get_label() == "Start":
            self.button.set_label("Stop")
            self.player.set_state(gst.STATE_PLAYING)
        else:
            self.player.set_state(gst.STATE_NULL)
            self.button.set_label("Start")

    def needdata(self, src, length):
        bytes = np.int16(np.random.rand(length/2)*30000).data
        src.emit('push-buffer', gst.Buffer(bytes))

GTK_Main()
gtk.gdk.threads_init()
gtk.main()

回答1:


I think that your problem is most likely to do with timestamping of the buffers. I've done some quick testing, using that code and replacing the shout element with oggdemux, theoradec, ffmpegcolorspace and ximagesink. At first, I got no output, but after I dispensed with the muxing/demuxing altogether, I got a static image, along with some debug messages about timestamps. I got the correct output after setting the is-live and do-timestamp properties to true on appsrc.

I assume that it should be possible to directly set the timestamps on the buffers that you are pushing out of appsrc, but alas I've not discovered how to do that.



来源:https://stackoverflow.com/questions/7431245/gstreamer-appsrc-works-for-xvimagesink-but-no-in-theoraenc-oggmux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!