def convert_video(input_path: Path, output_path: Path, codec: str = "MP4V") -> None:
    """Convert a video file to use a different codec.

    Creates the output directory if it doesn't exist. Reads the input video
    frame by frame and writes to a new file using the specified codec.

    Args:
        input_path: Path to the input video file
        output_path: Path where the converted video will be saved
        codec: FourCC code for the desired output codec. Defaults to ``"MP4V"``
    """
    if not output_path.parent.exists():
        output_path.parent.mkdir(parents=True)

    # create video reader for input file
    video_reader = cv2.VideoCapture(str(input_path))

    # create video writer for output file
    fourcc = cv2.VideoWriter_fourcc(*codec)
    frame_width = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
    frame_height = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = int(video_reader.get(cv2.CAP_PROP_FPS))
    video_writer = cv2.VideoWriter(
        str(output_path),
        fourcc,
        fps,
        (frame_width, frame_height),
    )

    # read frames
    success, frame = video_reader.read()
    while success:
        video_writer.write(frame)
        success, frame = video_reader.read()

    video_reader.release()
    video_writer.release()
Convert a video file to use a different codec.

    Creates the output directory if it doesn't exist. Reads the input video
    frame by frame and writes to a new file using the specified codec.

    Args:
        input_path: Path to the input video file
        output_path: Path where the converted video will be saved
        codec: FourCC code for the desired output codec. Defaults to ``"MP4V"``
    
src/anomalib/data/utils/video.py