Author: Eiko

Tags: ffmpeg, video, audio, media, cli, linux

Time: 2024-11-11 21:33:48 - 2024-11-11 21:33:48 (UTC)

Basic Concepts Of ffmpeg

ffmpeg can read, filter, transcode, and stream multimedia content.

  • reads from arbitrary number of inputs (files, pipes, streams, devices).

    type FfmpegRead = [Media Input]
    data Media (io :: InOut) = File Object | Pipe Object | Stream Object | Device Object
    data InOut = Input | Output

    inputs are specified with the -i <input> option.

  • writes to arbitrary number of outputs, specified by plain output filename or url.

    type FfmpegWrite = [Media Output]

Elementary Streams

Each input or output can contain any number of elementary streams. An elementary stream can be:

  • video stream

  • audio stream

  • subtitle

  • attachment

  • data

data Object  = Object 
  { globalProps :: GlobalProps
  , metaData    :: MetaData
  , streams     :: [ElementaryStream]
  }
data ElementaryStream = Video | Audio | Subtitle | Attachment | Data

ffmpeg has no restriction, but the allowed streams depend on the container format.

Selecting the direction of stream from with input to which outpus is done with the -map option.

The indexes of inputs/outputs and streams start from 0. 2:3 refers to the 4th stream of the 3rd input/output.

Options apply to the next input/output, so the order of options is important.

Decoder

Decoder receive elementary streams and produce raw frames. This includes pixels for video, PCM for audio.

decoder :: ElementaryStream -> [RawFrame]

Filter Graphs

Filter graphs are used to process raw frames. It consists of one or more individual filters linked into a graph. There are two types of filtergraphs:

  • Simple -filter has a single input and a single output.

    simpleFilter :: [RawFrame] -> [RawFrame]
  • Complex -filter_complex may have multiple or zero inputs, each of them receiving from decoder or another complex filtergraph’s output. Can have one or more outputs.

    complexFilter :: [[RawFrame]] -> [[RawFrame]]