我正在尝试创建一个非常不寻常的程序,需要视频从一个剪辑到另一个剪辑顺利播放,而不会闪烁。此时,在流的末尾,我将路径更改为下一个剪辑并将其设置为再次播放。这很有效,除了两者之间的小眨眼,这不是最佳的。
我想通过在视频片段之间创建过渡来摆脱这种情况。但是,由于缺乏GStreamer的Python教程......我该怎么做?
我正在使用Python 2.7,PyGTK 2.24和GStreamer。
这是我目前的代码:
import pygtk
pygtk.require('2.0')
import gtk, pango
import pygst
pygst.require('0.10')
import gst
import Trailcrest
import os, sys
class Video:
def __init__(self):
def on_message(bus, message):
if message.type == gst.MESSAGE_EOS:
# End of Stream
player.set_state(gst.STATE_NULL)
player.set_property("uri", "file://" + os.getcwd() + "/VID/BGA-AMB-HABT-001.ogv")
player.set_state(gst.STATE_PLAYING)
elif message.type == gst.MESSAGE_ERROR:
player.set_state(gst.STATE_NULL)
(err, debug) = message.parse_error()
print "Error: %s" % err, debug
def on_sync_message(bus, message):
if message.structure is None:
return False
if message.structure.get_name() == "prepare-xwindow-id":
gtk.gdk.threads_enter()
gtk.gdk.display_get_default().sync()
win_id = videowidget.window.xid
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)
gtk.gdk.threads_leave()
win = gtk.Window()
win.set_resizable(False)
win.set_has_frame(False)
win.set_position(gtk.WIN_POS_CENTER)
fixed = gtk.Fixed()
win.add(fixed)
fixed.show()
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size("IMG/IMG-AMB-HABT-001.png", 640, 480)
pixbuf = pixbuf.scale_simple(640, 480, gtk.gdk.INTERP_BILINEAR)
pixmap, mask = pixbuf.render_pixmap_and_mask()
img = gtk.Image()
img.set_from_pixmap(pixmap, mask)
fixed.put(img, 0, 0)
img.show()
videowidget = gtk.DrawingArea()
fixed.put(videowidget, 0, 0)
videowidget.set_size_request(640, 480)
videowidget.show()
# Setup GStreamer
player = gst.element_factory_make("playbin", "MultimediaPlayer")
bus = player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
#used to get messages that GStreamer emits
bus.connect("message", on_message)
#used for connecting video to your application
bus.connect("sync-message::element", on_sync_message)
player.set_property("uri", "file://" + os.getcwd() + "/VID/BGA-AMB-HABT-001.ogv")
player.set_state(gst.STATE_PLAYING)
win.show()
def main():
gtk.gdk.threads_init()
gtk.main()
return 0
if __name__ == "__main__":
Video()
main()