Skip to Content
defold-typescript libraries
defold (official)

defold/extension-videoplayer-mpeg/mpeg

Functions to play MPEG1 videos

  • GitHub: defold/extension-videoplayer-mpeg — pinned to 1.1.1 (released while Defold 1.10.2 was current)
    1. Pick a release from defold/extension-videoplayer-mpeg releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as mpeg from "mpeg"

Functions

mpeg.open(video: buffer | string): LuaMultiReturn<[number, string]>

Open a video for decoding.

Parameters

  • video: buffer | string — The video data as a buffer or string. Ownership of the buffer is not transferred.

Returns

  • handle: number — Returns video handle. Use in subsequent calls.
  • err: string — Error message if video failed to open.

mpeg.close(handle: number)

Close an opened video. This will release an memory allocated by the videoplayer.

Parameters

  • handle: number — The video handle to close.

mpeg.decode(handle: number, seconds: number)

Advance the internal timer by seconds and decode video/audio up to this time.

Parameters

  • handle: number — The video handle to decode.
  • seconds: number — Number of seconds to advance.

mpeg.write(handle: number, data: string): LuaMultiReturn<[number, string]>

Write data to the internal stream buffer of a video started with stream(). Use the streaming_buffer_bytes_remaining and streaming_buffer_capacity to determine how much data to write to the buffer.

Parameters

  • handle: number — The video handle to write to.
  • data: string — Bytes with stream data.

Returns

  • bytes_written: number — The number of written bytes or nil if writing failed.
  • error: string — Error message if writing failed for some reason.

mpeg.seek(handle: number, time: number, seek_exact: boolean)

Seek to the specified time. Will seek to the last intra frame just before the desired time.

Parameters

  • handle: number — The video handle to seek on.
  • time: number — Time to seek to.
  • seek_exact: boolean — If value is true the function will seek to the exact time, otherwise it will seek to the last intra frame just before the desired time. Exact seeking can be slow, because all frames up to the seeked one have to be decoded on top of the previous intra frame. Defaults to false.

mpeg.rewind(handle: number)

Rewind video to the beginning.

Parameters

  • handle: number — The video handle to rewind.

mpeg.get_frame(handle: number): buffer

Get the video frame buffer. The video frame buffer will be updated when decode() is called and enough data has been decoded to produce a frame.

Parameters

  • handle: number — The video handle to get frame buffer for.

Returns

  • frame: buffer — The decoded video frame buffer or nil if no video frame buffer is available. The ownership of the buffer is not transferred to the caller.

mpeg.get_info(handle: number): table

Get information about an opened video.

Parameters

  • handle: number — The video to get info for.

Returns

  • info: table — Video information
    • width: number — Video width.
    • height: number — Video height.
    • bytes_per_pixel: number — The number of bytes per pixel.
    • framerate: number — The frame rate (frames per second) of the video stream.
    • samplerate: number — The sample rate (samples per second) of the audio stream.
    • is_looping: boolean — If the video is looping or not.
    • is_streaming: boolean — If the video is opened in streaming mode.
    • eos: boolean — If the video has reached the end of stream.
    • streaming_buffer_bytes_remaining: number — The number of unread bytes remaining in the stream buffer when streaming.
    • streaming_buffer_capacity: number — The capacity of the stream buffer in bytes.

On this page