PortAudio to AAC Error: Failed to create native encoder: :"Invalid config"

Hey,

I’m trying to stream from PortAudio to HLS as below.

The pipeline breaks when converting RawAudio to AAC with Failed to create native encoder: :"Invalid config"

How can I get around this? Thanks.

child(:pa_src, PortAudio.Source)
|> child(:hls_out_aac_encoder, Membrane.AAC.FDK.Encoder)
|> via_in(Pad.ref(:input, :audio),
  options: [encoding: :AAC, segment_duration: Membrane.Time.milliseconds(2000)]
)
|> child(
  :hls_sink_bin,
  %Membrane.HTTPAdaptiveStream.SinkBin{
    manifest_name: manifest_name,
    manifest_module: Membrane.HTTPAdaptiveStream.HLS,
    storage: %Membrane.HTTPAdaptiveStream.Storages.FileStorage{
      directory: directory
    },
    hls_mode: hls_mode,
    mp4_parameters_in_band?: true,
    target_window_duration: Membrane.Time.seconds(20)
  }
)
1 Like

Hi, can you plug a debug filter right after the source and post the output here?

|> child(%Membrane.Debug.Filter{handle_buffer: &IO.inspect/1})
1 Like

I get multiple instances of %Membrane.Buffer{}

The first two being:

%Membrane.Buffer{
  payload: <<93, 233, 0, 128, 93, 233, 0, 128, 174, 180, 0, 0, 93, 233, 0, 128,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, ...>>,
  pts: 0,
  dts: nil,
  metadata: %{}
}
%Membrane.Buffer{
  payload: <<128, 233, 0, 128, 128, 233, 0, 128, 192, 180, 0, 0, 128, 233, 0,
    128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>,
  pts: 75366,
  dts: nil,
  metadata: %{}
}

And the last two being:

%Membrane.Buffer{
  payload: <<130, 242, 0, 128, 130, 242, 0, 128, 65, 185, 0, 0, 130, 242, 0,
    128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>,
  pts: 75760762,
  dts: nil,
  metadata: %{}
}
%Membrane.Buffer{
  payload: <<206, 242, 0, 128, 206, 242, 0, 128, 103, 185, 0, 0, 206, 242, 0,
    128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>,
  pts: 75824006,
  dts: nil,
  metadata: %{}
}

And here’s a fuller stack trace of the original error:

[error] <0.977.0>/:hls_out_aac_encoder Error occured in Membrane Element:
** (RuntimeError) Failed to create native encoder: :"Invalid config"
    (membrane_aac_fdk_plugin 0.18.10) lib/membrane_aac_fdk_plugin/encoder.ex:255: Membrane.AAC.FDK.Encoder.mk_native!/5
    (membrane_aac_fdk_plugin 0.18.10) lib/membrane_aac_fdk_plugin/encoder.ex:111: Membrane.AAC.FDK.Encoder.handle_stream_format/4
    (membrane_core 1.1.2) lib/membrane/core/callback_handler.ex:139: Membrane.Core.CallbackHandler.exec_callback/4
    (membrane_core 1.1.2) lib/membrane/core/callback_handler.ex:69: Membrane.Core.CallbackHandler.exec_and_handle_callback/5
    (membrane_core 1.1.2) lib/membrane/core/element/stream_format_controller.ex:82: Membrane.Core.Element.StreamFormatController.exec_handle_stream_format/4
    (membrane_core 1.1.2) lib/membrane/core/element.ex:237: Membrane.Core.Element.handle_info/2
    (stdlib 6.1.2) gen_server.erl:2345: :gen_server.try_handle_info/3
    (stdlib 6.1.2) gen_server.erl:2433: :gen_server.handle_msg/6
    (stdlib 6.1.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

Oops sorry, I meant handle_stream_format, not handle_buffer

%Membrane.RawAudio{channels: 32, sample_rate: 44100, sample_format: :s16le}

Right, so PortAudio somehow detects 32 audio channels in your input device, and AAC cannot encode that… Try setting channels: 1 or channels: 2 option in the source

Yes! That fixes it.

Thank you.

On a related note, is there then a way with membrane to stream AAC to an rtmp endpoint?

If it has to be via ffmpeg, any pointers on how to achieve that in a membrane pipeline?

I opened Add input channels constraint to encoder by mat-hek · Pull Request #62 · membraneframework/membrane_aac_fdk_plugin · GitHub, so the error should be better in such cases :wink:

Regarding RTMP, there’s Membrane.RTMP.Sink — Membrane RTMP plugin v0.27.3

1 Like

This is helpful

Thanks!

1 Like