使用 GStreamer 和 GStreamer 进行视频过渡GNonLin 不工作

发布于 2024-11-27 08:47:04 字数 3708 浏览 1 评论 0原文

我一直在尝试将 2 个视频与 gstreamer 结合在一起 使用 gstreamer 和 gstreamer 在它们之间进行短转换(如 smpte) python 中的 gnonlin。但是我无法让 gnloperation/smpte 转换正常工作。

目标

下面是一个程序。我希望它播放一个文件的前 4 秒,并在 2 秒处开始对另一个文件进行 smpte 过渡(持续 2 秒)。 (因此第二个文件将在整个过程中开始播放 2 秒,但在 2 秒转换过程中“显示”),转换完成后,应显示第二个文件本身的 2 秒。

这是基于Python 中的另一个 gstreamer/gnonlin 脚本。我在 gstreamer-devel 列表上提出了这个问题(和再次),我在这里尝试。

问题

转换未完成。过渡运行大约 0.5 秒,然后视频 1 播放约 1.5 秒,然后视频 2 切入。我尝试更改控制器的结束位置(例如,更改为 controller.set("position", 0.5 * gst.SECOND, 0.0)),以及 转换在 0.5 秒内完成,但转换完成后,视频 1 会再次开始播放一段时间,然后视频 2 开始播放。

考虑到视频过渡可能被限制为 0.5 秒,我将 gnloperation 更改为 0.5 秒,但是同样的非完成问题仍然存在,除了过渡仅播放约 0.3 秒,并且视频 1 的部分方式开始一会儿,然后播放视频 2。

脚本

#! /usr/bin/python
import gst, gobject
gobject.threads_init()

comp  = gst.element_factory_make("gnlcomposition", "composition")

gsrc1 = gst.element_factory_make("gnlfilesource")
gsrc1.props.location = "file:///home/rory/helmetcam/dingle-tom/vshort01.mov"
gsrc1.props.start          = 0
gsrc1.props.duration       = 4 * gst.SECOND
gsrc1.props.media_start    = 0
gsrc1.props.media_duration = 4 * gst.SECOND
gsrc1.props.priority       = 3
comp.add(gsrc1)


gsrc2 = gst.element_factory_make("gnlfilesource")
gsrc2.props.location = "file:///home/rory/helmetcam/dingle-tom/vshort02.mov"
gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 6 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 2 * gst.SECOND
gsrc2.props.priority       = 2
comp.add(gsrc2)


bin = gst.Bin()
alpha1 = gst.element_factory_make("alpha")
queue = gst.element_factory_make("queue")
smpte  = gst.element_factory_make("smptealpha")
smpte.props.type = 21
mixer  = gst.element_factory_make("videomixer")

bin.add(alpha1, queue, smpte, mixer)
alpha1.link(mixer)
queue.link(smpte)
smpte.link(mixer)

controller = gst.Controller(smpte, "position")
controller.set_interpolation_mode("position", gst.INTERPOLATE_LINEAR)
controller.set("position", 0, 1.0)
controller.set("position", 2.0 * gst.SECOND, 0.0)

bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink")))
bin.add_pad(gst.GhostPad("sink2", queue.get_pad("sink")))
bin.add_pad(gst.GhostPad("src",   mixer.get_pad("src")))

op = gst.element_factory_make("gnloperation")
op.add(bin)
op.props.start          = 2 * gst.SECOND
op.props.duration       = 2 * gst.SECOND
op.props.media_start    = 0
op.props.media_duration = 2 * gst.SECOND
op.props.priority       = 1
comp.add(op)

# create the backend
color= gst.element_factory_make("ffmpegcolorspace")
enc = gst.element_factory_make("theoraenc")
mux = gst.element_factory_make("oggmux")
sink = gst.element_factory_make("filesink")
sink.props.location = "./transitions-between-two.ogv"
pipeline = gst.Pipeline()
pipeline.add(comp, color, enc, mux, sink)
color.link(enc)
enc.link(mux)
mux.link(sink)

def on_pad(comp, pad, elements):
    convpad = elements.get_compatible_pad(pad, pad.get_caps())
    pad.link(convpad)
comp.connect("pad-added", on_pad, color)

# now run the pipeline
loop = gobject.MainLoop(is_running=True)
bus = pipeline.get_bus()
bus.add_signal_watch()
def on_message(bus, message, loop):
    if message.type == gst.MESSAGE_EOS:
        loop.quit()
    elif message.type == gst.MESSAGE_ERROR:
        print message
        loop.quit()
bus.connect("message", on_message, loop)
pipeline.set_state(gst.STATE_PLAYING)
loop.run()
pipeline.set_state(gst.STATE_NULL)

I've been trying to combine 2 videos together with gstreamer with a
short transition (like smpte) between them using gstreamer & gnonlin in python. However I can't get the gnloperation/smpte transition to work.

Goal

Below is a programme. I want it to play the first 4 sec of one file, and at 2 sec to start doing a smpte transition (that lasts for 2 seconds) to another file. (so the second file will start playing 2 seconds into the whole thing but be 'revealed' over the course of the 2 second transition), and after the transition is finished, the 2 sec of the 2nd file on it's own should be shown.

This is based on another gstreamer/gnonlin script in python. I have asked this question on the gstreamer-devel list (and again), and am trying here.

Problem

The transition doesn't finish. The transition runs for about 0.5 seconds, then video 1 plays for ~ 1.5 sec and then video 2 cuts in. I've tried changing the end position of the controller (e.g. to controller.set("position", 0.5 * gst.SECOND, 0.0)), and the
transition completes in the 0.5 sec, but as soon as the transition finish, video 1 starts playing again for a little bit, then video 2 starts playing.

Thinking that maybe the video transition is limited to 0.5 sec, I changed the gnloperation to 0.5 sec, however the same non-finishing problem persists, except that the transition only plays for about 0.3 sec, and part of the way through video 1 kicks in for a little bit, and then video 2 plays.

Script

#! /usr/bin/python
import gst, gobject
gobject.threads_init()

comp  = gst.element_factory_make("gnlcomposition", "composition")

gsrc1 = gst.element_factory_make("gnlfilesource")
gsrc1.props.location = "file:///home/rory/helmetcam/dingle-tom/vshort01.mov"
gsrc1.props.start          = 0
gsrc1.props.duration       = 4 * gst.SECOND
gsrc1.props.media_start    = 0
gsrc1.props.media_duration = 4 * gst.SECOND
gsrc1.props.priority       = 3
comp.add(gsrc1)


gsrc2 = gst.element_factory_make("gnlfilesource")
gsrc2.props.location = "file:///home/rory/helmetcam/dingle-tom/vshort02.mov"
gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 6 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 2 * gst.SECOND
gsrc2.props.priority       = 2
comp.add(gsrc2)


bin = gst.Bin()
alpha1 = gst.element_factory_make("alpha")
queue = gst.element_factory_make("queue")
smpte  = gst.element_factory_make("smptealpha")
smpte.props.type = 21
mixer  = gst.element_factory_make("videomixer")

bin.add(alpha1, queue, smpte, mixer)
alpha1.link(mixer)
queue.link(smpte)
smpte.link(mixer)

controller = gst.Controller(smpte, "position")
controller.set_interpolation_mode("position", gst.INTERPOLATE_LINEAR)
controller.set("position", 0, 1.0)
controller.set("position", 2.0 * gst.SECOND, 0.0)

bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink")))
bin.add_pad(gst.GhostPad("sink2", queue.get_pad("sink")))
bin.add_pad(gst.GhostPad("src",   mixer.get_pad("src")))

op = gst.element_factory_make("gnloperation")
op.add(bin)
op.props.start          = 2 * gst.SECOND
op.props.duration       = 2 * gst.SECOND
op.props.media_start    = 0
op.props.media_duration = 2 * gst.SECOND
op.props.priority       = 1
comp.add(op)

# create the backend
color= gst.element_factory_make("ffmpegcolorspace")
enc = gst.element_factory_make("theoraenc")
mux = gst.element_factory_make("oggmux")
sink = gst.element_factory_make("filesink")
sink.props.location = "./transitions-between-two.ogv"
pipeline = gst.Pipeline()
pipeline.add(comp, color, enc, mux, sink)
color.link(enc)
enc.link(mux)
mux.link(sink)

def on_pad(comp, pad, elements):
    convpad = elements.get_compatible_pad(pad, pad.get_caps())
    pad.link(convpad)
comp.connect("pad-added", on_pad, color)

# now run the pipeline
loop = gobject.MainLoop(is_running=True)
bus = pipeline.get_bus()
bus.add_signal_watch()
def on_message(bus, message, loop):
    if message.type == gst.MESSAGE_EOS:
        loop.quit()
    elif message.type == gst.MESSAGE_ERROR:
        print message
        loop.quit()
bus.connect("message", on_message, loop)
pipeline.set_state(gst.STATE_PLAYING)
loop.run()
pipeline.set_state(gst.STATE_NULL)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角迷惘 2024-12-04 08:47:04

看起来问题出在第二个源文件的属性中。

而不是:

gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 6 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 2 * gst.SECOND
gsrc2.props.priority       = 2

尝试:

gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 4 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 4 * gst.SECOND
gsrc2.props.priority       = 2

这似乎对我来说按预期工作。

It looks like the problem is in the properties of your second source file.

in stead of:

gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 6 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 2 * gst.SECOND
gsrc2.props.priority       = 2

try:

gsrc2.props.start          = 2 * gst.SECOND
gsrc2.props.duration       = 4 * gst.SECOND
gsrc2.props.media_start    = 0
gsrc2.props.media_duration = 4 * gst.SECOND
gsrc2.props.priority       = 2

This seems to work as expected for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文