Boombox (Boombox v0.2.6)
View SourceBoombox is a tool for audio and video streaming.
See run/1 for details and examples.livemd for examples.
Summary
Types
When configuring a track for a media type (video or audio), the following options are used
In order to configure a RTP input a receiving port MUST be provided and the media that will be received
MUST be configured. Media configuration is explained further in common_rtp_opt/0.
In order to configure a RTP output the target port and address MUST be provided (can be provided in :target option as a <address>:<port> string)
and the media that will be sent MUST be configured. Media configuration is explained further in common_rtp_opt/0.
If true the incoming streams will be passed to the output according to their timestamps, if not they will be passed as fast as possible. True by default.
Functions
Asynchronous version of run/2.
Informs Boombox that it will not be provided any more packets with write/2 and should terminate
accordingly.
Runs boombox with given input and plays audio and video streams on your computer.
Reads a packet from Boombox.
Runs boombox with given input and output.
Runs boombox with CLI arguments.
Writes provided packet to Boombox.
Types
@opaque boombox_server()
      @type common_rtp_opt() :: {:video_encoding, Membrane.RTP.encoding_name()} | {:video_payload_type, Membrane.RTP.payload_type()} | {:video_clock_rate, Membrane.RTP.clock_rate()} | {:audio_encoding, Membrane.RTP.encoding_name()} | {:audio_payload_type, Membrane.RTP.payload_type()} | {:audio_clock_rate, Membrane.RTP.clock_rate()} | {:aac_bitrate_mode, Membrane.RTP.AAC.Utils.mode()}
When configuring a track for a media type (video or audio), the following options are used:
- <media_type>_encoding - MUST be provided to configure given media type. Some options are encoding-specific. Currently supported encodings are: AAC, Opus, H264, H265.
 - <media_type>_payload_type, <media_type>_clock rate - MAY be provided. If not, an unofficial default will be used. The following encoding-specific parameters are available for both RTP input and output:
 - aac_bitrate_mode - MUST be provided for AAC encoding. Defines which mode should be assumed/set when depayloading/payloading.
 
@type elixir_input() :: {:stream | :writer, in_raw_data_opts()}
@type elixir_output() :: {:stream | :reader, out_raw_data_opts()}
@type hls_mode_opt() :: {:mode, :live | :vod}
      @type hls_variant_selection_policy_opt() :: {:variant_selection_policy, Membrane.HTTPAdaptiveStream.Source.variant_selection_policy()}
@type in_rtp_opts() :: [ common_rtp_opt() | {:port, :inet.port_number()} | {:audio_specific_config, binary()} | {:vps, binary()} | {:pps, binary()} | {:sps, binary()} ]
In order to configure a RTP input a receiving port MUST be provided and the media that will be received
MUST be configured. Media configuration is explained further in common_rtp_opt/0.
The following encoding-specific parameters are available for RTP input:
- audio_specific_config - MUST be provided for AAC encoding. Contains crucial information about the stream and has to be obtained from a side channel.
 - vps (H265 only), pps, sps - MAY be provided for H264 or H265 encodings. Parameter sets, could be obtained from a side channel. They contain information about the encoded stream.
 
@type input() :: (path_or_uri :: String.t()) | {path_or_uri :: String.t(), [hls_variant_selection_policy_opt()] | [{:framerate, Membrane.H264.framerate() | Membrane.H265.framerate_t()}]} | {:mp4 | :aac | :wav | :mp3 | :ivf | :ogg | :h264 | :h265, location :: String.t()} | {:mp4 | :aac | :wav | :mp3 | :ivf | :ogg, location :: String.t(), [{:transport, :file | :http}]} | {:h264, location :: String.t(), transport: :file | :http, framerate: Membrane.H264.framerate()} | {:h265, location :: String.t(), transport: :file | :http, framerate: Membrane.H265.framerate_t()} | {:webrtc, webrtc_signaling()} | {:whip, uri :: String.t(), [{:token, String.t()}]} | {:rtmp, (uri :: String.t()) | (client_handler :: pid())} | {:rtsp, url :: String.t()} | {:rtp, in_rtp_opts()} | {:hls, url :: String.t()} | {:hls, url :: String.t(), [hls_variant_selection_policy_opt()]} | {:srt, url :: String.t()} | {:srt, url :: String.t(), srt_auth_opts()} | {:srt, server_awaiting_accept :: ExLibSRT.Server.t()}
@type out_raw_data_opts() :: [ {:audio, :binary | boolean()} | {:video, :image | boolean()} | {:audio_format, Membrane.RawAudio.SampleFormat.t()} | {:audio_rate, Membrane.RawAudio.sample_rate_t()} | {:audio_channels, Membrane.RawAudio.channels_t()} | {:video_width, non_neg_integer()} | {:video_height, non_neg_integer()} | pace_control_opt() ]
@type out_rtp_opts() :: [ common_rtp_opt() | {:address, :inet.ip_address() | String.t()} | {:port, :inet.port_number()} | {:target, String.t()} | transcoding_policy_opt() ]
In order to configure a RTP output the target port and address MUST be provided (can be provided in :target option as a <address>:<port> string)
and the media that will be sent MUST be configured. Media configuration is explained further in common_rtp_opt/0.
@type output() :: (path_or_uri :: String.t()) | {path_or_uri :: String.t(), [transcoding_policy_opt() | hls_mode_opt()]} | {:mp4 | :aac | :wav | :mp3 | :ivf | :ogg | :h264 | :h265, location :: String.t()} | {:mp4 | :aac | :wav | :mp3 | :ivf | :ogg | :h264 | :h265, location :: String.t(), [transcoding_policy_opt()]} | {:webrtc, webrtc_signaling()} | {:webrtc, webrtc_signaling(), [transcoding_policy_opt()]} | {:whip, uri :: String.t(), [ {:token, String.t()} | {bandit_option :: atom(), term()} | transcoding_policy_opt() ]} | {:hls, location :: String.t()} | {:hls, location :: String.t(), [hls_mode_opt() | transcoding_policy_opt()]} | {:rtp, out_rtp_opts()} | {:srt, url :: String.t()} | {:srt, url :: String.t(), srt_auth_opts()} | :player
@type pace_control_opt() :: {:pace_control, boolean()}
If true the incoming streams will be passed to the output according to their timestamps, if not they will be passed as fast as possible. True by default.
@type transcoding_policy_opt() :: {:transcoding_policy, :always | :if_needed | :never}
      @type webrtc_signaling() :: Membrane.WebRTC.Signaling.t() | String.t()
Functions
@spec async(Enumerable.t() | nil, input: input(), output: output()) :: Task.t() | Enumerable.t()
Asynchronous version of run/2.
Doesn't block the calling process until the termination of the processing.
It returns a Task.t() that can be awaited later.
If the output is a :stream or :reader endpoint, or the input is a :writer endpoint,
the behaviour is identical to run/2.
@spec close(Boombox.Writer.t()) :: :finished | {:error, :incompatible_mode}
Informs Boombox that it will not be provided any more packets with write/2 and should terminate
accordingly.
Can be called only when using :writer endpoint on input.
@spec play(Enumerable.t() | nil, input() | elixir_input()) :: :ok
Runs boombox with given input and plays audio and video streams on your computer.
Boombox.play(input) is idiomatic to Boombox.run(input: input, output: :player).
Example
Boombox.play("rtmp://localhost:5432")
  @spec read(Boombox.Reader.t()) :: {:ok | :finished, Boombox.Packet.t()} | {:error, :incompatible_mode}
Reads a packet from Boombox.
If returned with :ok, then this function can be called
again to request the next packet, and if returned with :finished, then Boombox finished it's
operation and will not produce any more packets.
Can be called only when using :reader endpoint on output.
@spec run(Enumerable.t() | nil, input: input() | elixir_input(), output: output() | elixir_output() ) :: :ok | Enumerable.t() | Boombox.Writer.t() | Boombox.Reader.t()
Runs boombox with given input and output.
Example
Boombox.run(input: "rtmp://localhost:5432", output: "index.m3u8")See input/0 and output/0 for available inputs and outputs and
examples.livemd for examples.
If the input is a :stream endpoint, a Stream or other Enumerable is expected
as the first argument.
If the input is a :writer endpoint this function will return a Boombox.Writer struct,
which is used to write media packets to boombox with write/2 and to finish writing with close/1.
If the output is a :reader endpoint this function will return a Boombox.Reader struct,
which is used to read media packets from boombox with read/1.
Boombox.run(
  input: "path/to/file.mp4",
  output: {:webrtc, "ws://0.0.0.0:1234"}
)
  @spec run_cli([String.t()]) :: :ok
Runs boombox with CLI arguments.
Example
# boombox.exs
Mix.install([:boombox])
Boombox.run_cli()elixir boombox.exs -i "rtmp://localhost:5432" -o "index.m3u8"
  @spec write(Boombox.Writer.t(), Boombox.Packet.t()) :: :ok | :finished | {:error, :incompatible_mode}
Writes provided packet to Boombox.
Returns :ok if more packets can be provided, and
:finished when Boombox finished consuming and will not accept any more packets. Returns
synchronously once the packet has been processed by Boombox.
Can be called only when using :writer endpoint on input.