video_processor.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:AMBR 作者: Algomorph 项目源码 文件源码
def __init__(self, args, out_postfix="_out", with_video_output=True):
        self.global_video_offset = 0
        self.flip_video = False
        self.datapath = "./"
        self.__dict__.update(vars(args))
        self.writer = None

        if os.path.exists("settings.yaml"):
            stream = open("settings.yaml", mode='r')
            self.settings = load(stream, Loader=Loader)
            stream.close()
            self.datapath = self.settings['datapath'].replace("<current_user>", getuser())
            print("Processing path: ", self.datapath)
            if 'raw_options' in self.settings:
                raw_options = self.settings['raw_options']
                if self.in_video in raw_options:
                    self.global_video_offset = raw_options[args.in_video]['global_offset']
                    self.flip_video = raw_options[args.in_video]['flip']

        self.cap = None
        self.reload_video()
        print("Processing video file {:s}.".format(self.in_video))

        last_frame = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT) - 1)

        if self.end_with == -1:
            self.end_with = last_frame
        else:
            if self.end_with > last_frame:
                print(("Warning: specified end frame ({:d}) is beyond the last video frame" +
                       " ({:d}). Stopping after last frame.")
                      .format(self.end_with, last_frame))
                self.end_with = last_frame

        print("Frame range: {:d}--{:d}".format(self.start_from, self.end_with))

        if with_video_output:
            if self.out_video == "":
                self.out_video = args.in_video[:-4] + "_" + out_postfix + ".mp4"

            self.writer = cv2.VideoWriter(os.path.join(self.datapath, self.out_video),
                                          cv2.VideoWriter_fourcc('X', '2', '6', '4'),
                                          self.cap.get(cv2.CAP_PROP_FPS),
                                          (int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
                                           int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))),
                                          True)
            self.writer.set(cv2.VIDEOWRITER_PROP_NSTRIPES, cpu_count())
        else:
            self.writer = None

        self.frame = None
        self.cur_frame_number = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号