I have been recording uncompressed videos using Picamera. I am using custom output to capture Presentation timestamps (pts) and Pi-internal clocks time for each frame. Code Below.
import io
import picamera
import time
class PtsOutput(object):
def __init__(self, camera, video_filename, pts_filename, pi_time_filename):
self.camera = camera
self.video_output = io.open(video_filename, 'wb')
self.pts_output = io.open(pts_filename, 'w')
self.pi_time_output = io.open(pi_time_filename, 'w')
self.start_time = None
def write(self, buf):
self.video_output.write(buf)
if self.camera.frame.complete and self.camera.frame.timestamp:
if self.start_time is None:
self.start_time = self.camera.frame.timestamp
self.pts_output.write('# timecode format v2\n')
self.pts_output.write('%f\n' % ((self.camera.frame.timestamp - self.start_time) / 1000.0))
self.pi_time_output.write('# frame write time: %s\n' %time.time())
def flush(self):
self.video_output.flush()
self.pts_output.flush()
self.pi_time_output.flush()
def close(self):
self.video_output.close()
self.pts_output.close()
self.pi_time_output.close()
with picamera.PiCamera() as camera:
camera.resolution = (320,240)
camera.framerate = 30
camera.start_recording(PtsOutput(camera, 'test_30fps.yuv','pts.txt','pi_clock_time.txt'), format='yuv')
camera.start_preview()
camera.wait_recording(60)
camera.stop_recording()
I have multiple questions:
Can I compare the frame capture times according to two clocks ( pi clock & picamera clock). What is the relationship between the two clocks?
What is exact definition of Presentation time frame. Is it time camera takes the image or is it the time it decides to take? or something else?
Which time is more reliable ? time given by picamera or piclock ? I see that inter-frame duration(difference of timestamps of any two consecutive frames) of picamera clock don't differ at all. which seems to good to be true.