-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_assets.py
41 lines (33 loc) · 1.07 KB
/
get_assets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from os import chdir, listdir, makedirs
from subprocess import DEVNULL, check_output, run
from supervision.assets import VideoAssets, download_assets
def get_size(path):
return (
check_output(
f'ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 {path}',
shell=True,
)
.decode()
.strip()
)
def half_downscale(original_folder, new_folder):
makedirs(new_folder, exist_ok=True)
for video in listdir(original_folder):
if video.endswith('.mp4'):
run(
f'ffmpeg -y -i {original_folder}/{video} -vf scale="iw/2:ih/2" {new_folder}/{video}',
shell=True,
stderr=DEVNULL,
stdin=DEVNULL,
stdout=DEVNULL,
)
original = get_size(f'{original_folder}/{video}')
modified = get_size(f'{new_folder}/{video}')
print(f'{video}: {original} -> {modified}')
makedirs('videos', exist_ok=True)
chdir('videos')
for asset in VideoAssets.list():
download_assets(asset)
chdir('..')
half_downscale('videos', 'half_videos')
half_downscale('half_videos', 'quarter_videos')