Skip to content

Conversation

@blackhold
Copy link
Contributor

Description

Allow convert tracks to STEMS using htdemucs and MP4Box + install dependencies on debian

Related to: Closes #15881

Changes

  • Asks user to install htdemucs and MP4Box if not installed, installs the dependencies
  • Add the option to convert track to stems. Right click on a track > Analyze > Convert to stems
  • Implements GUI and workflow for stem conversion using htdemucs and MP4Box
  • Opens a window to manage conversions (in development)
  • Adds a button to open stems conversions window below stems hamburger menu (in development)

@github-actions github-actions bot added ui build developer experience Issues, bugs and PRs related to the development process, development environment & developer docs labels Jan 22, 2026
Copy link
Member

@JoergAtGithub JoergAtGithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this PR does not take into account the Change Requests from #15881, which were to use mixxxdj/demucs and onnxruntime.

Comment on lines 66 to 67
python3-full
python3-venv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing Python is an unwanted dependency! Please implement your code in C++ following the Mixxx coding guidelines!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtualenv is needed to install demucs, I install it using pip. For python3-full I give you reason that is not needed, but python3-venv it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use our own https://github.com/mixxxdj/demucs model, export it to ONNX format and run it in onnxruntime. Python as runtime dependency is not acceptable in any flavor!

@daschuer
Copy link
Member

Thank you for all the work. I hope I will find time for testing soon.

While I agree with @JoergAtGithub that this is not the final version that can be deployed to other users it contains nice GUI work that is reusable. Mabe we can move the heavy dependencies out of this PR so that it is optional for the users to install it or not?

We will see, let's work on this.

@daschuer
Copy link
Member

The git history is not yet in a good shape. But it can be fixed by rebasing.

Here the first task:

d563880 is a leftover from you first PR ans should be removed.

There are to options: Rebase interactive. Git will open the default editor, likely vim (a usability challenge, do you know vim ... can be changed)

git rebase upstream/2.6 -i 
 in vim, comment out the unwanted commit with # and save.

or

git rebase onto=d563880b4b017125e51ace4437b489ae6244874e~1 d563880b4b017125e51ace4437b489ae6244874e

this works like `git rebase onto=new_base old_base
"~1" means the commit before

Than

git push -f 

@daschuer
Copy link
Member

602a365

Now also contains the unrelated changes regarding the Ubuntu font.
Can we fix an merge that topic fist?

@blackhold
Copy link
Contributor Author

602a365

Now also contains the unrelated changes regarding the Ubuntu font. Can we fix an merge that topic fist?

This commit shoud be inside stemgen branch. Is related to this PR.

@blackhold
Copy link
Contributor Author

@JoergAtGithub @acolombier I'm looking about ONNX integration.

I see that the solution is to install the libonnxruntime-dev library, clone mixxx/demucs repo and execute script scripts/convert-pth-to-onnx to generate the htdemucs.onnx file. Does it is correct?

Then, my question is, to execute this script you need python installed. Also to meet python script dependencies you have to install them (better in virtualenv than in system) and also we return to same point.

I cloned the project and tried to execute convert-pth-to-onnx.py with no success (I used requirements.txt of the project). Which is the right torch version to could execute the script?

Searching I see this article

Do you have htdemucs.onnx file? Do you plan to have it uploaded somewhere to avoid the installer has to execute the script? I think it would be easier.

I understand that the process will be:

1. User selects audio track
2. Mixxx → ONNX Runtime → ONNX Model
   ↓
   Generates 4 separated stems (raw audio)
   ↓
3. ffmpeg → Encodes to desired format (MP3, FLAC, WAV, etc.)
4. MP4Box → Creates STEM container (M4A with metadata)
5. Saves stems to output folder

@acolombier
Copy link
Member

Does it is correct?

No need to do that. The model is available here, and no change was brought to it since AFAIK (only devex improvement, testing and benchmarking)

Do you have htdemucs.onnx file?

Yes, it is in the release linked above - htdemucs.onnx

I understand that the process will be:

It's correct up to 3) - we will be using taglib to generate the stem. This feature is pretty much ready here, but waiting for input from the upstream.

So technically, it will be

...
3) ffmpeg -> bundle all streams into a MP4
4) populate the the MP4 file with a valid stem metadata

…eldelafosse/stemgen + install stemgen in debian
…ndency)

- Replace Python script (stems_create_container.py) with native C++ implementation
- Implement createStemManifest() to generate STEM metadata JSON
- Implement findMP4Box() to locate MP4Box executable in system
- Implement addStemMetadata() to add STEM metadata atom using MP4Box
- Create multi-track M4A with ffmpeg directly (mixdown + 4 stems)
- Remove dependency on Python virtual environment for STEM container creation
…tory

- Check if fonts-ubuntu is available
- Ask user to enable non-free repository if needed
- Install fonts-ubuntu conditionally
- Fix syntax errors (2>%1 → 2>/dev/null)

Fixes mixxxdj#15816
- Ask user about stem conversion support
- Setup Python virtual environment
- Install demucs
- Compile and install GPAC/MP4Box

Related to mixxxdj#15307
@blackhold
Copy link
Contributor Author

blackhold commented Jan 24, 2026

Well guys, it made me sweat but I finally managed to get htdemucs working through ONNX. I reviewed the part about making it compatible with all operating systems, I've already seen how, but I got stuck because when doing it I had to touch some configuration and another library (libtag or something) broke, but for now this option has allowed me to move forward to test the conversion and complete the entire process.

Now that this is working, I'll dive into implementing conversion options. There's a Python library called ONNX that allows me to interact with the model (and I can test it without compiling each time). Things I want to try are: offering the option to choose between different available models (for example, there's an experimental one that allows separating into 6 stems), as well as audio compression options (or not). I had it partially set up, but due to the other library issue I had to revert to HEAD and go step by step.

One question: do the stem files always have to be .stem.m4a?

An other: what shall I do with temp created files? maintain them or delete?

Thanks and good night!

Hard work, but getting fun! :)

@JoergAtGithub
Copy link
Member

This fits much better now! Thank you!
What needs to be changed is the direct use of libsndfile to read the audio file. Mixxx has already an own infrastructure to read audio files, which can be found in the ./src/sources . These soundsources should also be used here.

Regarding options:

  • We took the deliberated design decision for 4 stem channels. Which proved to be right, as all other DJ software switched to 4 stem design in the meantime. Also the STEM file format does not allow a different number of stem channels. Furthermore it became the standard for DJ hardware, which has either controls for all 4 stem channels or simplified to 2 stems (Vocals + Other).
  • The STEM file format supports only two options for audio encoding (lossless ALAC, or AAC 256 kbps VBR) choosing between them would be a very useful option.
  • Training/Tweaking of models should be done outside of Mixxx. The differences between the models are so small that you need a scientific benchmark for evaluation anyway. (We described how to do this in: https://mixxx.org/news/2025-10-27-gsoc2025-demucs-to-onnx-dhunstack/ )
  • But what is possible, and already discussed, is to offer the user to select alternative models in ONNX format. If you for example provide an ONNX file of mdx-net model, we could offer it the end user for download. But as these models are huge, we will not ship more than one model with Mixxx itself.

@JoergAtGithub
Copy link
Member

The CI builds fail. It appears that the stem separation is not properly disabled when onnxruntime is not installed.

@Eve00000
Copy link
Contributor

Hard work, but getting fun! :)

Nice!.
I suppose you experience the challenge of gathering new knowledge and achieving a goal that you previously considered nearly impossible.
Are you already on the Mixxx-Zulip?

@blackhold
Copy link
Contributor Author

The CI builds fail. It appears that the stem separation is not properly disabled when onnxruntime is not installed.

Done!

@blackhold
Copy link
Contributor Author

What needs to be changed is the direct use of libsndfile to read the audio file. Mixxx has already an own infrastructure to read audio files, which can be found in the ./src/sources . These soundsources should also be used here.

Done!

@github-actions github-actions bot added the skins label Jan 24, 2026
@JoergAtGithub
Copy link
Member

Please fix the CI build fails.

@JoergAtGithub
Copy link
Member

CI is still failing for all platforms

@blackhold
Copy link
Contributor Author

I need help with this 5817757 I'm not able to get compiling work when libonnxruntime is not installed. I have revised all STEM_CONVERSION protecting the functions, but I don't know what is happening.

Thanks you much!

@blackhold
Copy link
Contributor Author

Let's try now! crossing fingers...

@blackhold
Copy link
Contributor Author

This fixes the strange behaviour that I found before last commits. Now I'm going to do a commit for code style fits using pre-commit.

@JoergAtGithub
Copy link
Member

The pre-commit check is failing. The best way to fix pre-commit issues is to install pre-commit locally on your system, as described here: https://github.com/mixxxdj/mixxx/wiki/Using-Git#set-up-automatic-code-checking
Than it will fix these issues automatically before every commit.
Alternatively, you can download the pre-commit.patch file from the artifacts of this PR
grafik
unzip it, and apply it using:
git apply pre-commit.patch

@blackhold
Copy link
Contributor Author

Yes, I'm using pre-commit locally, it passes but don't change the files. I'll try patch method.

@blackhold
Copy link
Contributor Author

Done:

1870 git apply /home/laura/Baixades/pre-commit.patch
1871 git status
1872 git add .
1873 git commit -a
1874 git push

@blackhold
Copy link
Contributor Author

blackhold commented Jan 27, 2026

In work's computer I did the same again right now (here I don't have pre-commit installed):

laura@triptofan:~/dev/mixxx$ git apply /home/laura/Baixades/pre-commit.patch
laura@triptofan:~/dev/mixxx$ git status
En la branca stemgen
La vostra branca està al dia amb «origin/stemgen».

Canvis no «staged» per a cometre:
  (useu «git add <fitxer>...» per a actualitzar què es cometrà)
  (useu «git restore <fitxer>...» per a descartar canvis en el directori de treball)
	modificat:        src/stems/stemconverter.cpp

no hi ha canvis afegits a cometre (useu «git add» o «git commit -a»)
laura@triptofan:~/dev/mixxx$ git add .
laura@triptofan:~/dev/mixxx$ git commit -a
[stemgen e459caba59] apply patch
 1 file changed, 4 insertions(+), 2 deletions(-)
laura@triptofan:~/dev/mixxx$ git push
S'estan enumerant els objectes: 9, fet.
S'estan comptant els objectes: 100% (9/9), fet.
Compressió de diferències usant fins a 8 fils
S'estan comprimint els objectes: 100% (5/5), fet.
S'estan escrivint els objectes: 100% (5/5), 434 bytes | 434.00 KiB/s, fet.
Total 5 (4 diferències), reusats 0 (0 diferències), paquets reusats 0
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:blackhold/mixxx.git
   7e20f50068..e459caba59  stemgen -> stemgen
laura@triptofan:~/dev/mixxx$ 

@blackhold
Copy link
Contributor Author

Hurrahhh!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build developer experience Issues, bugs and PRs related to the development process, development environment & developer docs skins ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants