Video

Video values to BAML functions can be created in client libraries. This document explains how to use these functions both at compile time and runtime to handle video data. For more details, refer to video types.

When you create a Video using from_url or fromUrl, the URL is passed directly to the model without any intermediate fetching. If the model cannot access external media, it will fail on such inputs. In these cases, convert the video to Base64 before passing it to the model.

Usage Examples

1from baml_py import Video
2from baml_client import b
3
4async def test_video_input():
5 # Create a Video object from a URL
6 video = Video.from_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
7 res = await b.TestVideoInput(video=video)
8
9 # Create a Video object from Base64 data
10 video_b64 = "AAAAGGZ0eXBpc29t..."
11 video = Video.from_base64("video/mp4", video_b64)
12 res = await b.TestVideoInput(video=video)

Static Methods

fromUrl
(url: string, mediaType?: string) => Video

Creates a Video object from a URL. Optionally specify the media type, otherwise it will be inferred from the URL.

fromBase64
(mediaType: string, base64: string) => Video

Creates a Video object using Base64 encoded data along with the given MIME type.

fromFile
(file: File) => Promise<Video>

Only available in browser environments. @boundaryml/baml/browser
Creates a Video object from a File object. Available in browser environments only.

fromBlob
(blob: Blob, mediaType?: string) => Promise<Video>

Only available in browser environments. @boundaryml/baml/browser
Creates a Video object from a Blob object. Available in browser environments only.

fromUrlToBase64
(url: string) => Promise<Video>

Only available in browser environments.
Creates a Video object by fetching from a URL. Available in browser environments only.

Instance Methods

isUrl
() => boolean

Check if the video is stored as a URL.

asUrl
() => string

Get the URL of the video if it’s stored as a URL. Throws an Error if the video is not stored as a URL.

asBase64
() => [string, string]

Get the base64 data and media type if the video is stored as base64. Returns [base64Data, mediaType]. Throws an Error if the video is not stored as base64.

toJSON
() => { url: string } | { base64: string; media_type: string }

Convert the video to a JSON representation. Returns either a URL object or a base64 object with media type.