Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 9 additions & 61 deletions visualmetrics/visualmetrics-portable.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,14 @@ def video_to_frames(
gc.collect()
if extract_frames(video, directory, full_resolution, viewport):
client_viewport = None
directories = [directory]
for dir in directories:
if orange_file is not None:
remove_frames_before_orange(dir, orange_file)
remove_orange_frames(dir, orange_file)
find_render_start(dir, orange_file, cropped, is_mobile)
adjust_frame_times(dir)
eliminate_duplicate_frames(dir, cropped, is_mobile)
crop_viewport(dir)
gc.collect()
if orange_file is not None:
remove_frames_before_orange(directory, orange_file)
remove_orange_frames(directory, orange_file)
find_render_start(directory, orange_file, cropped, is_mobile)
adjust_frame_times(directory)
eliminate_duplicate_frames(directory, cropped, is_mobile)
crop_viewport(directory)
gc.collect()
else:
logging.critical("Error extracting the video frames from %s", video)
else:
Expand Down Expand Up @@ -500,7 +498,7 @@ def find_recording_platform(video):
lines = result.stderr.splitlines()

is_mobile = False
matcher = re.compile(".*com\.android\.version.*")
matcher = re.compile(r".*com\.android\.version.*")
for line in lines:
if matcher.search(line):
is_mobile = True
Expand Down Expand Up @@ -977,18 +975,6 @@ def get_decimate_filter():
return decimate


def clean_directory(directory):
files = glob.glob(str(Path(directory) / "*.png"))
for file in files:
Path(file).unlink()
files = glob.glob(str(Path(directory) / "*.jpg"))
for file in files:
Path(file).unlink()
files = glob.glob(str(Path(directory) / "*.json"))
for file in files:
Path(file).unlink()


def is_color_frame(file, color_file):
"""Check a section from the middle, top and bottom of the viewport to see if it matches"""
global frame_cache
Expand Down Expand Up @@ -1476,12 +1462,6 @@ def calculate_key_color_frames(histograms, key_colors):
for key in key_colors:
key_color_frames[key] = []

current = None
current_key = None
total = 0
matched = 0
buckets = 256
channels = ["r", "g", "b"]
histograms = histograms.copy()

while len(histograms) > 0:
Expand Down Expand Up @@ -1567,17 +1547,6 @@ def calculate_frame_progress(histogram, start, final):
return math.floor(progress * 100)


def find_visually_complete(progress):
time = 0
for p in progress:
if int(p["progress"]) == 100:
time = p["time"]
break
elif time == 0:
time = p["time"]
return time


def calculate_speed_index(progress):
si = 0
last_ms = progress[0]["time"]
Expand All @@ -1591,11 +1560,6 @@ def calculate_speed_index(progress):


def calculate_contentful_speed_index(progress, directory):
# convert output comes out with lines that have this format:
# <pixel count>: <rgb color> #<hex color> <gray color>
# This is CLI dependant and very fragile
matcher = re.compile(r"(\d+?):")

try:
from PIL import Image

Expand Down Expand Up @@ -1846,19 +1810,6 @@ def check_config():
return ok


def check_process(command, output):
ok = False
try:
out = subprocess.check_output(
command, stderr=subprocess.STDOUT, shell=True, encoding="UTF-8"
)
if out.find(output) > -1:
ok = True
except BaseException:
ok = False
return ok


##########################################################################
# Main Entry Point
##########################################################################
Expand Down Expand Up @@ -1902,9 +1853,6 @@ def main():
help="Directory of video frames "
"(as input if exists or as output if a video file is specified).",
)
parser.add_argument(
"--render", help="Render the video frames to the given mp4 video file."
)
parser.add_argument(
"--screenshot",
help="Save the last frame of video as an image to the path provided.",
Expand Down
Loading
Loading