[Bounty] SoX / Spectral analysis plugin

shwetha17

Member
May 24, 2018
785
0
16
Bounty: $50

Brief: Create a plugin that will display spectrogram of audio files.

Details: Using SoX and a method of operation similar to the Screenshot and MediaInfo plugins to create and display a spectral analysis (spectogram) of supported audio files (configurable via array). Will execute the sox binary with configurable flags (via settings menu or config.php) and display the output in the ruTorrent UI with option to download to local disk.

Pseudo comand: sox --multi-threaded $inputpath -n spectrogram -t $inputfilename
Example command: sox --multi-threaded "/home/media/Sample/Artist - Title.flac" -n spectrogram -t "Artist - Title.flac"

Notes:
Output images are quiet large at 944 x 613 px. Don't mind is these are scaled or something to fit better on smaller resolution. Two example outputs here and here

Would be a very handy plugin for anyone that transcodes from lossless files on server without having to manually check each file. If anyone else would find this useful please feel free to contribute.
 

jith45

Member
May 25, 2018
960
0
16
OK, i will see.
SOX has a lot of options for spectrogram building (see http://sox.sourceforge.net/sox.html) I dont't know - what is mean a most of its. As result, two questions
1) Which of its must be realized?
2) Which options are 'constant' (e.q. may be setted in the Settings dialog) and which - 'dynamic' (e.q. must be corrected every time, when user choice 'Build spectrogram' menu item)?
 

shwetha17

Member
May 24, 2018
785
0
16
A sample command I would use now would be:
sox --multi-threaded "/home/media/Artist/Album/Track name.flac" -n spectrogram -t "Track name.flac"
The bold parts being the constant, only variables are the file path and the file name at the end.

Any extra switches would be past after the end filename such as "-l" and "-m" for making the spectrogram monochrome.
 

shwetha17

Member
May 24, 2018
785
0
16
Just to add, avoid using the -x -y SoX flags for scaling, the time penelties are far to great:

Code:
kolor@tyrant:/tmp$ time sox --multi-threaded Sample\ -\ Test\ 4.flac -n spectrogram -t Sample\ -\ Test\ 4.flac -o sample.png

real 0m3.764s
user 0m28.450s
sys 0m0.076s
kolor@tyrant:/tmp$ time sox --multi-threaded Sample\ -\ Test\ 4.flac -n spectrogram -t Sample\ -\ Test\ 4.flac -o sample1.png -x 600 -y 200 -z 100

real 0m16.572s
user 1m49.023s
sys 0m0.608s
 

shwetha17

Member
May 24, 2018
785
0
16
Spot on!
If I could ask for 1 final tweak would it be possible to add the -t flag with the file name as a parameter?
This would then put the file name of the file being analysed into the final image
fixed it
 

jith45

Member
May 25, 2018
960
0
16
Flag -t is used for definition of the file format. If a processed file has a valid extension (e.q. corresponding to the file type) then you don't need this flag. If it hasn't - you must specify *file format* after -t, not a file name.
Tell me please, when you finish with checking - i will move source to the svn repository.
 

shwetha17

Member
May 24, 2018
785
0
16
Correct it would be under most circumstances but because we are applying the spectrogram effect and it is passed after that it sets the image title:

Quote

if($filename!=='')
{
$mediafile = basename($filename);
$commands = array();
$name = '"${dir}"/frame.png';
$commands[] = getExternal("sox").
" ".escapeshellarg($filename)." ".
implode( " ", array_map( "escapeshellarg", explode(" ",$arguments) ) ).
' -t "'. $mediafile. '" -o '.
$name;
$commands[] = '{';
$commands[] = '>-=*=-';
$commands[] = '}';
$commands[] = 'chmod a+r "${dir}"/frame.png';
}


ZQIBH.png