def test_get_non_existing_resource_from_non_existing_category(self): """Test the get_internal_resource function Non-existing resource, non-existing category """ path = toolbox2.get_internal_resource('dummy', 'foobar') assert not os.path.isfile(path), 'The returned path should not exist.'
def test_get_existing_resource_from_existing_category(self): """Test the get_internal_resource function Existing resource, existing category """ path = toolbox2.get_internal_resource('fonts', 'Vera.ttf') assert os.path.isfile(path), 'The returned path does not exist.'
def test_get_existing_resource_from_non_existing_category(self): """Test the get_internal_resource function Existing resource, non-existing category """ path = toolbox2.get_internal_resource("dummy", "Vera.ttf") assert not os.path.isfile(path), "The returned path should not exist."
def test_get_non_existing_resource_from_existing_category(self): """Test the get_internal_resource function Non-existing resource, existing category """ path = toolbox2.get_internal_resource("fonts", "foobar") assert not os.path.isfile(path), "The returned path should not exist."
def drawtext(self, basedir, options=None): if not options: options = {} avinfo = self._get_input_avinfo() rate = int(math.ceil(avinfo.video_fps)) box = options.get('box', 0) timecode = options.get('timecode', 0) text = options.get('text', '') if options.get('hostname', 0) == 1: text += " " + socket.gethostname() if options.get('date', 0) == 1: text += " " + time.ctime() text = text.strip() # Avoid a leading white-space if no text is set if timecode and text: text += " " # The timecode will be appended automatically if not text and timecode == 0: # Nothing to draw, stop right there return # Put the text in a tmp file (this avoid dealing with escaping) # The tmp file is placed in the work directory, so that it is deleted with it path = '' if text: fd, path = tempfile.mkstemp(suffix='toolbox2_burn_text', dir=basedir, text=True) os.write(fd, text) os.close(fd) fontsize = options.get('fontsize', 12) fontname = options.get('fontname', 'vera') fontfiles = { 'vera': toolbox2.get_internal_resource('fonts', 'Vera.ttf'), 'dejavu': toolbox2.get_internal_resource('fonts', 'DejaVuSans.ttf'), 'liberation': toolbox2.get_internal_resource('fonts', 'LiberationSans-Regular.ttf'), 'arial': toolbox2.get_internal_resource('fonts', 'Arial.ttf'), } fontfile = fontfiles.get(fontname) if not fontfile: raise FFmpegWorkerException('Unsupported fontname: %s' % fontname) padding = options.get('padding', 10) position = options.get('position', 'center') positions = { 'top-left': 'x=%d:y=%d' % (padding, padding), 'top-center': 'x=(w/2-tw/2):y=%d' % padding, 'top-right': 'x=(w-tw-%d):y=%d' % (padding, padding), 'bottom-left': 'x=%d:y=(h-lh-%d)' % (padding, padding), 'bottom-center': 'x=(w/2-tw/2):y=(h-lh-%d)' % padding, 'bottom-right': 'x=(w-tw-%d):y=(h-lh-%d)' % (padding, padding), 'center-left': 'x=%d:y=(h/2-lh/2)' % padding, 'center': 'x=(w/2-tw/2):y=(h/2-lh/2)', 'center-right': 'x=(w-tw-%d):y=(h/2-lh/2)' % padding, } position_coords = positions.get(position) drawtext_filter = '' # Is it a custom position? We expect a string <number>x<number> if not position_coords: xy = position.split('x') if len(xy) == 2: drawtext_filter += 'drawtext=x=%s:y=%s:' % (xy[0], xy[1]) else: drawtext_filter += 'drawtext=x=0:y=0:' else: drawtext_filter += 'drawtext=%s:' % position_coords drawtext_filter += 'fontcolor=white:' drawtext_filter += 'fontfile=%s:' % fontfile if fontsize: drawtext_filter += 'fontsize=%d:' % fontsize if box: drawtext_filter += 'box=1:boxcolor=0x00000000@1:' if text: drawtext_filter += 'textfile=%s:' % path if timecode: drawtext_filter += 'timecode=\'%s\':rate=%s' % ( avinfo.timecode.replace(':', '\\:'), rate ) self.video_filter_chain.append( ('drawtext', drawtext_filter) )
def drawtext(self, basedir, options=None): if not options: options = {} avinfo = self._get_input_avinfo() rate = int(math.ceil(avinfo.video_fps)) box = options.get("box", 0) timecode = options.get("timecode", 0) text = options.get("text", "") if options.get("hostname", 0) == 1: text += " " + socket.gethostname() if options.get("date", 0) == 1: text += " " + time.ctime() text = text.strip() # Avoid a leading white-space if no text is set if timecode and text: text += " " # The timecode will be appended automatically if not text and timecode == 0: # Nothing to draw, stop right there return # Put the text in a tmp file (this avoids dealing with escaping) # The tmp file is placed in the work directory, so that it is deleted with it path = "" if text: fd, path = tempfile.mkstemp(suffix="toolbox2_burn_text", dir=basedir, text=True) with os.fdopen(fd, "w") as fp: fp.write(text) fontsize = options.get("fontsize", 12) fontname = options.get("fontname", "vera") fontfiles = { "vera": toolbox2.get_internal_resource("fonts", "Vera.ttf"), "dejavu": toolbox2.get_internal_resource("fonts", "DejaVuSans.ttf"), "liberation": toolbox2.get_internal_resource("fonts", "LiberationSans-Regular.ttf"), "arial": toolbox2.get_internal_resource("fonts", "Arial.ttf"), } fontfile = fontfiles.get(fontname) if not fontfile: raise FFmpegWorkerException("Unsupported fontname: %s" % fontname) padding = options.get("padding", 10) position = options.get("position", "center") positions = { "top-left": "x=%d:y=%d" % (padding, padding), "top-center": "x=(w/2-tw/2):y=%d" % padding, "top-right": "x=(w-tw-%d):y=%d" % (padding, padding), "bottom-left": "x=%d:y=(h-lh-%d)" % (padding, padding), "bottom-center": "x=(w/2-tw/2):y=(h-lh-%d)" % padding, "bottom-right": "x=(w-tw-%d):y=(h-lh-%d)" % (padding, padding), "center-left": "x=%d:y=(h/2-lh/2)" % padding, "center": "x=(w/2-tw/2):y=(h/2-lh/2)", "center-right": "x=(w-tw-%d):y=(h/2-lh/2)" % padding, } position_coords = positions.get(position) drawtext_filter = "" # Is it a custom position? We expect a string <number>x<number> if not position_coords: xy = position.split("x") if len(xy) == 2: drawtext_filter += "drawtext=x=%s:y=%s:" % (xy[0], xy[1]) else: drawtext_filter += "drawtext=x=0:y=0:" else: drawtext_filter += "drawtext=%s:" % position_coords drawtext_filter += "fontcolor=white:" drawtext_filter += "fontfile=%s:" % fontfile if fontsize: drawtext_filter += "fontsize=%d:" % fontsize if box: drawtext_filter += "box=1:boxcolor=0x00000000@1:" if text: drawtext_filter += "textfile=%s:" % path if timecode: drawtext_filter += "timecode='%s':rate=%s" % ( avinfo.timecode.replace(":", "\\:"), rate, ) self.video_filter_chain.append(("drawtext", drawtext_filter))
def drawtext(self, basedir, options=None): if not options: options = {} avinfo = self._get_input_avinfo() rate = int(math.ceil(avinfo.video_fps)) box = options.get('box', 0) timecode = options.get('timecode', 0) text = options.get('text', '') if options.get('hostname', 0) == 1: text += " " + socket.gethostname() if options.get('date', 0) == 1: text += " " + time.ctime() text = text.strip() # Avoid a leading white-space if no text is set if timecode and text: text += " " # The timecode will be appended automatically if not text and timecode == 0: # Nothing to draw, stop right there return # Put the text in a tmp file (this avoid dealing with escaping) # The tmp file is placed in the work directory, so that it is deleted with it path = '' if text: fd, path = tempfile.mkstemp(suffix='toolbox2_burn_text', dir=basedir, text=True) os.write(fd, text) os.close(fd) fontsize = options.get('fontsize', 12) fontname = options.get('fontname', 'vera') fontfiles = { 'vera': toolbox2.get_internal_resource('fonts', 'Vera.ttf'), 'dejavu': toolbox2.get_internal_resource('fonts', 'DejaVuSans.ttf'), 'liberation': toolbox2.get_internal_resource('fonts', 'LiberationSans-Regular.ttf'), 'arial': toolbox2.get_internal_resource('fonts', 'Arial.ttf'), } fontfile = fontfiles.get(fontname) if not fontfile: raise FFmpegWorkerException('Unsupported fontname: %s' % fontname) padding = options.get('padding', 10) position = options.get('position', 'center') positions = { 'top-left': 'x=%d:y=%d' % (padding, padding), 'top-center': 'x=(w/2-tw/2):y=%d' % padding, 'top-right': 'x=(w-tw-%d):y=%d' % (padding, padding), 'bottom-left': 'x=%d:y=(h-lh-%d)' % (padding, padding), 'bottom-center': 'x=(w/2-tw/2):y=(h-lh-%d)' % padding, 'bottom-right': 'x=(w-tw-%d):y=(h-lh-%d)' % (padding, padding), 'center-left': 'x=%d:y=(h/2-lh/2)' % padding, 'center': 'x=(w/2-tw/2):y=(h/2-lh/2)', 'center-right': 'x=(w-tw-%d):y=(h/2-lh/2)' % padding, } position_coords = positions.get(position) drawtext_filter = '' # Is it a custom position? We expect a string <number>x<number> if not position_coords: xy = position.split('x') if len(xy) == 2: drawtext_filter += 'drawtext=x=%s:y=%s:' % (xy[0], xy[1]) else: drawtext_filter += 'drawtext=x=0:y=0:' else: drawtext_filter += 'drawtext=%s:' % position_coords drawtext_filter += 'fontcolor=white:' drawtext_filter += 'fontfile=%s:' % fontfile if fontsize: drawtext_filter += 'fontsize=%d:' % fontsize if box: drawtext_filter += 'box=1:boxcolor=0x00000000@1:' if text: drawtext_filter += 'textfile=%s:' % path if timecode: drawtext_filter += 'timecode=\'%s\':rate=%s' % ( avinfo.timecode.replace(':', '\\:'), rate) self.video_filter_chain.append(('drawtext', drawtext_filter))