1
我正在嘗試創建一個非常不尋常的程序,它需要視頻才能從一個剪輯順暢地播放到下一個剪輯,而不會閃爍。此時,在流的結尾處,我將路徑更改爲下一個剪輯並將其設置爲再次播放。這個效果很好,除了在兩者之間有一點點眨眼之外,這不是最佳的。GStreamer上的視頻轉換?
我盤算我可以通過創建視頻片段之間的轉換擺脫這一點。但是,由於Python的GStreamer教程缺乏,我該怎麼做?
我使用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()
爲什麼你需要* python *教程?我想這只是圖書館週圍的一個小型python包裝。 –
如果趨勢一直存在,我將需要一個基於python的教程,因爲Python本質上與C非常不同,並且因爲PyGST有時有不同的處理方式。 – CodeMouse92
此外,我需要它與PyGTK的上下文。 – CodeMouse92