def __call__(self, *args, **kwargs): try: os.makedirs(self.output_path) except Exception as e: logger.debug(e) pass sequence = ffmpeg.extract(path=self.video_path) try: for frame, image in enumerate(sequence): if frame % 100 == 0: logger.debug("Decoding frames {0} to {1}".format( frame, frame + 100)) if not self.no_resize: image.thumbnail((self.width, self.height), Image.BILINEAR) path = Video.getframepath(int(frame), self.output_path) try: image.save(path) except IOError as e: logger.debug(e) os.makedirs(os.path.dirname(path)) image.save(path) except: if not self.no_cleanup: logger.error("Aborted. Cleaning up...") shutil.rmtree(self.output_path) raise
def __call__(self, args): try: os.makedirs(args.output) except: pass sequence = [] if args.image_dir: sequence = self.sequencefromdir(args.video) else: sequence = ffmpeg.extract(args.video) try: for frame, image in enumerate(sequence): if frame % 100 == 0: print("Decoding frames {0} to {1}".format( frame, frame + 100)) if not args.no_resize: try: image.thumbnail((args.width, args.height), Image.BILINEAR) except IOError: print "ERROR: resizing image {0}".format(frame) path = Video.getframepath(frame, args.output) try: image.save(path) except IOError: os.makedirs(os.path.dirname(path)) image.save(path) except: if not args.no_cleanup: print "Aborted. Cleaning up..." shutil.rmtree(args.output) raise
def __call__(self, args): try: os.makedirs(args.output) except: pass sequence = [] if args.image_dir: sequence = self.sequencefromdir(args.video) else: sequence = ffmpeg.extract(args.video) try: for frame, image in enumerate(sequence): if frame % 100 == 0: print ("Decoding frames {0} to {1}" .format(frame, frame + 100)) if not args.no_resize: try: image.thumbnail((args.width, args.height), Image.BILINEAR) except IOError: print "ERROR: resizing image {0}".format(frame) path = Video.getframepath(frame, args.output) try: image.save(path) except IOError: os.makedirs(os.path.dirname(path)) image.save(path) except: if not args.no_cleanup: print "Aborted. Cleaning up..." shutil.rmtree(args.output) raise
def __call__(self, args): video, data = self.getdata(args) if args.pascal: if not args.output: print "error: PASCAL output needs an output" return file = args.output print "Dumping video {0}".format(video.slug) elif args.output: file = open(args.output, 'w') print "Dumping video {0}".format(video.slug) else: file = cStringIO.StringIO() scale = args.scale if args.dimensions or args.original_video: if args.original_video: w, h = ffmpeg.extract(args.original_video).next().size else: w, h = args.dimensions.split("x") w = float(w) h = float(h) s = w / video.width if s * video.height > h: s = h / video.height scale = s for track in data: track.boxes = [x.transform(scale) for x in track.boxes] if args.lowercase: track.label = track.label.lower() if args.xml: self.dumpxml(file, data) elif args.json: self.dumpjson(file, data) elif args.matlab: self.dumpmatlab(file, data, video, scale) elif args.pickle: self.dumppickle(file, data) elif args.labelme: self.dumplabelme(file, data, args.slug, args.labelme) elif args.pascal: if scale != 1: print "Warning: scale is not 1, yet frames are not resizing!" print "Warning: you should manually update the JPEGImages" self.dumppascal(file, video, data, args.pascal_difficult, args.pascal_skip, args.pascal_negatives) else: self.dumptext(file, data) if args.pascal: return elif args.output: file.close() else: sys.stdout.write(file.getvalue())
def video_to_image_of_resolution(path_video, width, height): sequence = ffmpeg.extract(path_video) try: for frame, image in enumerate(sequence): if frame % 100 == 0: logger.debug("Decoding frames {0} to {1}".format( frame, frame + 100)) image.thumbnail((width, height), Image.BILINEAR) path = Video.getframepath(frame, args.output) try: image.save(path) except IOError: os.makedirs(os.path.dirname(path)) image.save(path) except: print "Aborted. Cleaning up..." shutil.rmtree(args.output) raise ValueError("Error extracting video")
from vision import ffmpeg f = ffmpeg.extract( "/csail/vision-videolabelme/databases/video_adapt/demos/bottle_table.mov", fps=None, size=(100, 100)) i = iter(f) print len(f) for t in f: print t.size
def __call__(self, args): video = session.query(Video).filter(Video.slug == args.slug) if video.count() == 0: print "Video {0} does not exist!".format(args.slug) raise SystemExit() video = video.one() print "Parsing text data" data = {} if args.json: data = self.getdatajson(args.labelfile) else: data = self.getdatatext(args.labelfile, video.totalframes) scale = args.scale if args.dimensions or args.original_video or args.original_frame: print "Computing scale" if args.original_video: w, h = ffmpeg.extract(args.original_video).next().size elif args.original_frame: w, h = Image.open(args.original_frame).size else: w, h = args.dimensions.split("x") w = float(w) h = float(h) s = float(video.width) / w if s * h > video.height: s = float(video.height) / h scale = s print "Scale = {0}".format(scale) segmentcount = 1 for segment in video.segments: print "Segment {0} of {1}".format(segmentcount, len(video.segments)) segmentcount += 1 for job in segment.jobs: for boxid in data: label = data[boxid]['label'] boxes = data[boxid]['boxes'] query = session.query(Label).filter( Label.videoid == video.id).filter(Label.text == label) if query.count() == 0: continue label = query.one() newpath = Path(label=label) visible = False for frame, boxdata in boxes.iteritems(): frame = int(frame) if frame < segment.start or segment.stop <= frame or ( frame % video.blowradius != 0): continue newbox = Box(path=newpath) #newbox.xtl = max(boxdata['xtl'], 0) #newbox.ytl = max(boxdata['ytl'], 0) #newbox.xbr = max(boxdata['xbr'], 0) #newbox.ybr = max(boxdata['ybr'], 0) newbox.xtl = boxdata['xtl'] newbox.ytl = boxdata['ytl'] newbox.xbr = boxdata['xbr'] newbox.ybr = boxdata['ybr'] newbox.occluded = boxdata['occluded'] newbox.outside = boxdata['outside'] newbox.generated = boxdata['generated'] newbox.frame = frame scalebox = newbox.getbox() scalebox = scalebox.transform(scale) newbox.xtl = scalebox.xtl newbox.ytl = scalebox.ytl newbox.xbr = scalebox.xbr newbox.ybr = scalebox.ybr if not newbox.outside: visible = True if visible: job.paths.append(newpath) session.add(job) session.commit()
def __call__(self, args): video = session.query(Video).filter(Video.slug == args.slug) if video.count() == 0: print "Video {0} does not exist!".format(args.slug) raise SystemExit() video = video.one() print "Parsing text data" data = {} if args.json: data = self.getdatajson(args.labelfile) else: data = self.getdatatext(args.labelfile, video.totalframes) scale = args.scale if args.dimensions or args.original_video or args.original_frame: print "Computing scale" if args.original_video: w, h = ffmpeg.extract(args.original_video).next().size elif args.original_frame: w, h = Image.open(args.original_frame).size else: w, h = args.dimensions.split("x") w = float(w) h = float(h) s = float(video.width) / w if s * h > video.height: s = float(video.height) / h scale = s print "Scale = {0}".format(scale) segmentcount = 1 for segment in video.segments: print "Segment {0} of {1}".format(segmentcount, len(video.segments)) segmentcount += 1 for job in segment.jobs: for boxid in data: label = data[boxid]['label'] boxes = data[boxid]['boxes'] query = session.query(Label).filter(Label.videoid == video.id).filter(Label.text == label) if query.count() == 0: continue label = query.one() newpath = Path(label=label) visible = False for frame, boxdata in boxes.iteritems(): frame = int(frame) if frame < segment.start or segment.stop <= frame or (frame % video.blowradius != 0): continue newbox = Box(path=newpath) #newbox.xtl = max(boxdata['xtl'], 0) #newbox.ytl = max(boxdata['ytl'], 0) #newbox.xbr = max(boxdata['xbr'], 0) #newbox.ybr = max(boxdata['ybr'], 0) newbox.xtl = boxdata['xtl'] newbox.ytl = boxdata['ytl'] newbox.xbr = boxdata['xbr'] newbox.ybr = boxdata['ybr'] newbox.occluded = boxdata['occluded'] newbox.outside = boxdata['outside'] newbox.generated = boxdata['generated'] newbox.frame = frame scalebox = newbox.getbox() scalebox = scalebox.transform(scale) newbox.xtl = scalebox.xtl newbox.ytl = scalebox.ytl newbox.xbr = scalebox.xbr newbox.ybr = scalebox.ybr if not newbox.outside: visible = True if visible: job.paths.append(newpath) session.add(job) session.commit()
from vision import ffmpeg f = ffmpeg.extract("/csail/vision-videolabelme/databases/video_adapt/demos/bottle_table.mov", fps = None, size = (100, 100)) i = iter(f) print len(f) for t in f: print t.size