pydub
pydub copied to clipboard
Support for mogg files
Mogg files are used to contain different tracks of a song. It could be very useful to be able to split these files in several ogg files.
It seems that a mogg file is essentially a container format with multiple ogg streams.
Do you have an example mogg file?
I suspect with an extra parameter to ffmpeg it'll be possible to extract those streams individually.
Hi @jiaaro Here is an example of .mogg file I uploaded: https://dl.dropboxusercontent.com/u/4703391/Avenged%20Sevenfold%20-%20Afterlife.mogg
@ddahan sorry for the delay - I don't think that is a valid mogg file. I found this reddit thread linking to mogg files extracted from rock band and I was able to successfully open "A Hard Day's Night" (10 total audio channels) like so:
>>> from pydub import AudioSegment
>>> sound = AudioSegment.from_file("/Users/jiaaro/Downloads/A Hard Day's Night.mogg")
>>> print(sound.channels)
10
Thanks for your answer. It seems you can load a mogg file indeed. But how would you extract some of the tracks to export them in a new file? For example, if I want to create a guitar backing-track (ie. removing guitar tracks from the original mogg), and export the file to mp3, how can I do this with pydub? Thanks.
The latest release of pydub (v0.19.0 - available on pypi starting today :) ) supports using AudioSegment.split_to_mono() on audio segments with any number of channels. That's probably your best bet (though you'll need to recombine any stere pairs manually)
Unfortunately, this returns a list of two AudioSegments. If there are 10 channels, I suppose there are at least 5 differents tracks in the song..
It's important that you're on the very latest version of pydub (v0.19)
you can check your version with pip freeze, and you an upgrade with pip install -U pydub
Excellent :) Thanks.
One last question: currently, the overlay() method seems to accept one AudioSegment only.
That means if my source has 10 channels, and my output need to have 8 channels, I need to loop on the overlay method to merge the chanels 1 by 1. (for example if I want to keep channel 1->8, I would use overlay to merge: 1 with 2, then 3 with [1+2], then 4 with [1+2+3], etc.)
Is there a cleaner way?
Thanks again.
I think that's what you'll have to do given the current AudioSegment methods. I could imagine a new class (StereoMixer maybe?) which allows you to set what audio segments start and end where and gain and panning, and at the end do a single pass to combine them all, but such a thing doesn't exist yet.
At a high level, such a thing would just keep a reference to all the audio segments in question and at the time of the "mix down" it would:
- Make sure all the audio segments have the same bit depth and frame rate
- Call
sound.get_array_of_samples()on each one and sum all the signals - one sample at a time - Generate a new output AudioSegment using the combined values
That would be great 👍
For anyone finding this thread in the future, I did prototype a Mixer class which may be a good starting point. Perhaps that's something to polish up a bit more and add to pydub?
sorry to revive an old issue, is this already implemented?
can someone provide a working example of extracting mogg to wav?
thanks a lot in advance.