Skip to content

Video

stegobox.io.video.read(filename)

Read a videocapture from a file.

Parameters:

Name Type Description Default
filename str

The name or path to the video file.

required

Returns:

Type Description
VideoCapture

cv2.VideoCapture: a videocapture

Source code in stegobox/io/video.py
def read(filename: str) -> cv2.VideoCapture:
    """Read a videocapture from a file.

    Args:
        filename: The name or path to the video file.

    Returns:
        cv2.VideoCapture: a videocapture
    """
    return cv2.VideoCapture(filename)

stegobox.io.video.write(img_array, fps, size, filename, encoding='avc1')

Saves a video to the designated file path.

Parameters:

Name Type Description Default
img_array list[ndarray]

An encrypted collection of images.

required
fps int

Video frame rate.

required
size tuple[int, int]

Video size.

required
filename str

The designated file path.

required
encoding str

Video file encoding, defaults to "avc1".

'avc1'
Source code in stegobox/io/video.py
def write(
    img_array: list[numpy.ndarray],
    fps: int,
    size: tuple[int, int],
    filename: str,
    encoding: str = "avc1",
) -> None:
    """Saves a video to the designated file path.

    Args:
        img_array: An encrypted collection of images.
        fps: Video frame rate.
        size: Video size.
        filename: The designated file path.
        encoding: Video file encoding, defaults to "avc1".
    """
    out = cv2.VideoWriter(filename, cv2.VideoWriter_fourcc(*encoding), fps, size)
    for img in img_array:
        out.write(img)
    out.release()

stegobox.io.video.write_hfyu(img_array, fps, size, filename)

Source code in stegobox/io/video.py
def write_hfyu(
    img_array: list[numpy.ndarray], fps: int, size: tuple[int, int], filename: str
) -> None:
    write(img_array, fps, size, filename, encoding="HFYU")

stegobox.io.video.write_mjpg(img_array, fps, size, filename)

Source code in stegobox/io/video.py
def write_mjpg(
    img_array: list[numpy.ndarray], fps: int, size: tuple[int, int], filename: str
) -> None:
    write(img_array, fps, size, filename, encoding="MJPG")

stegobox.io.video.read_with_ffmpeg(video_path)

Source code in stegobox/io/video.py
def read_with_ffmpeg(
    video_path: str,
) -> tuple[cv2.VideoCapture, ffmpeg.nodes.FilterableStream]:
    return cv2.VideoCapture(video_path), ffmpeg.input(video_path)

stegobox.io.video.write_with_ffmpeg(video_temp_path, audio_temp_path, output_path, remove_source=True)

Source code in stegobox/io/video.py
def write_with_ffmpeg(
    video_temp_path: str,
    audio_temp_path: str,
    output_path: str,
    remove_source: bool = True,
) -> None:
    video = ffmpeg.input(video_temp_path)
    audio = ffmpeg.input(audio_temp_path)

    out = ffmpeg.output(
        audio.audio, video.video, output_path, acodec="copy", vcodec="copy"
    ).overwrite_output()
    out.run()

    if remove_source:
        os.remove(video_temp_path)
        os.remove(audio_temp_path)