Skip to content

video

stable

Raw video frame buffer plugin for building, manipulating, and exporting RGBA video data. Provides a Video class for frame management alongside free functions for pixel format conversion and BMP parsing.

use plugin video::{Video, add_frame, set_fps, …}
19 functions Audio & Media
/ filter jk navigate Esc clear
Functions (19)
  1. Video Creates a new video buffer with the given pixel dimensions.
  2. add_frame Append an RGBA frame to the video
  3. set_fps Set the frames-per-second rate
  4. set_codec Set the codec label string
  5. set_resolution Change width and height before frames are added
  6. frame_count Get the number of stored frames
  7. duration Get video duration in seconds
  8. get_frame Retrieve a frame by index
  9. set_metadata Set a metadata key-value pair
  10. get_metadata Get all metadata as a table
  11. info Get width, height, fps, codec, and duration
  12. export Export all frames as a raw ZRAW byte blob
  13. clear_frames Remove all frames from the buffer
  14. create_raw_frame Create a solid-color RGBA frame
  15. rgba_to_rgb Strip alpha channel from RGBA bytes
  16. rgb_to_rgba Add alpha channel to RGB bytes
  17. frame_size Compute byte size of a frame
  18. parse_bmp_header Parse a BMP file header
  19. flip_vertical Flip an RGBA frame upside-down

Creates a new video buffer with the given pixel dimensions.

Creates a new video buffer with the given pixel dimensions. Defaults to 30 fps and "raw" codec. All frames added must be width * height * 4 bytes (RGBA).

use plugin video::{Video, create_raw_frame}

let vid = Video(320, 240)
vid.set_fps(24)
let frame = create_raw_frame(320, 240, 0, 128, 255)
vid.add_frame(frame)
print(vid.frame_count())

Append an RGBA frame to the video

Appends a raw RGBA frame (exactly width * height * 4 bytes) to the video buffer. Errors if the byte count does not match the video dimensions.

use plugin video::{Video, create_raw_frame}

let vid = Video(160, 120)
let red = create_raw_frame(160, 120, 255, 0, 0)
vid.add_frame(red)

Set the frames-per-second rate

Sets the playback frame rate. Must be greater than zero. Affects the value returned by duration.

use plugin video::{Video}

let vid = Video(640, 480)
vid.set_fps(60)

Set the codec label string

Sets the codec label string (e.g. "h264", "vp9", "raw"). This is metadata only and does not affect the stored frame bytes.

use plugin video::{Video}

let vid = Video(1920, 1080)
vid.set_codec("h264")

Change width and height before frames are added

Changes the video dimensions. Can only be called before any frames have been added — errors otherwise.

use plugin video::{Video}

let vid = Video(100, 100)
vid.set_resolution(1280, 720)

Get the number of stored frames

Returns the number of frames currently stored in the buffer.

use plugin video::{Video, create_raw_frame}

let vid = Video(64, 64)
vid.add_frame(create_raw_frame(64, 64, 0, 0, 0))
vid.add_frame(create_raw_frame(64, 64, 255, 255, 255))
print(vid.frame_count())

Get video duration in seconds

Returns the total duration in seconds calculated as frame_count / fps.

use plugin video::{Video, create_raw_frame}

let vid = Video(320, 240)
vid.set_fps(25)
vid.add_frame(create_raw_frame(320, 240, 0, 0, 0))
print(vid.duration())

Retrieve a frame by index

Returns the raw RGBA bytes for the frame at the given zero-based index. Errors if the index is out of range.

use plugin video::{Video, create_raw_frame}

let vid = Video(2, 2)
vid.add_frame(create_raw_frame(2, 2, 128, 64, 32))
let frame = vid.get_frame(0)
print(frame)

Set a metadata key-value pair

Sets a string metadata field on the video. Replaces the value if the key already exists.

use plugin video::{Video}

let vid = Video(1920, 1080)
vid.set_metadata("title", "My Video")
vid.set_metadata("author", "Alice")

Get all metadata as a table

Returns all metadata key-value pairs as a table.

use plugin video::{Video}

let vid = Video(640, 480)
vid.set_metadata("title", "Test")
let meta = vid.get_metadata()
print(meta["title"])

Get width, height, fps, codec, and duration

Returns a summary table with width, height, fps, codec, frame_count, and duration.

use plugin video::{Video}

let vid = Video(1280, 720)
vid.set_fps(30)
vid.set_codec("vp9")
let i = vid.info()
print("{i["width"]}x{i["height"]} @ {i["fps"]}fps")

Export all frames as a raw ZRAW byte blob

Exports all frames as a raw ZRAW container: a 20-byte header ("ZRAW" magic, width, height, fps, frame count) followed by the concatenated RGBA frame bytes.

use plugin video::{Video, create_raw_frame}

let vid = Video(4, 4)
vid.add_frame(create_raw_frame(4, 4, 255, 0, 0))
let raw = vid.export()
print(raw)

Remove all frames from the buffer

Removes all frames from the buffer, resetting frame_count to zero while keeping resolution, fps, codec, and metadata intact.

use plugin video::{Video, create_raw_frame}

let vid = Video(64, 64)
vid.add_frame(create_raw_frame(64, 64, 0, 0, 0))
vid.clear_frames()
print(vid.frame_count())

Create a solid-color RGBA frame

Creates a solid-color RGBA frame of w * h pixels. Alpha is always 255. Returns a byte blob of size w * h * 4.

use plugin video::{create_raw_frame}

let white = create_raw_frame(320, 240, 255, 255, 255)
let red   = create_raw_frame(320, 240, 255, 0, 0)

Strip alpha channel from RGBA bytes

Strips the alpha channel from RGBA bytes, returning a 3-bytes-per-pixel RGB blob. The input length must be a multiple of 4.

use plugin video::{create_raw_frame, rgba_to_rgb}

let rgba = create_raw_frame(10, 10, 128, 64, 32)
let rgb = rgba_to_rgb(rgba)

Add alpha channel to RGB bytes

Adds a fully opaque alpha channel (255) to each RGB pixel, returning an RGBA blob. The input length must be a multiple of 3.

use plugin video::{rgba_to_rgb, rgb_to_rgba, create_raw_frame}

let rgba = create_raw_frame(8, 8, 0, 200, 100)
let rgb  = rgba_to_rgb(rgba)
let back = rgb_to_rgba(rgb)

Compute byte size of a frame

Computes w * h * channels. Useful for pre-allocating buffers or validating frame byte lengths.

use plugin video::{frame_size}

print(frame_size(1920, 1080, 4))
print(frame_size(1920, 1080, 3))

Parse a BMP file header

Parses the header of a BMP file and returns a table with width, height, bpp (bits per pixel), and data_offset. Requires at least 54 bytes.

use plugin video::{parse_bmp_header}

let info = parse_bmp_header(bmp_bytes)
print("{info["width"]}x{info["height"]} @ {info["bpp"]}bpp")

Flip an RGBA frame upside-down

Flips an RGBA frame vertically by swapping rows top-to-bottom. The byte length must equal w * h * 4. Use this when working with BMP images, which are stored bottom-up.

use plugin video::{create_raw_frame, flip_vertical}

let frame = create_raw_frame(320, 240, 0, 128, 255)
let flipped = flip_vertical(frame, 320, 240)
enespt-br