Video capture and playback
File.cd(__DIR__)
Logger.configure(level: :error)
Mix.install([
{:membrane_core, "~> 1.0"},
{:membrane_h264_rgb_plugin, path: ".."},
# {:membrane_kino_plugin, github: "membraneframework-labs/membrane_kino_plugin", tag: "v0.4.0"},
{:membrane_kino_plugin, path: "../../membrane_kino_plugin"}
])
Pipeline definition
Live input video is requested from web browser (webcam), fed into elixir pipeline, converted to raw video RGB, scaled to desired resolution, converted back to I420 H264 and fed into kino player for live playback
import Membrane.ChildrenSpec
alias Membrane.{
Time,
Opus
}
alias Membrane.RCPipeline
width = 200
height = 200
kino_input =
Membrane.Kino.Input.new(
audio: false,
video: true,
flush_time: Time.milliseconds(10)
)
kino_player =
Membrane.Kino.Player.new(
audio: false,
video: true,
mirror: true,
flush_time: Time.milliseconds(10)
)
video_loopback = [
child(:source, %Membrane.Kino.Input.Bin.Source{kino: kino_input})
|> via_out(:video)
|> child(:rgb_decoder, %Membrane.H264_RGB.Decoder{
resolution: %{width: width, height: height}
})
|> child(:rgb_encoder, Membrane.H264_RGB.Encoder)
|> via_in(:video)
|> child(:player, %Membrane.Kino.Player.Sink{kino: kino_player})
]
:ok
Playing pipeline
pipeline = RCPipeline.start!()
RCPipeline.exec_actions(pipeline, spec: video_loopback)
Kino.render(kino_input)
kino_player