ffmpex v0.7.1 FFmpex

Create and execute ffmpeg CLI commands.

The API is a builder, building up the list of options per-file, per-stream(-per-file), and globally.

Note that adding options is backwards from using the ffmpeg CLI; when using ffmpeg CLI, you specify the options before each file. But with FFmpex (this library), you add the file/stream first, then add the relevant options afterward.

Example usage:

import FFmpex
use FFmpex.Options

command =
  FFmpex.new_command
  |> add_global_option(option_y())
  |> add_input_file("/path/to/input.avi")
  |> add_output_file("/path/to/output.avi")
    |> add_stream_specifier(stream_type: :video)
      |> add_stream_option(option_b("64k"))
    |> add_file_option(option_maxrate("128k"))
    |> add_file_option(option_bufsize("64k"))

:ok = execute(command)

Link to this section Summary

Functions

Add a per-file option to the command. Applies to the most recently added file.

Add a global option that applies to the entire command.

Add an input file to the command.

Add an output file to the command.

Add a per-stream option to the command. Applies to the most recently added stream specifier, of the most recently added file.

Add a stream specifier to the most recent file. The stream specifier is used as a target for per-stream options.

Execute the command using ffmpeg CLI.

Begin a new blank (no options) ffmpeg command.

Prepares the command to be executed, by converting the %Command{} into proper parameters to be feeded to System.cmd/3 or Port.open/2.

Link to this section Functions

Link to this function

add_file_option(command, option)

Add a per-file option to the command. Applies to the most recently added file.

Link to this function

add_global_option(command, option)

Add a global option that applies to the entire command.

Link to this function

add_input_file(command, file)

Add an input file to the command.

Link to this function

add_output_file(command, file)

Add an output file to the command.

Link to this function

add_stream_option(command, option)

Add a per-stream option to the command. Applies to the most recently added stream specifier, of the most recently added file.

Link to this function

add_stream_specifier(command, opts)

add_stream_specifier(command :: FFmpex.Command.t(), opts :: Keyword.t()) ::
  FFmpex.Command.t()

Add a stream specifier to the most recent file. The stream specifier is used as a target for per-stream options.

Example:

add_stream_specifier(command, stream_type: :video)

Options:

  • :stream_index - 0-based integer index for the stream
  • :stream_type - One of :video, :video_without_pics, :audio, :subtitle, :data, :attachments
  • :program_id - ID for the program
  • :stream_id - Stream id (e.g. PID in MPEG-TS container)
  • :metadata_key - Match streams with the given metadata tag
  • :metadata_value - Match streams with the given metadata value. Must also specify :metadata_key.
  • :usable - Matches streams with usable configuration, the codec must be defined and the essential information such as video dimension or audio sample rate must be present.
Link to this function

execute(command)

execute(command :: FFmpex.Command.t()) ::
  :ok | {:error, {Collectable.t(), exit_status :: non_neg_integer()}}

Execute the command using ffmpeg CLI.

Returns :ok on success, or {:error, {cmd_output, exit_status}} on error.

Begin a new blank (no options) ffmpeg command.

Link to this function

prepare(command)

prepare(command :: FFmpex.Command.t()) :: {binary() | nil, [binary()]}

Prepares the command to be executed, by converting the %Command{} into proper parameters to be feeded to System.cmd/3 or Port.open/2.

Under normal circumstances FFmpex.execute/1 should be used, use prepare only when converted args are needed to be feeded in a custom execution method.

Returns {ffmpeg_executable_path, list_of_args}.