我想将我的计算机与外部摄像机记录同步,这样我就可以准确地(精确到毫秒)知道与计算机记录的其他传感器相关的特定记录事件发生的时间。一种想法是每秒回放来自计算机的短的声音脉冲或啁啾,这些声音被摄像机上的麦克风接收到。但是,播放声音剪辑的简单cron作业的准确性是不够精确的。我正在考虑使用像gstreamer这样的东西,但是如何让它根据系统时钟精确地在某个时间回放剪辑?
发布于 2012-10-31 12:02:41
如果您知道摄像机的开始时间,则可以从捕获的视频流中推导出视频的任意时间。您不需要执行任何这些操作。在容器中,每个帧都有一个与其关联的时间戳,并且可以知道确切的时间。你所需要做的就是记下开场时间。
编辑:另一种方法是:如果你有一个你信任的时钟,你能把它放在摄像机的路径中吗?所以你总是对视频本身有一个衡量标准。
发布于 2012-10-31 21:27:34
这是我解决这个问题的尝试。我修改了http://pygstdocs.berlios.de/pygst-tutorial/playbin.html中的一个gstreamer python tutorial命令行playbin (示例2.3),让它以与系统时钟同步的时间间隔重复播放声音文件。
我已经确保管道使用系统时钟,而不是来自接收器的默认时钟,并禁止管道设置元素的基本时间。然后,随着文件的播放完成,它会返回到开始处,并手动设置基准时间,以便接收器将等待在下一个时期播放缓冲区。
#!/usr/bin/env python
import sys, os
#import time, thread
import glib,gobject
import pygst
pygst.require("0.10")
import gst
class CLI_Main:
def __init__(self):
self.player = gst.element_factory_make("playbin2", "player")
fakesink = gst.element_factory_make("fakesink", "fakesink")
self.player.set_property("video-sink", fakesink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
# use the system clock instead of the sink's clock
self.sysclock = gst.system_clock_obtain()
self.player.use_clock(self.sysclock)
# disable the pipeline from setting element base times
self.player.set_start_time(gst.CLOCK_TIME_NONE)
# default tick interval
self.tick_interval = 1;
self.tick_interval = float(sys.argv[1])
filepath = sys.argv[2]
if os.path.isfile(filepath):
self.playmode = True
self.player.set_property("uri", "file://" + filepath)
current_time = self.sysclock.get_time()
print current_time
play_time = (current_time/long(self.tick_interval*gst.SECOND) + 1) * long(self.tick_interval*gst.SECOND)
print play_time
self.player.set_base_time(play_time)
self.player.set_state(gst.STATE_PLAYING)
print "starting"
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
# compute the next time the sound should be played
current_time = self.sysclock.get_time()
play_time = (current_time/int(self.tick_interval*gst.SECOND) + 1)*int(self.tick_interval*gst.SECOND)
# setup the next time to play the sound and seek it to the beginning
self.player.set_base_time(play_time)
# seek the player so that the sound plays from the beginning
self.player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 0L, gst.SEEK_TYPE_NONE, 0L)
# make sure that the player will play
self.player.set_state(gst.STATE_PLAYING)
#self.playmode = False
print play_time
elif t == gst.MESSAGE_ERROR:
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.playmode = False
mainclass = CLI_Main()
loop = glib.MainLoop()
loop.run()如果代码被破解和凌乱,我很抱歉;我仍然是python的新手。
https://stackoverflow.com/questions/13107636
复制相似问题