Creating a Membrane Framework pipeline for converting a .ts file to a HLS playlist

I would like to create a HLS playlist that I can upload to S3 and serve adaptive bitrate video to visitors. To achieve this, I want to create an Oban worker which takes the URL of a .ts file as input, and outputs a URL of a .m3u8 playlist. The playlist would then get embedded into Heex in my Phoenix app.

I found another post with some code from 2-3 years ago which does what I want, but the dependent Membrane framework library membrane_mpegts_plugin hasn’t been updated in 4 years and isn’t compatible with membrane_core 1.1.2.

I really need to work with .ts files so I figured I’d update membrane_mpegts_plugin. Thankfully, membrane_core has a good changelog and upgrade guides which outline what needs to change in the plugin. I’ve spent two days on the task and I’ve made lots of progress, but I’ve ran into a testing error that I’m having trouble understanding and working through.

  1) test Demuxer works in a Pipeline that defines links statically in its init (Membrane.MPEG.TS.IntegrationTest)
     test/mpeg_ts/integration_test.exs:13
     Assertion failed, no matching message after 2000ms
     Showing 2 of 2 messages in the mailbox
     code: assert_receive {Membrane.Testing.Pipeline, ^pid_value, {:handle_element_start_of_stream, {:audio_out, :input}}}
     mailbox:
       pattern: {
                  Membrane.Testing.Pipeline,
                  ^pid_value,
                  {
                    :handle_element_start_of_stream,
                    {:audio_out, :input}
                  }
                }
       value:   {Membrane.Testing.Pipeline, #PID<0.278.0>, :setup}

       pattern: {
                  Membrane.Testing.Pipeline,
                  ^pid_value,
                  {
                    :handle_element_start_of_stream,
                    {:audio_out, :input}
                  }
                }
       value:   {Membrane.Testing.Pipeline, #PID<0.278.0>, :play}
     stacktrace:
       test/mpeg_ts/integration_test.exs:34: Membrane.MPEG.TS.IntegrationTest.perform_integration_test/1
       test/mpeg_ts/integration_test.exs:14: (test)

I’m struggling to understand why the shape of the pattern { Membrane.Testing.Pipeline, ^pid_value, { :handle_element_start_of_stream, {:audio_out, :input} } } is so different from the value {Membrane.Testing.Pipeline, #PID<0.278.0>, :play}. How come the pattern has a tuple after ^pid_value,, whereas the value has a :play atom after the PID? Normally this is where I would look at the code in the stack trace, but in this case there isn’t any file beyond integration_test.exs which I’m already familiar with.

I tried configuring ExUnit to show more stacktrace by setting :stacktrace_depth to 50, but that didn’t give me any more lines than the 2 I already see.

I’m hoping for some outside perspective to help get me back on track.

Hello @cgrimmett !
I think it might be easier for you to use: GitHub - kim-company/membrane_mpeg_ts_plugin: Membrane.Filter that demuxes MPEG-TS streams which is a plugin containing MPEG-TS demuxer, maintained by a third party. This one is up to date with membrane_core v1.1 and it’s undergoing active development.
For the list of actively maintained plugins you can take a look here: GitHub - membraneframework/membrane_core: The core of Membrane Framework, multimedia processing framework written in Elixir

Sorry for confusion, I think we should have deprecated that old membrane_mpegts_plugin package on Hex as I don’t think we plan to maintain it anymore.

I really appreciate you work on updating the plugin, I know how exhausting it can be!

If you would like to continue on updating membrane_mpegts_plugin, I can try to help with this one (but I definitely recommend trying the third party plugin).
It seems that for some reason buffers are not flowing in the pipeline. I suspect that it might have something to do with the fact, that now the default flow_control for both input and output pads in the filter is :auto and not :manual, as it used to be. It means that the logic in handle_demand nor sending :demand actions work at all.

1 Like

Oh thank you! I didn’t realize there was another mpeg-ts library. I will use that one instead.

1 Like