我创建了一个管道:
def encoder(name):
pipeline = Gst.Pipeline()
audioin = Gst.ElementFactory.make("appsrc", "audioin")
videoin = Gst.ElementFactory.make("appsrc", "videoin")
h264parse = Gst.ElementFactory.make("h264parse", "h264")
alaw = Gst.ElementFactory.make("rawaudioparse", "alaw")
faac = Gst.ElementFactory.make("faac", "faac")
mux = Gst.ElementFactory.make("mp4mux", "mux")
filesink = Gst.ElementFactory.make("filesink", "fsink")
filesink.set_property("location", name + ".mp4")
videoin.set_property("caps", Gst.caps_from_string('video/x-h264,width=1920,height=1080,framerate=9/1,stream-format=(string)avc'))
audioin.set_property("caps", Gst.caps_from_string('audio/x-alaw,channels=1,rate=8000'))
pipeline.add(videoin)
pipeline.add(audioin)
pipeline.add(alaw)
pipeline.add(faac)
pipeline.add(h264parse)
pipeline.add(mux)
pipeline.add(filesink)
audioin.link(alaw)
videoin.link(h264parse)
h264parse.link(mux)
alaw.link(faac)
faac.link(mux)
mux.link(filesink)
return pipeline, audioin, videoin
pipeline, audioin, videoin = encoder('filename')
在这里,我从 reader.video、reader.audio 接收数据并将其推入缓冲区
async def convert(reader):
async def readforever(stream, cb):
while not stream.at_eof():
cb(await stream.read(2048))
def push(src):
def pushbuffer(data):
print(rotating(), len(data), ' ', end="\r", flush=True)
buf = Gst.Buffer.new_allocate(None, len(data), None)
buf.fill(0, data)
src.emit('push-buffer', buf)
return True
return pushbuffer
pipeline.set_state(Gst.State.PLAYING)
print('started')
await asyncio.gather(readforever(reader.video, push(videoin)), readforever(reader.audio, push(audioin)))
videoin.emit("end-of-stream")
audioin.emit("end-of-stream")
print(pipeline)
bus = pipeline.get_bus()
print(await reader.picture.read())
print(await reader.bort.read())
print('eos')
#bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.EOS) # зависает
pipeline.set_state(Gst.State.NULL)
gstreamer 日志说数据已经到达,但文件中没有任何内容。
需要发出错误警告https://bugzilla.gnome.org/show_bug.cgi?id=659489
并将传入的流通过队列