hlcfan
I’m playing around with membrane, trying to stream an MP4(h264/aac) file through HLS to my phone, I think the first thing is to demux the file into video and audio streams. The code look like this
use Membrane.Pipeline
def handle_init(path_to_file) do
children = %{
source_file: %Membrane.File.Source{location: path_to_file},
demuxer: Membrane.MPEG.TS.Demuxer,
video_parser: %Membrane.H264.FFmpeg.Parser{framerate: {24, 1}},
video_decoder: Membrane.H264.FFmpeg.Decoder,
audio_decoder: Membrane.AAC.FDK.Decoder,
audio_converter: %FFmpeg.SWResample.Converter{
output_caps: %Membrane.Caps.Audio.Raw{channels: 2, format: :s16le, sample_rate: 48_000}
},
sink: %Membrane.File.Sink{location: "video_output"},
portaudio: PortAudio.Sink
}
links = [
link(:source_file) |> to(:demuxer),
link(:demuxer) |> via_out(Pad.ref(:output, 256)) |> to(:video_parser),
link(:demuxer) |> via_out(Pad.ref(:output, 257)) |> to(:audio_decoder),
link(:video_parser) |> to(:video_decoder),
link(:video_decoder) |> to(:sink),
link(:audio_decoder) |> to(:audio_converter),
link(:audio_converter) |> to(:portaudio)
]
spec = %ParentSpec{
children: children,
links: links
}
{{:ok, spec: spec}, %{}}
end
However, when I run it, there’s no sound, and also video_output is zero bytes.
iex(3)> Pipeline.play(pid)
:ok
iex(4)>
21:01:41.415 [debug] [pipeline@<0.295.0>] Changing playback state from stopped to prepared
21:01:41.441 [debug] [pipeline@<0.295.0>] Playback state changed from stopped to prepared
21:01:41.441 [debug] [pipeline@<0.295.0>] Changing playback state from prepared to playing
21:01:41.441 [debug] [:video_decoder] Evaluating playback buffer
21:01:41.441 [debug] [:source_file] Evaluating playback buffer
21:01:41.441 [debug] [:video_parser] Evaluating playback buffer
21:01:41.441 [debug] [:audio_converter] Evaluating playback buffer
21:01:41.441 [debug] [:audio_decoder] Evaluating playback buffer
21:01:41.441 [debug] [:sink] Evaluating playback buffer
21:01:41.441 [debug] [:demuxer] Evaluating playback buffer
21:01:41.488 [debug] [:portaudio] Evaluating playback buffer
21:01:41.488 [debug] [pipeline@<0.295.0>] Playback state changed from prepared to playing
21:01:41.499 [debug] [:video_parser] Ignoring event %Membrane.Core.Events.EndOfStream{}
21:01:41.499 [debug] [:audio_decoder] Ignoring event %Membrane.Core.Events.EndOfStream{}
I need a bit help here, am I doing this correctly?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mat-hek
Hi @hlcfan, you’re right, the first step would be to demux the MP4, but you’re using
Membrane.MPEG.TS.Demuxer, that is able to demux MPEG-TS stream, not MP4. We don’t have MP4 demuxer in Membrane yet, though it’s in the roadmap.hlcfan
Thanks @mat-hek for the quick reply. Looking forward to the MP4 demuxer!
hlcfan
After converting the file to TS format, it works, thanks!
hlcfan
@mat-hek Do you have an example of how to stream a TS file through HLS? I can’t seem to find one.
mat-hek
I don’t, but once you have H264 and AAC, you should be able to put them into HLS like in this demo
EddTally
Hey, I’m doing something similar to you, did you ever complete this project?
If so are you able to share the code with me/us?
EddTally
I’ve completed the pipeline with the help of @DominikWolek
First take your MP4 file and demux it to acc Audio and H264 Video.
I use ffmpeg command for this, (there might be a ffmpeg elixir wrapper out there to do it safer than this, I feel like calling System.cmd isn’t a nice thing)
For the file name I just take the basename of the original Mp4.
This should split your mp4 into two files, one .aac and it’s corresponding video file .h264
Then in your handle_init function you can create your SkinBin like so:
output_dir is the path you wish to save your HLS files to for streaming them.
Once you have your sink you need to create your source and filters, a lot of this next bit of code can be found here inside the Sink Bin Integration Test on membrane_http_adaptive_stream_plugin’s github.
@audio_video_tracks_sourcesis our sources in this format:But it can be whatever you want as long as it’s in the tuple
{path, codec, type}Once you’ve got all that you can startup your program with
iex -S mixthen start the init
{:ok, pid} = Module.start_linkAnd your program will generate the HLS files to the @output_dir that you specified.
You can test to see if they’re correct by serving them from a simple python server like so:
python3 -m http.server 8000And playing it with ffplay
ffplay http://localhost:8000/FILENAMEwith FILENAME being output_dir/index.m3u8
Feel free to ask any questions or if I’ve left something out!
EddTally
Updated to include -profile:v baseline