Finding the end of a looped playlist in a music file

Programming related discussions related to game research
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Finding the end of a looped playlist in a music file

Post by aluigi »

Often on youtube there are videos of 4, 8, 10, or even more hours containing a certain amount of tracks in loop.
For example the original playlist is only 40 minutes but the video is 4 hour, so if you want to keep a local collection of these audio files you are going to waste lot of space for nothing and maybe you don't like to listen the same playlist again and again.

I needed a basic and simple solution without big software, anything bloat to compile, complicated API, and hours spent reading and searching a solution.

There is this simple tool from acousticid that creates audio fingerprints of any input audio file, it splits it in small chunks and spit out a 32bit number for each chunk.
https://github.com/acoustid/chromaprint
The tool needs ffmpeg in the system, it's open source, multiplatform, and has compiled releases for Windows too.

So I forced the tool to fingerprint the whole file (by default it only checks the first few seconds), dump the fingerprints in an array, and scans the array searching if the fingerprints at the beginning of the file are found later.

The tool is launched as: fpcalc.exe -length 0 -raw -json FILE

It's a super simple and basic solution, but it works well since I only got few false positives in over 200 files I tested.

I made a simple tool for doing the job and returning the number of seconds where the repeated fingerprint is found, it can even launch ffmpeg for automatically cutting the file (add -DCUTIT to gcc when compiling).

Hope it's useful.