ExCubecl.Transcode (ExCubecl v0.4.0)

Copy Markdown View Source

Encode and mux media output.

Supports file-to-file transcoding and frame-by-frame streaming encoding.

File-to-file transcode

ExCubecl.Transcode.run("input.mp4", "output.mp4",
  video: [codec: :h264, bitrate: "4M", fps: 30],
  audio: [codec: :aac, bitrate: "192k", sample_rate: 48000]
)

Frame-by-frame streaming transcode

{:ok, enc} = ExCubecl.Transcode.start("output.mp4",
  video: [codec: :h265, width: 1280, height: 720],
  audio: [codec: :aac]
)

ExCubecl.Transcode.write_frame(enc, processed_video_frame)
ExCubecl.Transcode.write_samples(enc, processed_audio_samples)
ExCubecl.Transcode.finish(enc)

Supported codecs

Video: h264, h265, vp9, av1, prores Audio: aac, opus, mp3, flac, pcm

Supported containers

mp4, mkv, webm, mov, ts

Summary

Functions

Finalizes encoding and closes the output file.

Transcodes an input file to an output file with the specified options.

Starts a streaming transcoder for frame-by-frame encoding.

Writes a video frame to the encoder.

Writes audio samples to the encoder.

Types

encoder()

@type encoder() :: reference()

Functions

finish(enc)

@spec finish(encoder()) :: :ok | {:error, term()}

Finalizes encoding and closes the output file.

run(input_path, output_path, opts \\ [])

@spec run(String.t(), String.t(), keyword()) :: :ok | {:error, term()}

Transcodes an input file to an output file with the specified options.

This is a convenience wrapper that opens the input, reads frames, applies encoding, and writes the output.

Options

  • :video — keyword list with :codec, :bitrate, :fps, :width, :height
  • :audio — keyword list with :codec, :bitrate, :sample_rate

start(output_path, opts \\ [])

@spec start(
  String.t(),
  keyword()
) :: {:ok, encoder()} | {:error, term()}

Starts a streaming transcoder for frame-by-frame encoding.

Returns an encoder reference to be used with write_frame/2, write_samples/2, and finish/1.

Options

  • :video — keyword list with :codec, :width, :height, :bitrate, :fps
  • :audio — keyword list with :codec, :bitrate, :sample_rate

write_frame(frame, enc)

@spec write_frame(encoder(), ExCubecl.VideoFrame.t()) :: :ok | {:error, term()}

Writes a video frame to the encoder.

write_samples(samples, enc)

@spec write_samples(encoder(), ExCubecl.AudioSamples.t()) :: :ok | {:error, term()}

Writes audio samples to the encoder.