Skip to content

Commit

Permalink
added docker-compose for local testing; fixed main processing function
Browse files Browse the repository at this point in the history
  • Loading branch information
jblom committed Sep 18, 2023
1 parent 44aa346 commit 0bfeb2b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
/data
__pycache__
.coverage
.flake8
.flake8
/config
/config.yml
pyproject.toml
poetry.lock
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.mp4
/config-local.yml
/data
/data/*
!/data/README.md
__pycache__
.coverage
2 changes: 1 addition & 1 deletion config.yml → config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ VISXP_PREP:
RUN_HECATE: true
RUN_KEYFRAME_EXTRACTION: true
RUN_AUDIO_EXTRACTION: true
TEST_INPUT_FILE: /data/test_openbeelden.mp4 # or null
TEST_INPUT_FILE: /data/testob.mp4 # or null
INPUT:
DELETE_ON_COMPLETION: True
OUTPUT:
Expand Down
1 change: 1 addition & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put a file in this dir and fill in the path into the config.yml VISXP_PREP.TEST_INPUT_FILE
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'
services:
web:
image: dane-video-segmentation-worker:latest
volumes:
- ./data:/data
- ./config:/root/.DANE
container_name: visxp
# command: --cfg=/mnt/data/config.yml
logging:
options:
max-size: 20m
restart: always
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# echo "Starting virtual env and DANE video segmentation worker"

python3.10 work_it_locally.py
python3.10 visxp_prep.py
# python3.10 worker.py

echo the worker crashed, tailing /dev/null for debugging
Expand Down
19 changes: 12 additions & 7 deletions visxp_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def generate_input_for_feature_extraction(

output_dirs = {}
for kind in ["keyframes", "metadata", "spectograms", "tmp"]:
output_dir = os.path.join("/data", os.path.basename(input_file_path), kind)
output_dir = os.path.join("/data", _get_source_id(input_file_path), kind)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
output_dirs[kind] = output_dir
Expand All @@ -39,7 +39,7 @@ def generate_input_for_feature_extraction(
except Exception:
logger.info("Could not obtain shots and keyframes. Exit.")
sys.exit()
fps = get_fps(input_file_path)
fps = _get_fps(input_file_path)
logger.info(f"Framerate is {fps}.")
with open(
os.path.join(output_dirs["metadata"], "shot_boundaries_timestamps_ms.txt"),
Expand All @@ -49,8 +49,8 @@ def generate_input_for_feature_extraction(
str(
[
(
frame_index_to_timecode(start, fps),
frame_index_to_timecode(end, fps),
_frame_index_to_timecode(start, fps),
_frame_index_to_timecode(end, fps),
)
for (start, end) in shots
]
Expand All @@ -63,7 +63,7 @@ def generate_input_for_feature_extraction(
with open(
os.path.join(output_dirs["metadata"], "keyframes_timestamps_ms.txt"), "w"
) as f:
f.write(str([frame_index_to_timecode(i, fps) for i in keyframes]))
f.write(str([_frame_index_to_timecode(i, fps) for i in keyframes]))

if cfg.VISXP_PREP.RUN_KEYFRAME_EXTRACTION:
logger.info("Extracting keyframe images now.")
Expand Down Expand Up @@ -106,12 +106,17 @@ def generate_input_for_feature_extraction(
return VisXPFeatureExtractionInput(500, "Not implemented yet!", -1)


def frame_index_to_timecode(frame_index: int, fps: float, out_format="ms"):
def _get_source_id(input_file_path: str) -> str:
fn = os.path.basename(input_file_path)
return fn[0 : fn.rfind(".")] if "." in fn else fn


def _frame_index_to_timecode(frame_index: int, fps: float, out_format="ms"):
if out_format == "ms":
return round(frame_index / fps * 1000)


def get_fps(media_file):
def _get_fps(media_file):
return cv2.VideoCapture(media_file).get(cv2.CAP_PROP_FPS)


Expand Down

0 comments on commit 0bfeb2b

Please sign in to comment.