Compare commits

...
Author SHA1 Message Date
henryruhs 1434c2c9bc use ideal pipesize for our task 2026-07-28 13:39:49 +02:00
Henry RuhsandGitHub a394d48f34 avoid tobytes copy (#1208) 2026-07-28 10:02:08 +02:00
HarisreedharandGitHub 5e8a37110d Restrict the preview frame slider and the reader seek to the last frame index (#1207)
* fix index bug

* fix rounding bug
2026-07-27 18:51:35 +05:30
7 changed files with 14 additions and 12 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ FACE_STORE : FaceStore = {}
def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
if FACE_STORE.get(vision_hash):
return FACE_STORE.get(vision_hash).get('faces')
@@ -21,7 +21,7 @@ def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
FACE_STORE.setdefault(vision_hash,
{
'lock': threading.Lock()
@@ -30,7 +30,7 @@ def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
def resolve_lock(vision_frame : VisionFrame) -> threading.Lock:
if numpy.any(vision_frame):
vision_hash = create_hash(vision_frame.tobytes())
vision_hash = create_hash(vision_frame.data)
return FACE_STORE.setdefault(vision_hash,
{
'lock': threading.Lock()
+1 -1
View File
@@ -66,7 +66,7 @@ def run_ffmpeg(commands : List[Command]) -> subprocess.Popen[bytes]:
def open_ffmpeg(commands : List[Command]) -> subprocess.Popen[bytes]:
commands = ffmpeg_builder.run(commands)
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE, pipesize = 1024 * 1024)
def create_video_reader(video_path : str, frame_number : int, video_metadata : VideoReaderMetadata) -> subprocess.Popen[bytes]:
+2 -2
View File
@@ -74,7 +74,7 @@ def extract_audio_metadata(audio_path : str) -> AudioMetadata:
duration = float(format_entries.get('duration'))
sample_rate = int(audio_entries.get('sample_rate'))
frame_total = int(duration * sample_rate)
frame_total = round(duration * sample_rate)
channel_total = int(audio_entries.get('channels'))
bit_rate = int(format_entries.get('bit_rate'))
@@ -101,7 +101,7 @@ def extract_video_metadata(video_path : str) -> VideoMetadata:
duration = float(format_entries.get('duration'))
fps = extract_video_fps(video_entries.get('r_frame_rate'))
frame_total = int(duration * fps)
frame_total = round(duration * fps)
width = int(video_entries.get('width'))
height = int(video_entries.get('height'))
bit_rate = int(format_entries.get('bit_rate'))
+3 -2
View File
@@ -26,8 +26,9 @@ def render() -> None:
'visible': False
}
if is_video(state_manager.get_item('target_path')):
video_frame_total = count_video_frame_total(state_manager.get_item('target_path'))
preview_frame_slider_options['value'] = state_manager.get_item('reference_frame_number')
preview_frame_slider_options['maximum'] = count_video_frame_total(state_manager.get_item('target_path'))
preview_frame_slider_options['maximum'] = video_frame_total - 1
preview_frame_slider_options['visible'] = True
PREVIEW_FRAME_SLIDER = gradio.Slider(**preview_frame_slider_options)
with gradio.Row():
@@ -57,5 +58,5 @@ def listen() -> None:
def update_preview_frame_slider() -> gradio.Slider:
if is_video(state_manager.get_item('target_path')):
video_frame_total = count_video_frame_total(state_manager.get_item('target_path'))
return gradio.Slider(maximum = video_frame_total, visible = True)
return gradio.Slider(maximum = video_frame_total - 1, visible = True)
return gradio.Slider(value = 0, visible = False)
+1 -1
View File
@@ -106,7 +106,7 @@ def start(webcam_device_id : int, webcam_mode : WebcamMode, webcam_resolution :
yield capture_vision_frame
if webcam_mode in [ 'udp', 'v4l2' ]:
try:
stream.stdin.write(capture_vision_frame.tobytes())
stream.stdin.write(capture_vision_frame.data)
except Exception:
pass
+3 -2
View File
@@ -35,7 +35,8 @@ def get_reader(video_path : str, context : str) -> VideoReader:
def conditional_seek_video_reader(video_reader : VideoReader, frame_number : int = 0) -> None:
frame_number = min(video_reader.get('metadata').get('frame_total'), frame_number)
frame_total = video_reader.get('metadata').get('frame_total')
frame_number = min(frame_total - 1, frame_number)
skip_total = frame_number - video_reader.get('frame_number')
skip_margin = 128
@@ -132,7 +133,7 @@ def get_writer(video_path : str, temp_video_fps : Fps, temp_video_resolution : R
def write_video_frame(video_writer : VideoWriter, vision_frame : VisionFrame) -> None:
video_writer.get('process').stdin.write(vision_frame.tobytes())
video_writer.get('process').stdin.write(vision_frame.data)
def close_video_writer(video_writer : VideoWriter) -> bool:
+1 -1
View File
@@ -41,7 +41,7 @@ def test_extract_audio_metadata() -> None:
assert audio_metadata.get('sample_rate') == 44100
assert audio_metadata.get('channel_total') == 1
assert audio_metadata.get('frame_total') == 167039
assert audio_metadata.get('frame_total') == 167040
assert audio_metadata.get('bit_rate') == 128000
audio_metadata = extract_audio_metadata(get_test_example_file('source-48000khz-2ch.wav'))