-
Notifications
You must be signed in to change notification settings - Fork 12
/
extract_features.py
55 lines (47 loc) · 1.85 KB
/
extract_features.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import click
from winnow.pipeline.extract_video_signatures import extract_video_signatures
from winnow.pipeline.pipeline_context import PipelineContext
from winnow.pipeline.store_database_signatures import store_database_signatures
from winnow.utils.config import resolve_config
from winnow.utils.files import scan_videos, scan_videos_from_txt
from winnow.utils.logging import configure_logging_cli
@click.command()
@click.option("--config", "-cp", help="path to the project config file", default=os.environ.get("WINNOW_CONFIG"))
@click.option(
"--list-of-files",
"-lof",
help="path to txt with a list of files for processing - overrides source folder from the config file",
default=None,
)
@click.option(
"--frame-sampling",
"-fs",
help=(
"Sets the sampling strategy (values from 1 to 10 - eg "
"sample one frame every X seconds) - overrides frame "
"sampling from the config file"
),
default=None,
)
@click.option(
"--save-frames",
"-sf",
help="Whether to save the frames sampled from the videos - overrides save_frames on the config file",
default=None,
is_flag=True,
)
def main(config, list_of_files, frame_sampling, save_frames):
logger = configure_logging_cli()
logger.info("Loading config file")
config = resolve_config(config_path=config, frame_sampling=frame_sampling, save_frames=save_frames)
logger.info("Searching for Dataset Video Files")
if list_of_files is None:
videos = scan_videos(config.sources.root, "**", extensions=config.sources.extensions)
else:
videos = scan_videos_from_txt(list_of_files, extensions=config.sources.extensions)
pipeline = PipelineContext(config)
extract_video_signatures(files=videos, pipeline=pipeline)
store_database_signatures(files=videos, pipeline=pipeline)
if __name__ == "__main__":
main()