View Source Membrane H264 FFmpeg plugin
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.26.2"}
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(_ctx, _opts) do
structure =
child(:source, %Membrane.File.Source{chunk_size: 40_960, location: "input.h264"})
|> child(:parser, %H264.FFmpeg.Parser{framerate: {30, 1}})
|> child(:decoder, H264.FFmpeg.Decoder)
|> child(:sink, %Membrane.File.Sink{location: "output.raw"})
{[spec: structure], %{}}
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
structure =
child(:source, %Membrane.File.Source{chunk_size: 40_960, location: "input.raw"})
|> child(:parser, %Membrane.RawVideo.Parser{width: 1280, height: 720, pixel_format: :I420})
|> child(:encoder, %Membrane.H264.FFmpeg.Encoder{preset: :fast, crf: 30})
|> child(:sink, %Membrane.File.Sink{location: "output.h264"})
{[spec: structure], %{}}
end
end
copyright-and-license
Copyright and License
Copyright 2018, Software Mansion