View Source 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

Installation

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

	{:membrane_ffmpeg_swresample_plugin, "~> 0.16.0"}

You also need to have FFmpeg library installed.

usage

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 2018, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0