media

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package media is the shared media backend for image and video generation.

It owns the two provider surfaces the Content Creator relies on:

  • OpenAI-compatible /images/generations and /images/edits for stills, with optional reference images passed as JSON `images:[{image_url:dataURL}]`.
  • OpenAI-compatible async /videos → GET /videos/{id} → GET /videos/{id}/content for clips, with optional `input_reference:{image_url:dataURL}` seed.

Everything is HTTP JSON. There is no SDK dependency, no shell interpolation, no bearer forwarded to arbitrary download URLs, and no automatic retry of a paid POST — a failed create surfaces as an error the caller decides about. When the corresponding config block is disabled, endpoint resolution refuses and no request is issued.

Index

Constants

View Source
const (
	ReferenceModeEdits       = "edits"
	ReferenceModeGenerations = "generations"
)

How GenerateImage sends reference images; see config.ImageGen.ReferenceMode.

Variables

This section is empty.

Functions

func Assemble

func Assemble(ctx context.Context, clips []string, output, size string) error

Assemble concatenates clips into a single H.264/AAC MP4 at output. Each clip is normalised (scale+pad to size when set, silent AAC stereo added if missing, common fps) so a concat is guaranteed to succeed regardless of input diversity. The final file is probed and its actual duration/resolution are validated before the temp is renamed into place.

func DownloadVideo

func DownloadVideo(ctx context.Context, ep Endpoint, id, output string) error

DownloadVideo streams /videos/{id}/content to output atomically. Uses the provider bearer against the provider host; other hosts (e.g. presigned CDN URLs) would be reached through downloadURL, which does not forward the bearer.

func ExtractLastFrame

func ExtractLastFrame(ctx context.Context, videoPath, output, size string) error

ExtractLastFrame writes a single-frame image at output from the final frame of videoPath. If size is non-empty ("WxH") the frame is scaled+padded onto that canvas so it matches a later shot's resolution without stretching. Argv-only, no shell interpolation.

func GenerateImage

func GenerateImage(ctx context.Context, ep Endpoint, prompt, size string, references []string, output string) error

GenerateImage produces a single PNG at output. When references is empty it calls POST /images/generations. With references it follows ep.ReferenceMode: edits (the default) calls POST /images/edits with images:[{image_url}], and generations calls POST /images/generations with image:[dataURL...] for gateways that have no edits route. All non-URL fetches are bounded and the output is written atomically. Errors are redacted of the API key.

This is a paid POST: it is issued once, exactly. No automatic retry, and no hidden fallback to a different endpoint on 4xx.

func HasFFmpeg

func HasFFmpeg() bool

HasFFmpeg reports whether ffmpeg is available. Callers use it to render a clear "install ffmpeg" hint instead of failing mid-workflow.

func HasFFprobe

func HasFFprobe() bool

Types

type Endpoint

type Endpoint struct {
	BaseURL string
	APIKey  string
	Model   string
	Headers map[string]string
	// ReferenceMode is ReferenceModeEdits or ReferenceModeGenerations; empty
	// means edits. Only image requests with references look at it.
	ReferenceMode string
}

Endpoint is a resolved provider target: base URL, credential, model, plus any extra headers the provider needs. It is what every media call takes.

func ImageEndpoint

func ImageEndpoint(cfg *config.Config) (Endpoint, error)

ImageEndpoint resolves the image generation endpoint from cfg.ImageGen, falling back through cfg.ImageGen.Provider → cfg.Providers[id] → openai defaults. It refuses when the block is disabled or no key is available.

func VideoEndpoint

func VideoEndpoint(cfg *config.Config) (Endpoint, error)

VideoEndpoint resolves the video generation endpoint the same way, from cfg.VideoGen. Refuses when the block is disabled or no key is available.

type ProbeInfo

type ProbeInfo struct {
	Duration float64
	Width    int
	Height   int
	HasAudio bool
}

ProbeInfo is a subset of ffprobe output the workflow acts on.

func Probe

func Probe(ctx context.Context, path string) (ProbeInfo, error)

Probe returns basic media metadata for path.

type VideoJob

type VideoJob struct {
	ID       string `json:"id"`
	Status   string `json:"status"`
	Progress int    `json:"progress"`
	Error    string `json:"error,omitempty"`
}

VideoJob is the trimmed view of a provider video job the workflow needs. Status mirrors the provider ("queued"|"in_progress"|"completed"|"failed"), Progress is 0..100, and Error is non-empty when the provider reports one.

func CreateVideo

func CreateVideo(ctx context.Context, ep Endpoint, prompt, size string, seconds int, referencePath string) (VideoJob, error)

CreateVideo POSTs /videos with the prompt, size, seconds, and an optional image reference encoded as data URL under input_reference.image_url. It returns the queued VideoJob synchronously; the actual render happens on the provider and is polled with GetVideo. Paid call, issued once — no retry.

func GetVideo

func GetVideo(ctx context.Context, ep Endpoint, id string) (VideoJob, error)

GetVideo polls /videos/{id}. The provider assigns a numeric progress and a discrete status; callers download the content only when Status=="completed".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL