View Source Membrane Opus plugin

Hex.pm API Docs CircleCI

Opus encoder and decoder.

It is a part of Membrane Multimedia Framework.

installation

Installation

The package can be installed by adding membrane_opus_plugin to your list of dependencies in mix.exs:

def deps do
  [
	{:membrane_opus_plugin, "~> 0.15.0"}
  ]
end

This package depends on libopus library.

ubuntu

Ubuntu

sudo apt-get install libopus-dev

arch-manjaro

Arch/Manjaro

pacman -S opus

macos

MacOS

brew install opus

usage

Usage

encoder

Encoder

The pipeline encodes a sample raw file and saves it as an opus file:

defmodule Membrane.ReleaseTest.Pipeline do
  use Membrane.Pipeline

  alias Membrane.RawAudio

  @impl true
  def handle_init(_) do
    children = [
      source: %Membrane.File.Source{
        location: "/tmp/input.raw"
      },
      encoder: %Membrane.Opus.Encoder{
        application: :audio,
        input_caps: %RawAudio{
          channels: 2,
          sample_format: :s16le,
          sample_rate: 48_000
        }
      },
      parser: %Membrane.Opus.Parser{delimitation: :delimit},
      sink: %Membrane.File.Sink{
        location: "/tmp/output.opus"
      }
    ]

    links = [
      link(:source)
      |> to(:encoder)
      |> to(:parser)
      |> to(:sink)
    ]

    {{:ok, spec: %ParentSpec{children: children, links: links}}, %{}}
  end
end

Opus audio generally needs to be packaged in an Ogg container in order to be played by a media player. See Membrane.Ogg.Payloader in the Membrane Ogg Plugin.

decoder

Decoder

The pipeline parses, decodes a sample opus file and then saves it as a raw file:

defmodule Membrane.ReleaseTest.Pipeline2 do
  use Membrane.Pipeline

  @impl true
  def handle_init(_) do
    children = [
      source: %Membrane.File.Source{
        location: "/tmp/input.opus"
      },
      parser: Membrane.Opus.Parser,
      opus: Membrane.Opus.Decoder,
      sink: %Membrane.File.Sink{
        location: "/tmp/output.raw"
      }
    ]

    links = [
      link(:source)
      |> to(:parser)
      |> to(:opus)
      |> to(:sink)
    ]

    {{:ok, spec: %ParentSpec{children: children, links: links}}, %{}}
  end
end

Copyright 2019, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0