Skip to content

Commit

Permalink
Merge pull request #673 from rnissl/main
Browse files Browse the repository at this point in the history
generate select filter as binary search for less stack consumption during evaluation
  • Loading branch information
ptpt authored Sep 19, 2024
2 parents 4c7a198 + 5fac470 commit 3663f38
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mapillary_tools/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ def extract_frames(

self._run_ffmpeg(cmd)

def generate_binary_search(
self,
sorted_frame_indices: T.Set[int]
) -> str:
length = len(sorted_frame_indices)

if length == 0:
return "0"

if length == 1:
return f"eq(n\\,{ sorted_frame_indices[0] })"

middle = length // 2
return f"if(lt(n\\,{ sorted_frame_indices[middle] })\\,{ self.generate_binary_search(sorted_frame_indices[:middle]) }\\,{ self.generate_binary_search(sorted_frame_indices[middle:]) })"

def extract_specified_frames(
self,
video_path: Path,
Expand Down Expand Up @@ -226,7 +241,7 @@ def extract_specified_frames(
# the maximum command line length for the CreateProcess function is 32767 characters
# https://devblogs.microsoft.com/oldnewthing/20031210-00/?p=41553

eqs = "+".join(f"eq(n\\,{idx})" for idx in sorted(frame_indices))
eqs = self.generate_binary_search(sorted(frame_indices))

# https://github.com/mapillary/mapillary_tools/issues/503
if sys.platform in ["win32"]:
Expand Down

0 comments on commit 3663f38

Please sign in to comment.