Skip to content

Conversation

varsill
Copy link
Collaborator

@varsill varsill commented Mar 18, 2025

This PR adds support for:

  • VP9

TODO:

  • support for MP3

@varsill varsill requested a review from FelonEkonom March 25, 2025 09:57
cpu_quota = :erlang.system_info(:cpu_quota)

number_of_threads =
if cpu_quota != :unknown,
do: cpu_quota,
else: :erlang.system_info(:logical_processors_available)

builder |> child(:vp8_encoder, %VP8.Encoder{g_threads: number_of_threads, cpu_used: 15})
encoder = Module.concat(vpx, Encoder) |> struct!(g_threads: number_of_threads, cpu_used: 15)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like calling struct!/2 as it allows to create a struct that misses some required fields and I am not sure if it supports non-nil default values

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed struct!() usage for both H26x and VPx

@varsill varsill requested a review from FelonEkonom March 27, 2025 14:00
Comment on lines 140 to 132
Membrane.Logger.warning("""
The only input stream format that can be assumed is
`%Membrane.RemoteStream{content_format: Membrane.MPEGAudio}`, while you wanted to assume:
#{inspect(stream_format)}
""")

builder
|> child(:stream_format_changer, %Membrane.Transcoder.StreamFormatChanger{
stream_format: stream_format
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to raise here, as the code won't act as the user assumed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 122 to 151
defp maybe_plug_resampler(builder, input_format, %Opus{})
when not is_opus_compliant(input_format) do
builder
|> child(:resampler, %Membrane.FFmpeg.SWResample.Converter{
output_stream_format: %RawAudio{
sample_format: :s16le,
sample_rate: 48_000,
channels: 1
}
})
end

defp maybe_plug_resampler(builder, input_format, %AAC{})
when not is_aac_compliant(input_format) do
builder
|> child(:resampler, %Membrane.FFmpeg.SWResample.Converter{
output_stream_format: %RawAudio{
sample_format: :s16le,
sample_rate: 44_100,
channels: 1
}
})
end

defp maybe_plug_resampler(builder, input_format, %MPEGAudio{})
when not is_mp3_compliant(input_format) do
builder
|> child(:resampler, %Membrane.FFmpeg.SWResample.Converter{
output_stream_format: %RawAudio{sample_rate: 44_100, sample_format: :s32le, channels: 2}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice, but are you sure we don't want to plug resampler if e.g. input format doesn't have :channels field?

@varsill varsill requested a review from FelonEkonom April 10, 2025 09:15
Co-authored-by: Feliks Pobiedziński <[email protected]>
@varsill varsill merged commit d490293 into master Apr 10, 2025
0 of 3 checks passed
@varsill varsill deleted the varsill/support_more_codecs branch April 10, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants