Skip to content

Commit

Permalink
Merge pull request #67 from membraneframework/specify-output-stream-v…
Browse files Browse the repository at this point in the history
…ideo-size

Specify output stream video size
  • Loading branch information
FelonEkonom authored Mar 6, 2025
2 parents cfa42f1 + 01e81e1 commit 1469557
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/boombox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ defmodule Boombox do
| {: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()}
]

@typedoc """
Expand Down
14 changes: 10 additions & 4 deletions lib/boombox/elixir_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Boombox.ElixirStream do

alias __MODULE__.{Sink, Source}
alias Boombox.Pipeline.Ready
alias Membrane.FFmpeg.SWScale

@options_audio_keys [:audio_format, :audio_rate, :audio_channels]

Expand All @@ -21,7 +22,7 @@ defmodule Boombox.ElixirStream do
{:video,
get_child(:elixir_stream_source)
|> via_out(Pad.ref(:output, :video))
|> child(%Membrane.FFmpeg.SWScale.Converter{format: :I420})
|> child(%SWScale.Converter{format: :I420})
|> child(%Membrane.H264.FFmpeg.Encoder{profile: :baseline, preset: :ultrafast})}

:audio ->
Expand Down Expand Up @@ -67,8 +68,10 @@ defmodule Boombox.ElixirStream do
|> child(:elixir_stream_video_transcoder, %Membrane.Transcoder{
output_stream_format: Membrane.RawVideo
})
|> child(:elixir_stream_rgb_converter, %Membrane.FFmpeg.SWScale.Converter{
format: :RGB
|> child(:elixir_stream_rgb_converter, %SWScale.Converter{
format: :RGB,
output_width: options[:video_width],
output_height: options[:video_height]
})
|> via_in(Pad.ref(:input, :video))
|> get_child(:elixir_stream_sink)
Expand All @@ -90,7 +93,10 @@ defmodule Boombox.ElixirStream do
do: @options_audio_keys,
else: []

options = Keyword.validate!(options, [:video, :audio] ++ audio_keys) |> Map.new()
options =
options
|> Keyword.validate!([:video, :audio, :video_width, :video_height] ++ audio_keys)
|> Map.new()

if options.audio == false and options.video == false do
raise "Got audio and video options set to false. At least one track must be enabled."
Expand Down

0 comments on commit 1469557

Please sign in to comment.