Loop Audio File
I have a little Membrane Pipeline with a video, and some audio tracks. I want to add some background music to it. A short track, that just loops over and over, until the video is done.
I've looked at doing something like:
and now I need to send a seek event to that child as far as I understand. However, I can't find any examples of that. How do I send this child an event?
Any tips?
14 Replies
Hi @Aske, events are meant to be sent by other elements through pads, using https://hexdocs.pm/membrane_core/Membrane.Element.Action.html#t:event/0
So you'd need a filter right after the file that would intercept end_of_stream and send the seek event through its input. However, I'm not sure if it works, because concatenated MP3 files are not necessarily a valid MP3 - for example some ID3 tags are only valid at the beginning of file
I h
So the preferred solution would be to remove all the elements that process the MP3 and spawn them again
*I have more stuff after the file here
Ah.. yeah, I see. It would still be an issue for the MAD.Decoder
Can I remove and add named elements in one go? Or how would I go about doing that? It complains over this:
Nope, since the removal is not atomic. You need to wrap the names in tuples like
{:mp3_source_bg, make_ref()}
. Usually it's better to make them a group, like spec = {[child(..), ...], group: :bg_audio}
and then do remove_children: :bg_audio
.Ah, did not know that was possible!
Thanks for the help!
Hmm.. I never got this to work. I keep running into this unlink error. It looks like it's running correctly at least once, but perhaps the last run isn't cleaned up correctly (
playback: :stopped
in the logs below):
I don't even kill the group right now, just add it:
I don't think I really understand what's happening here 😬Are you sure you're removing the converter element?
I tried to comment out the remove_children, to rule out that cleanup being the source of the error. The only time I remove anything is with
{[terminate: :normal], state}
Oh I see. Can you provide the code so I can reproduce?
Yes, will do. Shaving it down to the minimums now.
Attempted again using a Filter as you described, but I still cannot get it to work. This time with raw audio to eliminate the mp3 issue:
https://gist.github.com/Doerge/77bc2a10e53da07a4124a861fb7526bd
On the
which looks like it is being received, because I see other elements (
end_of_stream
event in the Filter on the input pad, I send an event:which looks like it is being received, because I see other elements (
:mixer
) receiving it in the logs:
But it's only received once, so I assume it didn't work out..
I think I'm unfortunately still misunderstanding something conceptually here, but what? I've dug through documentation, and examples, but can't find anything similar to what I want to do here. Any help would be appreciated.Gist
Elixir Membrane Loop
Elixir Membrane Loop. GitHub Gist: instantly share code, notes, and snippets.
You're amazing! This also works for raw audio! Thank you! 🙏
glad to help 😉