akash-akya

akash-akya

Hi everyone,

I made a small Elixir library called FFix.

FFix helps you build ffmpeg commands and filter graphs using Elixir data and functions, instead of manually joining long -filter_complex, -map, and option strings.

It does not try to hide ffmpeg. Filter names, options, stream mappings, codecs, and muxer options are still ffmpeg-shaped. FFix just gives you a nicer way to compose and inspect them from Elixir.

Examples

Examples assume import FFix and import FFix.Filter.

cmd =
  command(
    "input.mp4",
    fn src ->
      src[:video]
      |> crop(w: 720, h: 720)
    end,
    fn cropped, src ->
      output("square.mp4", video: cropped, audio: src[:audio])
    end
  )

FFix.to_argv(cmd)

This builds a command like:

ffmpeg -i input.mp4 \
  -filter_complex '[0:v]crop=w=720:h=720[out0]' \
  -map '[out0]' \
  -map 0:a \
  square.mp4

A more useful example is when the filter graph starts branching.

This creates a vertical video from a normal landscape video. It splits the video into two branches: one branch becomes a blurred background, and the other is scaled and placed on top.

cmd =
  command(
    "input.mp4",
    fn src ->
      [bg_src, fg_src] = split(src[:video], outputs: 2)

      bg =
        bg_src
        |> scale(w: 1080, h: 1920, force_original_aspect_ratio: :increase)
        |> crop(w: 1080, h: 1920)
        |> gblur(sigma: 30)

      fg =
        fg_src
        |> scale(w: 1080, h: -1)

      bg
      |> overlay(fg, x: expr("(W-w)/2"), y: expr("(H-h)/2"))
    end,
    fn video, src ->
      output("vertical.mp4",
        video: video,
        audio: src[:audio],
        "c:v": :libx264,
        "c:a": :copy,
        shortest: true
      )
    end
  )

The same thing in raw ffmpeg form is roughly:

ffmpeg -i input.mp4 \
  -filter_complex "\
[0:v]split=outputs=2[bg_src][fg_src];\
[bg_src]scale=w=1080:h=1920:force_original_aspect_ratio=increase,crop=w=1080:h=1920,gblur=sigma=30[bg];\
[fg_src]scale=w=1080:h=-1[fg];\
[bg][fg]overlay=x=(W-w)/2:y=(H-h)/2[outv]" \
  -map "[outv]" \
  -map 0:a \
  -c:v libx264 \
  -c:a copy \
  -shortest \
  vertical.mp4

FFix is mostly useful when these commands are not static strings, and you need to build them from user input, stored config, templates, or application logic.


It also supports streaming. For example, this reads WAV data through stdin and streams MP3 data back through stdout:

cmd =
  command(
    input(:stdin, f: :wav),
    fn src ->
      src[:audio]
    end,
    fn audio ->
      output(:stdout,
        audio: audio,
        f: :mp3,
        "c:a": :libmp3lame
      )
    end
  )

cmd
|> FFix.stream!(stdin: File.stream!("input.wav", [], 8192))
|> Stream.filter(fn
  {:stdout, _chunk} -> true
  _event -> false
end)
|> Stream.map(fn {:stdout, chunk} -> chunk end)
|> Enum.into(File.stream!("output.mp3", [:write, :binary]))

And one command can write multiple outputs. For example, generate MP4 and WebM versions from the same input:

cmd =
  command(
    "input.mov",
    fn src ->
      [src[:video], src[:audio]]
    end,
    fn [video, audio] ->
      [
        output("video.mp4",
          video: video,
          audio: audio,
          "c:v": :libx264,
          "c:a": :aac,
          movflags: [:faststart]
        ),

        output("video.webm",
          video: video,
          audio: audio,
          "c:v": :"libvpx-vp9",
          "c:a": :libopus
        )
      ]
    end
  )

Some things FFix supports today:

  • Build ffmpeg commands and filter graphs with Elixir data/functions instead of raw string assembly.
  • Generated helpers and docs for ffmpeg filters like scale, crop, overlay, drawtext, fps, etc.
  • Named graph outputs, multiple inputs/outputs, and stream selectors like src[:video], src[:audio], src[audio: 1].
  • Parsing and serializing filter graphs.
  • to_argv/1 for the command boundary, plus a thin runner for stdin/stdout streaming, collected results, progress events, and ffmpeg logs.

For more details, the docs have the full API and more examples. There is an intro Livebook too.

The goal is to stay close to ffmpeg and keep the core simple. FFix models commands and filter graphs as normal Elixir data, and only serializes them to ffmpeg syntax at the boundary. I’ve used some version of this library for my own ffmpeg tasks for a few years. It was sitting in my backlog for a long time, so I finally cleaned it up and organised it with some help from an LLM agent.

Feedback is very welcome, especially on the API shape and scope.

Install:

def deps do
  [
    {:ffix, "~> 0.1.0"}
  ]
end

Note: ffmpeg must be available at compile time, because FFix generates filter helpers/docs from local ffmpeg metadata.

Links:

https://github.com/akash-akya/ffix

Showing Posts 1 to 1

manhvu

manhvu

Uses pipes to pass arguments to ffmpeg is a nice way.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews