import os
from glob import glob

clean = lambda x : sorted(list(filter(lambda y: os.path.isdir(y), x)))

paths = clean(glob('test-output/video/final'))
for path in paths:
    video_paths = clean(glob(f'{path}/*'))
    for video in video_paths:
        os.makedirs(f'{video}/converted_frames', exist_ok=True)
        for frame in sorted(list(glob(f'{video}/*_2.png'))):
            frame_basename = os.path.basename(frame)
            os.system(f'convert {frame} -quality 80 {video}/converted_frames/{frame_basename.replace("_2.png", "_2.jpg")}')