axeldelafosse/stemgen

Extract audio files from STEM file?

lucellent opened this issue · 6 comments

I downloaded the 65 free stems from NI that they provide, and they're 65 .mp4 files, each containing the stems

Is there a way to extract the stems from those containers? StemGen does the opposite

If you are in macos you could also use this: https://github.com/faroit/SplitStems

Maybe we could integrate that functionality also here?

Thanks for the suggestions!
Sadly the Audacity method doesn't work for me, I installed FFmpeg for Audacity but it doesn't find that specific library
and I'm on Windows

The only "workaround" for me is to import each song in Audition, then extract channels to mono, then combine the L and R channels for each stem... which takes just a very long time per song

If you get a ffmpeg command line binary (either for windows directly or WSL linux-for-windows), you can use a command line like the following :

for name in 0 1 2 3 4; do ffmpeg -i example.stem.m4a -map 0:${name} -acodec copy channel${name}.m4a ; done

This runs ffmpeg 5 times, extracting one channel at a time, doing a stream copy with no decode step.

To do this in one command, one can use filter_complex :

ffmpeg -i example.stem.m4a -filter_complex 'channelsplit=channel_layout=5.0[C0][C1][C2][C3][C4]' -map '[C0]' -ac 2 -codec alac channel0.m4a -map '[C1]' -ac 2 -codec alac channel1.m4a -map '[C2]' -ac 2 -codec alac channel2.m4a -map '[C3]' -ac 2 -codec alac channel3.m4a -map '[C4]' -ac 2 -codec alac channel4.m4a # for ALAC input to ALAC lossless output

or

ffmpeg -i example.stem.m4a -filter_complex 'channelsplit=channel_layout=5.0[C0][C1][C2][C3][C4]' -map '[C0]' -ac 2 channel0.flac -map '[C1]' -ac 2 channel1.flac -map '[C2]' -ac 2 channel2.flac -map '[C3]' -ac 2 channel3.flac -map '[C4]' -ac 2 channel4.flac # for ALAC input to FLAC lossless output

(I've used .flac in the second example instead of .m4a because it's lossless to lossless with ALAC input, and FLACs are more supported in external programs than ALAC files. Replace .flac with .m4a and add "-codec AAC" AAC output. The above commands are totally lossless if done with ALAC lossless stems. Unfortunately if done with lossy stem input, this will result in a decode (and re-encode) step, as one cannot combine filter_complex with stream copying.)

For example :

ffmpeg -i example.stem.m4a -filter_complex 'channelsplit=channel_layout=5.0[C0][C1][C2][C3][C4]' -map '[C0]' -ac 2 -codec aac channel0.m4a -map '[C1]' -ac 2 -codec aac channel1.m4a -map '[C2]' -ac 2 -codec aac channel2.m4a -map '[C3]' -ac 2 -codec aac channel3.m4a -map '[C4]' -ac 2 -codec aac channel4.m4a # WARNING! If using AAC input, this does a lossy to lossy recode

These commands appear to produce 5 different stereo files, as expected, though in fairness I have not verified that they are identical to each of the stereo input channels from the Stems. Based on my understanding of filter_complex and -ac 2, they should be.

I wrote Stemsep for this specific use case: https://github.com/axeldelafosse/stemgen/blob/master/stemsep.py

It's using a fork of Stempeg (included in the repo too: https://github.com/axeldelafosse/stemgen/tree/master/stempeg). But as @awesomer pointed out, you can use FFmpeg directly to do this.

If that's a common use case I'll probably add some docs!