peggy

A module for utilizing FFmpeg in Gleam. It requires that you have FFmpeg in your path. This modules contains the tools for building FFmpeg commands in a type-safe manner appropriate for video services written in this wonderful language.

Types

pub type Cfg {
  Cfg(overwrite_out: Bool)
}

Constructors

  • Cfg(overwrite_out: Bool)

A CLI argument provided to FFmpeg

pub type CmdOption {
  CmdOption(name: String, value: String)
  Flag(flag: String)
}

Constructors

  • CmdOption(name: String, value: String)
  • Flag(flag: String)

Command provided to FFmpeg

pub type Command {
  Command(
    files: List(File),
    options: List(CmdOption),
    config: Cfg,
  )
}

Constructors

  • Command(files: List(File), options: List(CmdOption), config: Cfg)

A file input provided to FFmpeg

pub type File {
  File(String)
}

Constructors

  • File(String)

Constants

pub const default_cfg: Cfg

Functions

pub fn add_arg(
  cmd: Command,
  name: String,
  value: String,
) -> Command

Adds argument to command

pub fn add_file(cmd: Command, file_name: String) -> Command

Adds file to command

pub fn add_flag(cmd: Command, flag: String) -> Command
pub fn allow_recast(cmd: Command) -> Command

Allow forcing a decoder of a different media type than the one detected or designated by the demuxer.

CMD: -recast_media

pub fn aspect_ratio(cmd: Command, ratio: String) -> Command

Set aspect ratio

CMD: -aspect

pub fn audio_bitrate(cmd: Command, rate: String) -> Command

Set audio bitrate

CMD: -b:a

pub fn audio_codec(cmd: Command, codec: String) -> Command

Specify audio codec

use ‘copy’ to copy stream

CMD: -c:a <audio_codec>

pub fn audio_filter(cmd: Command, filter: String) -> Command

Apply filter to audio

CMD: -af

pub fn audio_frame_rate(cmd: Command, rate: String) -> Command

Set audio frame rate

CMD: -s

pub fn audio_pad(cmd: Command) -> Command

Audio pad

CMD: -apad

pub fn audio_quality(cmd: Command, quality: String) -> Command

Set audio quality

This configuration is codec-specific

CMD: -aq

pub fn codec(cmd: Command, codec: String) -> Command

Specify codec

use ‘copy’ to copy stream

CMD: -c

pub fn disable_audio(cmd: Command) -> Command

Disable audio output

CMD: -an

pub fn disable_data(cmd: Command) -> Command

Disable data

CMD: -dn

pub fn disable_subtitle(cmd: Command) -> Command

Disable subtitles

-cn

pub fn disable_video(cmd: Command) -> Command

Disable video output

CMD: -vn

pub fn discard(cmd: Command) -> Command

Set discard

pub fn disposition(cmd: Command) -> Command

Set discard

pub fn duration(cmd: Command, duration: String) -> Command

Specifies duration to read/write from/to input/output Arg given before input -> duration of input Arg given after input -> duration of output

This argument takes precedent over until (-to)

CMD: -t

pub fn err_rate(cmd: Command, rate: Float) -> Command

Set maximum error rate 0.0 -> No errors 1.0 -> All errors

CMD: -max_err_rate

pub fn exec_sync(cmd: Command) -> Result(String, String)

Executes the command provided to ffmpeg

pub fn fmt(cmd: Command, format: String) -> Command

Specify format of output

pub fn frame_rate(cmd: Command, rate: String) -> Command

Set video frame rate

CMD: -s

pub fn frame_rate_max(cmd: Command, rate: String) -> Command

Set frame size

CMD: -s

pub fn frame_size(cmd: Command, size: String) -> Command

Set frame size

CMD: -s

pub fn input(cmd: Command, url: String) -> Command

Add input to command

pub fn limit_size(cmd: Command, size: Int) -> Command

Limit size of output file to a set number of bytes

CMD: -fs

pub fn loop(cmd: Command, loops: Int) -> Command

Specify format of output 0 -> No loop -1 -> Infinite loop

CMD: -stream_loop

pub fn metadata(cmd: Command, metastring: String) -> Command

Add metadata to output

Usage

peggy.new_command() |> peggy.input(“input.mp4”) |> peggy.metadata(“description = "awesome video"”) |> peggy.metadata(“"filmed by" = "some person"”) |> peggy.output(“output.mp4”) |> peggy.exec_sync()

CMD: -metadata <key=value>

pub fn new_command() -> Command

Creates new command for executing an FFmpeg command

pub fn no_overwrite(cmd: Command) -> Command

Do not overwrite the output file if exists. If the output file already exists, you will get an error

CMD: -n

pub fn num_audio_frames(cmd: Command, num: String) -> Command

Set number of audio frames

CMD: -frames

pub fn num_frames(cmd: Command, num: String) -> Command

Set number of frames

CMD: -frames

pub fn num_video_frames(cmd: Command, num: String) -> Command

Set number of video frames

CMD: -frames

pub fn output(cmd: Command, output: String) -> Command

Specify output of file

CMD:

pub fn overwrite(cmd: Command) -> Command

Overwrite output files if necessary

CMD: -y

pub fn seek(cmd: Command, pos: Int) -> Command

Seek position in input or output Arg given before input -> seek in input Arg given after input -> seek in output

CMD: -ss

pub fn seek_eof(cmd: Command, pos: Int) -> Command

Seek position in input or output relative to EOF Position should be negative in this case (0 is EOF) Arg given before input -> seek in input Arg given after input -> seek in output

CMD: -sseof

pub fn set_pass(cmd: Command, pass: Int) -> Command

Set frame size

CMD: -pass <1|2|3>

pub fn subtitle_codec(cmd: Command, codec: String) -> Command

Set subtitle codec

‘copy’ to copy stream

CMD: -c:s

pub fn target(cmd: Command, tgt: String) -> Command

Set target filetype

pub fn until(cmd: Command, stamp: String) -> Command

Specifies location to stop reading/writing at Arg given before input -> duration of input Arg given after input -> duration of output

CMD: -to

pub fn video_bitrate(cmd: Command, rate: String) -> Command

Set video bitrate

CMD: -b:v

pub fn video_codec(cmd: Command, codec: String) -> Command

Specify video codec

use ‘copy’ to copy stream

CMD: -c:v <video_codec>

pub fn video_filter(cmd: Command, filter: String) -> Command

Apply filter to video

CMD: -vf

pub fn volume(cmd: Command, volume: String) -> Command

Set volume 256 = normal

CMD: -vol

Search Document