Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pretty_duration_centis_limit():
mi = MediaInfoForTest(FFPROBE_EXAMPLE_JSON_PATH)
mi.duration_seconds = 1.9999
pretty_duration = MediaInfo.pretty_duration(mi.duration_seconds, show_centis=True)
assert_equals(pretty_duration, "00:01.99")
# draw metadata
if args.metadata_position == "top":
h = draw_metadata_helper()
# draw capture grid
w = 0
frames = sorted(frames, key=lambda x: x.timestamp)
for i, frame in enumerate(frames):
f = Image.open(frame.filename)
f.putalpha(args.capture_alpha)
image_capture_layer.paste(f, (w, h))
# show timestamp
if args.show_timestamp:
timestamp_time = MediaInfo.pretty_duration(frame.timestamp, show_centis=True)
timestamp_duration = MediaInfo.pretty_duration(media_info.duration_seconds, show_centis=True)
parsed_time = MediaInfo.parse_duration(frame.timestamp)
parsed_duration = MediaInfo.parse_duration(media_info.duration_seconds)
timestamp_args = {
"TIME": timestamp_time,
"DURATION": timestamp_duration,
"THUMBNAIL_NUMBER": i + 1,
"H": str(parsed_time["hours"]).zfill(2),
"M": str(parsed_time["minutes"]).zfill(2),
"S": str(parsed_time["seconds"]).zfill(2),
"c": str(parsed_time["centis"]).zfill(2),
"m": str(parsed_time["millis"]).zfill(3),
"dH": str(parsed_duration["hours"]).zfill(2),
"dM": str(parsed_duration["minutes"]).zfill(2),
"dS": str(parsed_duration["seconds"]).zfill(2),
"dc": str(parsed_duration["centis"]).zfill(2),
"dm": str(parsed_duration["millis"]).zfill(3)
"ffmpeg",
"-i", self.path,
"-ss", time,
"-vframes", "1",
"-s", "%sx%s" % (width, height),
]
if self.frame_type is not None:
ffmpeg_command += select_args
ffmpeg_command += [
"-y",
out_path
]
else:
skip_time = MediaInfo.pretty_duration(skip_time_seconds, show_millis=True)
ffmpeg_command = [
"ffmpeg",
"-ss", skip_time,
"-i", self.path,
"-ss", skip_delay,
"-vframes", "1",
"-s", "%sx%s" % (width, height),
]
if self.frame_type is not None:
ffmpeg_command += select_args
ffmpeg_command += [
"-y",
out_path
]
def make_capture(self, time, width, height, out_path="out.png"):
"""Capture a frame at given time with given width and height using ffmpeg
"""
skip_delay = MediaInfo.pretty_duration(self.skip_delay_seconds, show_millis=True)
ffmpeg_command = [
"ffmpeg",
"-ss", time,
"-i", self.path,
"-vframes", "1",
"-s", "%sx%s" % (width, height),
]
if self.frame_type is not None:
select_args = [
"-vf", "select='eq(frame_type\\," + self.frame_type + ")'"
]
if self.frame_type == "key":
select_args = [
def timestamp_generator(media_info, args):
"""Generates `num_samples` uniformly distributed timestamps over time.
Timestamps will be selected in the range specified by start_delay_percent and end_delay percent.
For example, `end_delay_percent` can be used to avoid making captures during the ending credits.
"""
delay = total_delay_seconds(media_info, args)
capture_interval = (media_info.duration_seconds - delay) / (args.num_samples + 1)
if args.interval is not None:
capture_interval = int(args.interval.total_seconds())
start_delay_seconds = math.floor(media_info.duration_seconds * args.start_delay_percent / 100)
time = start_delay_seconds + capture_interval
for i in range(args.num_samples):
yield (time, MediaInfo.pretty_duration(time, show_millis=True))
time += capture_interval