Giter Site home page Giter Site logo

Comments (8)

faroit avatar faroit commented on June 12, 2024

thanks for your contributions. I don't really see a difference between the arguments you use and the one used in write.py. Here is an example what is actually called by stempeg:

ffmpeg -y -f s16le -acodec pcm_s16le -ar 44100 -ac 2  -i mix.wav -i vocals.wav -i drums.wav -i bass.wav -i other.wav -map 0 -map 1 -map 2 -map 3 -map 4 -vn -acodec aac -ar 44100 -strict -2 -loglevel error -ab 256000 stems.mp4

maybe you can point me to the relevant changes one would need to make to improve the write functions?

from stempeg.

shoegazerstella avatar shoegazerstella commented on June 12, 2024

The difference should be in the codec.
I'm trying this example but then there must be something wrong in the way I use stempeg, but I can't understand what:

y, sr = librosa.load('STEMS/mix.wav')

# CREATE STEMS
which_stem = 1

if which_stem == 1:
    
    # stems x samples x channels
    y_0 = y.reshape((-1, 1))
    y_1 = np.zeros((y.shape[0], 1))

else:
    # stems x channel x samples
    y_0 = y.reshape((1, -1))
    y_1 = np.zeros((1, y.shape[0]))

# CREATE TENSOR
S = np.array([y_0, y_1])

# WRITE STEMS
output_wav = 'STEMS/stem_OUT.mp4'
stempeg.write_stems(S, output_wav, rate=sr)

For some reason, using stems x samples x channels, the generated .mp4 file runs twice the speed it should be, but the single .wav files are correct.
The stems x channel x samples, which should be the format required by stempeg.write, results in an error, as the vector has wrong size.

Error opening '/var/folders/zk/xlbb09bs2j3_wrxkj0fwbhvc0000gn/T/tmp2z3t3wiv.wav': Format not recognised.

Do you see any error in what I am doing?
Thanks a lot!

from stempeg.

faroit avatar faroit commented on June 12, 2024

The difference should be in the codec.

you mean the output codec (acodec)? I also check if libfdk_aac is available and use it. So that doesn't look to be different.

stempeg/stempeg/write.py

Lines 79 to 84 in ebbaec8

if avail is not None:
if 'libfdk_aac' in avail:
codec = 'libfdk_aac'
else:
codec = 'aac'
warnings.warn("For better quality, please install libfdc_aac")

For some reason, using stems x samples x channels, the generated .mp4 file runs twice the speed it should be, but the single .wav files are correct.
Do you see any error in what I am doing?

Are you writing mono files? The STEMS format is stereo only, that is why its hardcoded here. I might need to add a check for this to warn users...

from stempeg.

shoegazerstella avatar shoegazerstella commented on June 12, 2024

Yes in this case is mono.
I understand, thanks a lot for the clarification.

from stempeg.

shoegazerstella avatar shoegazerstella commented on June 12, 2024

Hi, sorry if I am reopening the issue.

I am saving the audio setting 2 channels as:

def save_stereo(filename):
    sound = AudioSegment.from_wav(filename)
    sound = sound.set_channels(2)
    sound.export(filename, format="wav", bitrate="256k", parameters=["-ac", "2"])
    return

Then I am collecting the stems and creating S but the error still pops up.
I am making sure nothing goes wrong in the numpy array when saving and when I listen back to it. It sounds okay.

mix: (2, 13340160) 
drums: (2, 13340160) 
bass: (2, 13340160) 
accompaniment: (2, 13340160) 
vocals: (2, 13340160)

S.shape: (5, 2, 13340160)
stempeg.write_stems(S, output_mp4, rate=sr_mix)

Error opening '/var/folders/zk/xlbb09bs2j3_wrxkj0fwbhvc0000gn/T/tmpwqt3zrer.wav': Format not recognised.

I also have these warnings. Could the error above be related to those?

/usr/local/lib/python3.7/site-packages/stempeg/write.py:84: UserWarning: For better quality, please install libfdc_aac
  warnings.warn("For better quality, please install libfdc_aac")
/usr/local/lib/python3.7/site-packages/stempeg/write.py:96: UserWarning: Number of samples does not divide by 1024, be aware that the AAC encoder add silence to the input signal
  "Number of samples does not divide by 1024, be aware that "

from stempeg.

shoegazerstella avatar shoegazerstella commented on June 12, 2024

[UPDATE]
Correct me if I am wrong, could It be related to bastibe/python-soundfile#203 ?
So stems x samples x channels should be the right format.

from stempeg.

faroit avatar faroit commented on June 12, 2024

has this issue been addressed?

from stempeg.

shoegazerstella avatar shoegazerstella commented on June 12, 2024

Sorry, I solved using the stems x samples x channels ordering.
Closing now.

from stempeg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.