Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 2.47 KB

File metadata and controls

80 lines (55 loc) · 2.47 KB

Membrane FFmpeg SWResample plugin

Hex.pm API Docs CircleCI

Plugin performing audio conversion, resampling and channel mixing, using SWResample module of FFmpeg library.

It is a part of Membrane Multimedia Framework.

Installation

Add the following line to your deps in mix.exs. Run mix deps.get.

{:membrane_ffmpeg_swresample_plugin, "~> 0.20.2"}

The precompiled builds of the ffmpeg will be pulled and linked automatically. However, should there be any problems, consider installing it manually.

Manual instalation of dependencies

macOS

brew install ffmpeg

Ubuntu

sudo apt-get install ffmpeg

Arch / Manjaro

pacman -S ffmpeg

Usage

The pipeline takes raw audio, converts the sample format from s24le to f32le and resamples it to 44.1 kHz rate.

defmodule Resampling.Pipeline do
  use Membrane.Pipeline

  alias Membrane.FFmpeg.SWResample.Converter
  alias Membrane.{File, RawAudio}

  @impl true
  def handle_init(_ctx, _opts) do
    structure = [
      child(:file_src, %File.Source{location: "/tmp/input.raw"})
      |> child(:converter, %Converter{
        input_stream_format: %RawAudio{channels: 2, sample_format: :s24le, sample_rate: 48_000},
        output_stream_format: %RawAudio{channels: 2, sample_format: :f32le, sample_rate: 44_100}
      })
      |> child(:file_sink, %File.Sink{location: "/tmp/output.raw"})
    ]

    {[spec: structure, playback: :playing], nil}
  end

  @impl true
  def handle_element_end_of_stream(:file_sink, _pad, _ctx_, _state) do
    {[playback: :stopped], nil}
  end
end

Copyright and License

Copyright 2018, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0