在python中的GStreamer管道中动态调整图像大小

时间:2014-08-14 06:49:30

标签: python dynamic gstreamer pipeline

我正在尝试创建一个程序,可以同时对不同的图像进行各种动画,我想要实现的效果之一是放大图片,这是通过保持固定大小的基本帧和图像大小来增加和减少。但是,当我尝试动态更改图像的大小时,它会导致错误,我尝试在网上搜索,但无法找到正确的解决方案。以下是我的代码。任何人都可以建议我正确的例子,我可以从中学到它将不胜感激(最好是python示例)。

#!/usr/bin/python
import gobject
import time

gobject.threads_init()
import pygst

pygst.require("0.10")
import gst

p = gst.parse_launch("""uridecodebin uri=file:///home/jango/Pictures/3.jpg name=src1 ! queue ! videoscale ! ffmpegcolorspace !
imagefreeze ! capsfilter name=vfps caps="video/x-raw-yuv, framerate=60/1, width=200, height=150" ! mix.
    uridecodebin uri=file:///home/jango/Pictures/2.jpg name=src2 ! queue ! videoscale ! ffmpegcolorspace !
    imagefreeze ! video/x-raw-yuv, framerate=60/1, width=200, height=150 ! mix.
uridecodebin uri=file:///home/jango/Pictures/1.jpg name=src ! queue ! videoscale ! ffmpegcolorspace !
imagefreeze ! video/x-raw-yuv, framerate=60/1, width=200, height=150 ! mix.
uridecodebin uri=file:///home/jango/Pictures/mia_martine.jpg ! queue ! videoscale ! ffmpegcolorspace !
imagefreeze ! video/x-raw-yuv, framerate=60/1, width=200, height=150 ! mix.
uridecodebin uri=file:///home/jango/Pictures/4.jpg ! queue ! videoscale ! ffmpegcolorspace !
imagefreeze ! video/x-raw-yuv, framerate=60/1, width=200, height=150 ! mix.
uridecodebin uri=file:///home/jango/Pictures/mia_marina1.jpg ! queue ! videoscale ! ffmpegcolorspace !
imagefreeze ! video/x-raw-yuv, framerate=60/1, width=200, height=150 ! mix.
    videotestsrc pattern=2 ! video/x-raw-yuv, framerate=10/1, width=1024, height=768 ! videomixer name=mix sink_6::zorder=0 ! ffmpegcolorspace ! theoraenc ! oggmux name=mux !
    filesink location=1.ogg
    filesrc location=/home/jango/Music/mp3/flute_latest.mp3 ! decodebin ! audioconvert ! vorbisenc ! queue ! mux.
""")

m = p.get_by_name("mix")
s0 = m.get_pad("sink_0")
s0.set_property("zorder", 1)
q = s0.get_caps()
q.make_writable()

control11 = gst.Controller.props
control = gst.Controller(s0, "ypos", "alpha", "xpos")
control.set_interpolation_mode("ypos", gst.INTERPOLATE_LINEAR)
control.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control.set("ypos", 0, 0)
control.set("ypos", 5 * gst.SECOND, 600)
control.set("xpos", 0, 0)
control.set("xpos", 5 * gst.SECOND, 500)
control.set("alpha", 0, 0)
control.set("alpha", 5 * gst.SECOND, 1.0)

s1 = m.get_pad("sink_1")
s1.set_property("zorder", 2)


control1 = gst.Controller(s1, "xpos", "alpha")
control1.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control1.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control1.set("xpos", 0, 0)
control1.set("xpos", 5 * gst.SECOND, 500)
control1.set("alpha", 0, 0)
control1.set("alpha", 5 * gst.SECOND, 1.0)
#

s2 = m.get_pad("sink_2")
s2.set_property("zorder", 3)

control2 = gst.Controller(s2, "ypos", "alpha", "xpos")
control2.set_interpolation_mode("ypos", gst.INTERPOLATE_LINEAR)
control2.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control2.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control2.set("xpos", 0, 0)
control2.set("xpos", 5 * gst.SECOND, 500)
control2.set("ypos", 0, 0)
control2.set("ypos", 5 * gst.SECOND, 300)
control2.set("alpha", 0, 0)
control2.set("alpha", 5 * gst.SECOND, 1.0)

s3 = m.get_pad("sink_3")
s3.set_property("zorder", 4)

control3 = gst.Controller(s3, "ypos", "alpha", "xpos")
control3.set_interpolation_mode("ypos", gst.INTERPOLATE_LINEAR)
control3.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control3.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control3.set("ypos", 0, 0)
control3.set("ypos", 5 * gst.SECOND, 600)
control3.set("xpos", 0, 0)
control3.set("xpos", 5 * gst.SECOND, 200)
control3.set("alpha", 0, 0)
control3.set("alpha", 5 * gst.SECOND, 1.0)

s4 = m.get_pad("sink_4")
s4.set_property("zorder", 5)

control4 = gst.Controller(s4, "ypos", "alpha", "xpos")
control4.set_interpolation_mode("ypos", gst.INTERPOLATE_LINEAR)
control4.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control4.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control4.set("ypos", 0, 0)
control4.set("ypos", 5 * gst.SECOND, 300)
control4.set("xpos", 0, 0)
control4.set("xpos", 5 * gst.SECOND, 200)
control4.set("alpha", 0, 0)
control4.set("alpha", 5 * gst.SECOND, 1.0)

s5 = m.get_pad("sink_5")
s5.set_property("zorder", 6)

control5 = gst.Controller(s5, "ypos", "alpha", "xpos")
control5.set_interpolation_mode("ypos", gst.INTERPOLATE_LINEAR)
control5.set_interpolation_mode("alpha", gst.INTERPOLATE_LINEAR)
control5.set_interpolation_mode("xpos", gst.INTERPOLATE_LINEAR)
control5.set("ypos", 0, 0)
control5.set("ypos", 5 * gst.SECOND, 0)
control5.set("xpos", 0, 0)
control5.set("xpos", 5 * gst.SECOND, 200)
control5.set("alpha", 0, 0)
control5.set("alpha", 5 * gst.SECOND, 1.0)

p.set_state(gst.STATE_PLAYING)
time.sleep(3)
p.set_state(gst.STATE_READY)
m = p.get_by_name("mix")
s0 = m.get_pad("sink_0")
q = s0.get_caps()
print q
if q.is_fixed():
    print "not doable"
else:
    caps = gst.caps_from_string("video/x-raw-yuv, framerate=60/1, width=1000, height=1000")
    s0.set_caps(caps)
p.set_state(gst.STATE_PLAYING)
gobject.MainLoop().run()

如果有人能为python开发人员提供GStreamer教程的良好学习点,那将是很棒的。

1 个答案:

答案 0 :(得分:2)

您可以动态更改图像大小,但为此您必须具备某些条件

首先,您的管道应该像这个源一样构建!视频! ffvideoscale!色彩空间 ! capsfilter caps =“caps”....

其次在python中,你从capsfilters元素获得了caps属性,并且你用大写字母改变了分辨率。

这应该有效,警告我是否记得你必须在分辨率变化之间添加一个超过100毫秒的gobject.timeout_add。