demo_app/helpers.py [70:97]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def extract_frames_from_video_bytes(
    video_bytes: bytes,
    frame_times_ms: list[int],
    img_type: Literal["pil", "cv2"] = "pil",
) -> dict[int, Union[np.ndarray, NoneType]]:
    """
    Extract frames from a video in memory at specified times.

    :param video_bytes: Video file in bytes.
    :param frame_times_ms: List of times in milliseconds to extract frames.
    :return: List of extracted frames.
    """
    # OpenCV does not support reading from bytes - use a temporary file
    with tempfile.NamedTemporaryFile() as temp:
        temp.write(video_bytes)

        video_capture = cv2.VideoCapture(temp.name)

    fps = video_capture.get(cv2.CAP_PROP_FPS)
    time_to_frame_mapper = {}

    for time_ms in frame_times_ms:
        frame_number = int((time_ms / 1000) * fps)
        video_capture.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
        success, frame = video_capture.read()
        if success:
            if img_type == "pil":
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



function_app/src/helpers/content_understanding.py [227:254]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def extract_frames_from_video_bytes(
    video_bytes: bytes,
    frame_times_ms: list[int],
    img_type: Literal["pil", "cv2"] = "pil",
) -> dict[int, Union[np.ndarray, NoneType]]:
    """
    Extract frames from a video in memory at specified times.

    :param video_bytes: Video file in bytes.
    :param frame_times_ms: List of times in milliseconds to extract frames.
    :return: List of extracted frames.
    """
    # OpenCV does not support reading from bytes - use a temporary file
    with tempfile.NamedTemporaryFile() as temp:
        temp.write(video_bytes)

        video_capture = cv2.VideoCapture(temp.name)

    fps = video_capture.get(cv2.CAP_PROP_FPS)
    time_to_frame_mapper = {}

    for time_ms in frame_times_ms:
        frame_number = int((time_ms / 1000) * fps)
        video_capture.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
        success, frame = video_capture.read()
        if success:
            if img_type == "pil":
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



