1

我想将我的计算机与外部摄像机记录同步,以便我可以准确地知道(以毫秒为单位)何时发生某些记录的事件与计算机记录的其他传感器有关。一种想法是每秒从计算机播放短的声音脉冲或啁啾声,这些声音被摄像机上的麦克风拾取。但是播放声音剪辑的简单 cron 作业的准确性不够精确。我正在考虑使用像 gstreamer 这样的东西,但是如何让它根据系统时钟在特定时间播放剪辑呢?

4

2 回答 2

0

如果您知道摄像机的开始时间,则可以从捕获的视频流中得出视频的任何时间的时间。你不需要做任何这些。每个帧在容器中都有一个与之关联的时间戳,并且可以知道确切的时间。您只需要记下开始墙的时间。

编辑:另一种方法如下:如果你有一个你信任的时钟,你能把它放在摄像机的路径中吗?所以你总是对视频本身有一个衡量标准。

于 2012-10-31T04:02:41.437 回答
0

这是我解决这个问题的尝试。我已经修改了来自http://pygstdocs.berlios.de/pygst-tutorial/playbin.html的 gstreamer python 教程命令行 playbin(示例 2.3)之一,以与系统时钟同步的定义间隔重复播放声音文件。

我确保管道使用系统时钟而不是接收器的默认时钟,并禁止管道设置元素的基本时间。然后在播放完文件后,它会回到开头,并手动设置基准时间,以便接收器在下一个 epoch 等待播放缓冲区。

#!/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 还是很陌生。

于 2012-10-31T13:27:34.360 回答