Skip to content

Commit

Permalink
now using mid scene timestamp/index to extract keyframe
Browse files Browse the repository at this point in the history
  • Loading branch information
jblom committed Dec 13, 2023
1 parent cc60521 commit f98a096
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run_shell_command(cmd: str) -> bytes:
)

stdout, stderr = process.communicate()
logger.info(stdout)
logger.debug(stdout)
logger.error(stderr)
logger.info("Process is done: return stdout")
return stdout
Expand Down
3 changes: 3 additions & 0 deletions main_data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def generate_input_for_feature_extraction(
media_file.duration_ms,
cfg.VISXP_PREP.SPECTOGRAM_WINDOW_SIZE_MS,
)
logger.info(keyframe_timestamps)

logger.info(keyframe_indices)

# NOTE this step can be skipped with scenedetect
if cfg.VISXP_PREP.RUN_KEYFRAME_EXTRACTION:
Expand Down
17 changes: 15 additions & 2 deletions scenedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,26 @@ def save_keyframe_indices_file(
return True


def calc_mid_keyframe_timestamp(start_sec: float, duration_sec: float) -> int:
s = int(start_sec * 1000)
ms_to_middle = int(duration_sec * 1000 / 2)
return s + ms_to_middle


def calc_mid_keyframe_index(start_frame: int, duration_frames: int) -> int:
frames_to_middle = int(
duration_frames / 2
) # ms from start to get to middle of scene
return start_frame + frames_to_middle # -1 on frame?


# extracts the keyframe timestamps from the generated CSV file
def get_keyframe_timestamps(
output_dir: str, duration_ms: int, window_size_ms: int = 1000
) -> List[int]:
logger.info("Extracting keyframe timestamps")
return [
int(float(row[3]) * 1000)
calc_mid_keyframe_timestamp(float(row[3]), float(row[9]))
for row in load_csv_data(output_dir)
if not too_close_to_edge(int(float(row[3]) * 1000), duration_ms, window_size_ms)
]
Expand All @@ -145,7 +158,7 @@ def get_keyframe_indices(
logger.info("Extracting keyframe indices")
# filter out the first frame also subtract 1 frame somehow
return [
int(row[1]) - 1
calc_mid_keyframe_index(int(row[1]), int(row[7]))
for row in load_csv_data(output_dir)
if not too_close_to_edge(int(float(row[3]) * 1000), duration_ms, window_size_ms)
]
Expand Down

0 comments on commit f98a096

Please sign in to comment.