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
Add the following line to your deps
in mix.exs
. Run mix deps.get
.
{:membrane_h264_ffmpeg_plugin, "~> 0.28.0"}
You also need to have ffmpeg libraries installed in your system.
Ubuntu
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev
Arch/Manjaro
pacman -S ffmpeg
MacOS
brew install ffmpeg
Usage Example
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
Membrane.H264.FFmpeg.Parser
is not actively developed and will soon be deprecated in favour of our pure Elixir implementation of the H264 parser. We encourage you to try out Membrane.H264.Parser
from membrane_h264_plugin.
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 2018, Software Mansion