简体   繁体   English

Python中的GStreamer计时

[英]GStreamer timing in Python

In my Python program I use GStreamer's playbin in combination with a textoverlay to play a video file and show some text on top of it. 在我的Python程序中,我结合使用GStreamer的playbintextoverlay来播放视频文件并在其上方显示一些文本。 This works fine: If I change the text property of the textoverlay then the new text is shown. 效果很好:如果我更改textoverlaytext属性,则会显示新文本。

But now I want to set the text based on the video's current position/time (like subtitles). 但是现在我想根据视频的当前位置/时间(如字幕)设置文本。

I read about a pipeline's clock, buffer's timestamps, segment-events and external timers which query the current time every x millisecs. 我读到了有关流水线的时钟,缓冲区的时间戳,段事件和外部计时器的信息,它们每x毫秒查询一次当前时间。 But what is the best practice to get informed about time-changes so that I can show the correct text as soon as possible? 但是,什么是通知时变的最佳实践,以便我能尽快显示正确的文本?

The best way to do it really synchronized with the video would be to use something like the cairooverlay element and do the rendering yourself directly inside the pipeline, based on the actual timestamps of the frames. 使其真正与视频同步的最佳方法是使用cairooverlay元素,然后根据帧的实际时间戳直接在管道内部进行渲染。 Or alternatively write your own element for doing that. 或者,您也可以编写自己的元素来执行此操作。

The easiest solution if timing is not needed to be super accurate would be to use the pipeline clock. 如果不需要时序非常精确,最简单的解决方案是使用流水线时钟。 You can get it from the pipeline once it started, and then could create single shot (or periodic) clock ids for the time or interval you want. 您可以在管道启动后从管道中获取它,然后可以为所需的时间或间隔创建单发(或周期性)时钟id。 And then use the async_wait() method on the clock. 然后在时钟上使用async_wait()方法。

To get the clock time that corresponds to eg the position 1 second of the pipeline you would add 1 second (ie 1000000000) to the pipeline's base time. 为了获得与例如流水线位置1秒相对应的时钟时间,您需要在流水线的基础时间上加上1秒(即1000000000)。 You can use that value then when creating the clock ids. 您可以在创建时钟ID时使用该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM