Comments (22)
Sounds like this is because now the files are converted to wav in memory. SHA: 7122e11
from dejavu.
What needs to happen is that Dejavu should convert and fingerprint piece by piece. The fingerprinting process for a single audio track is actually embarrassingly parallel, so there's no need to tax the RAM like we are doing now. You just have to be careful that you start fingerprinting each chunk of the audio such that it overlaps at least
DEFAULT_WINDOW_SIZE * DEFAULT_OVERLAP_RATIO
so that the windowing process doesn't miss fingerprints on window borders.
If this is something you care about, I would gladly accept a pull request fixing it.
from dejavu.
The piece by piece fingerprinting is slightly harder to do due to supporting multiple channels. The implementation for this would require to interleave fingerprinting per channel.
But from the tests I ran while trying to gain speedups there seems to be no notable difference between stereo fingerprinting and mono fingerprinting and their accuracy. Admittedly I've not tested this with microphone input.
As for the fingerprinting in chunks, what is the required size of each chunk?
from dejavu.
That's just the DEFAULT_WINDOW_SIZE * DEFAULT_OVERLAP_RATIO
that I mentioned. This is the amount of overlapping required to keep the same fingerprinting behaviour.
I'd welcome PRs fixing this.
from dejavu.
Sorry for the terrible formating but here is some code that will split up an audio file for you into peices that dejavu can handel. Would be much better to modify dejavu but this should hopefully help.
def write_audio_file(file_path,audio_array):
'''
Need to do this just for testing
want to be able to create some bizzarre test files for croma print
'''
pipe = sp.Popen([ FFMPEG_BIN,
'-y', # (optional) means overwrite the output file if it already exists.
'-r', "44100", # the input will have 44100 Hz
'-ac','2', # the input will have 2 channels (stereo)
"-f", 's16le', # means 16bit input
'-i', '-', # means that the input will arrive from the pipe
'-vn', # means "don't expect any video input"
'-acodec', "aac","-strict" ,"-2",#"ac3_fixed", # output audio codec
file_path],
stdin=sp.PIPE,stdout=sp.PIPE, stderr=sys.stdin)
pipe.stdin.write(audio_array)
def get_audio_array(pipe,minutes):
number_of_audio_frames = 88200_30_minutes
bytes_in_frame = 4
bytes_to_read = number_of_audio_frames*bytes_in_frame
raw_audio = pipe.stdout.read(bytes_to_read)
raw_audio_array = numpy.fromstring(raw_audio, dtype="int16")
if len(raw_audio_array) < 1:
return None,None,'reached end of file'
audio_array = raw_audio_array.reshape((len(raw_audio_array)/2,2))
return audio_array,raw_audio,None
def chunk_file(file_path,chunk_folder_path,max_chunk_size,file_suffix = ''):
pipe = read_audio_data(file_path)
extention = '.m4a' #probably a bad choice but first I go to work
i = 0
while True:
i += 1
audio_data,raw_audio_data,error = get_audio_array(pipe,5)
if error is not None:
print error
return
chunk_file_path = chunk_folder_path + '/chunk_' + str(i)+ '_' + file_suffix + extention
print 'write file ' + chunk_file_path
write_audio_file(chunk_file_path,raw_audio_data)
from dejavu.
Oh it is the chunck file function you need to call with with max_chun_size being an int number of minutes.
from dejavu.
Sorry, I'm really having trouble following your thoughts/code. Code sections will help, but I think an end-to-end example would be better.
Can you format this all in a branch or PR?
from dejavu.
'''
This will audio files that are too long into sections.
There are probably better libs to do this.
'''
FFMPEG_BIN = 'ffmpeg'
import subprocess as sp
import numpy
import sys
def read_audio_data(file_path,offset='00:00:00'):
#define TRUE 0
command = [ FFMPEG_BIN,
'-ss',offset,
'-i', file_path,
'-f', 's16le',
'-acodec', 'pcm_s16le',
'-ar', '44100', # ouput will have 44100 Hz
'-ac', '2', # stereo (set to '1' for mono)
'-']
pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)
return pipe
def write_audio_file(file_path,audio_array):
'''
Need to do this just for testing
want to be able to create some bizzarre test files for croma print
'''
pipe = sp.Popen([ FFMPEG_BIN,
'-y', # (optional) means overwrite the output file if it already exists.
#"-acodec", "pcm_s16le", # means raw 16bit input
'-r', "44100", # the input will have 44100 Hz
'-ac','2', # the input will have 2 channels (stereo)
"-f", 's16le', # means 16bit input
'-i', '-', # means that the input will arrive from the pipe
'-vn', # means "don't expect any video input"
'-acodec', "aac","-strict" ,"-2",#"ac3_fixed", # output audio codec
#'-acodec', "adpcm_sw",#"ac3_fixed", # output audio codec
#'-b',"mp3", # output bitrate (=quality). Here, 3000kb/second
file_path],
stdin=sp.PIPE,stdout=sp.PIPE, stderr=sys.stdin)
pipe.stdin.write(audio_array)
def get_audio_array(pipe,minutes):
number_of_audio_frames = 88200*30*minutes
bytes_in_frame = 4
bytes_to_read = number_of_audio_frames*bytes_in_frame
raw_audio = pipe.stdout.read(bytes_to_read)
raw_audio_array = numpy.fromstring(raw_audio, dtype="int16")
if len(raw_audio_array) < 1:
return None,None,'reached end of file'
audio_array = raw_audio_array.reshape((len(raw_audio_array)/2,2))
return audio_array,raw_audio,None
def chunk_file(file_path,chunk_folder_path,max_chunk_size,file_suffix = '',extention='.m4a'):
pipe = read_audio_data(file_path)
i = 0
while True:
i += 1
audio_data,raw_audio_data,error = get_audio_array(pipe,5)
if error is not None:
print error
return
chunk_file_path = chunk_folder_path + '/chunk_' + str(i)+ '_' + file_suffix + extention
print 'write file ' + chunk_file_path
write_audio_file(chunk_file_path,raw_audio_data)
def chunk_folder(folder_path,chunked_folder_path,max_chunk_size):
'''
so basically go through all files in folder
turn each file into a bunch of files of length max_chunk_size(given in minutes)
'''
from os import listdir
from os.path import isfile, join
file_names = [ file_name for file_name in listdir(folder_path) if isfile(join(folder_path,file_name)) ]
for file_name in file_names:
file_path = folder_path + '/' +file_name
chunk_file(file_path,chunked_folder_path,max_chunk_size,file_suffix=file_name)
from dejavu.
basically call
chunk_folder(path_to_long_audio_files,path_to_output_chunked_files,minutes_for_each_chunk_like_5)
Now you can use dejavu on long files. But would be better if dejavu did this internally.
from dejavu.
The problem even worse when it tries to fingerprint more files parallel.
I've hardcoded 1 into the script to avoid out of memory:
pool = multiprocessing.Pool(1)
From the command line it isn't possible to pass the max parallel processes as a parameter and it will be defaulted to 4.
djv.fingerprint_directory(directory, ["." + extension], 4)
The program doing a very good job besides this! It just doesn't really can handle long audio files.
from dejavu.
created a pull request that.
if you find some other improvement on the code go for it
#75
from dejavu.
Hi, guys.
Can someone guide me how to calculate the starting offset of the chunks?
it's obvious that I missed this when I created the PRs,
pls, help
from dejavu.
HI guys
Did you guys have any luck in getting this running in regards to low memory setups like Raspberry Pi's...?
from dejavu.
I can run it on RPi 2 no problem. I didn't try timing it but it seems to run pretty fast.
from dejavu.
@arunganesan what commit are you using?
from dejavu.
Hm, Im not sure. I just cloned the latest commit from like a few days ago. I am only fingerprinting short sounds. At max 30 seconds.
from dejavu.
You can check my repository
https://github.com/IskrenStanislavov/dejavu/tree/split-fingerprinting
it is tested to work with 4 hours audios
the only missing thing is the offset_seconds.detection from the original audio
from dejavu.
@worldveil
Hello, Will.
Is this the direction I should follow to calculate the proper offset_seconds?
3 min * 60 sec * 44100 samples per sec * 2 channels = 15,876,000 samples
from dejavu.
I would like to complete this PullRequest, but I definetely need your help...
Two things.
- I want to know how to properly calculate the offset in value manner, not the matrix version. Cause I don't have the experience with the tools used in fingerprinting.
- By splitting into files do I need to set up the time limits of files as described in:
#18 (comment)
and how to calculate in seconds.
Help would be highly appreciated.
from dejavu.
Does dejavu can fingerprint 2 hours long mp3 correctly and search yet ? what did i miss ?
from dejavu.
Any news on fixing this by merging split-fingerprinting? dejavu is almost unusable on low memory machines - even the example mp3 files give out of memory errors when trying to fingerprint on a 512MB machine :( (and relying on swap is a disaster on this machine - its only storage is a memory card). Thanks
Edit: got something working by fingerprinting my songs on a machine with lots more memory, and then simply copying the MySQL innodb database files over to the small machine. Seems to be running the recognition fine :)
from dejavu.
I had this issue in 2 ubuntu droplets. both had 512mb memory. then I extend one of them to 2gb and problem seams had disappeared!
from dejavu.
Related Issues (20)
- A directory of potentially duplicate audio files?
- it works well with python3.6 ~
- Not working for recordings
- Some errors when I use python3.7
- multiple concurrency
- Fingerprinting Audio With Differing Sample Rates HOT 1
- Jscght
- figerprinting file HOT 1
- Any way to generate the result image of the plots? HOT 1
- Does this package supports Python 3 HOT 4
- does this project work well on recognizing human speak? HOT 5
- Problem running the sample project HOT 1
- erors using fingerprint_file HOT 1
- Audio file
- Recognize TV shows using an HLS playlist HOT 6
- psycopg2.OperationalError
- Implementing Dejavu System with Individual Fingerprint Tables for Audio Files
- 代码可读性太差了,为了炫技而炫技,屎一样
- Alternative implementations HOT 2
- is this package has support for python3 ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dejavu.