View Source Membrane H264 FFmpeg plugin

Hex.pm API Docs CircleCI

This package provides H264 video parser, decoder and encoder, based on ffmpeg and x264.

It is a part of the Membrane Multimedia Framework

Documentation is available at HexDocs

installation

Installation

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

	{:membrane_h264_ffmpeg_plugin, "~> 0.21.1"}

You also need to have ffmpeg libraries installed in your system.

ubuntu

Ubuntu

sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev

arch-manjaro

Arch/Manjaro

pacman -S ffmpeg

macos

MacOS

brew install ffmpeg

usage-example

Usage Example

decoder

Decoder

The following pipeline takes 30fps H264 file and decodes it to the raw video.

defmodule Decoding.Pipeline do
  use Membrane.Pipeline

  @impl true
  def handle_init(_) do
    children = [
      source: %Membrane.File.Source{chunk_size: 40_960, location: "input.h264"},
      parser: %H264.FFmpeg.Parser{framerate: {30, 1}},
      decoder: H264.FFmpeg.Decoder,
      sink: %Membrane.File.Sink{location: "output.raw"}
    ]

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

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

encoder

Encoder

The following pipeline takes 720p raw video file as input and encodes it as H264.

defmodule Encoding.Pipeline do
  use Membrane.Pipeline

  @impl true
  def handle_init(_) do
    children = [
      source: %Membrane.File.Source{chunk_size: 40_960, location: "input.raw"},
      parser: %Membrane.RawVideo.Parser{width: 1280, height: 720, pixel_format: :I420},
      encoder: %Membrane.H264.FFmpeg.Encoder{preset: :fast, crf: 30},
      sink: %Membrane.File.Sink{location: "output.h264"}
    ]

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

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

Copyright 2018, Software Mansion

Software Mansion