def __init__(self, file_loc,fps=30):
super().__init__()
# the approximate capture rate.
self.fps = int(fps)
self.time_base = Fraction(1000,self.fps*1000)
file_loc = str(file_loc) #force str over unicode.
try:
file_path,ext = file_loc.rsplit('.', 1)
except:
logger.error("'{}' is not a valid media file name.".format(file_loc))
raise Exception("Error")
if ext not in ('mp4'):
logger.warning("media file container should be mp4. Using a different container is risky.")
self.file_loc = file_loc
self.container = av.open(self.file_loc,'w')
logger.debug("Opened '{}' for writing.".format(self.file_loc))
self.video_stream = self.container.add_stream('mjpeg',1/self.time_base)
self.video_stream.pix_fmt = "yuvj422p"
self.configured = False
self.frame_count = 0
self.write_video_frame_compressed = self.write_video_frame
评论列表
文章目录