2

I have many ogg & opus files on my server and need to generate json-waveform numeric arrays on an as-needed basis (example below).

recently i discovered the node based waveform-util which uses ffmpeg/ffprobe for rendering a JSON waveform and it works perfectly. i am undecided if having a node process constantly running is the optimum solution to my issue.

since ffmpeg seems to be able to handle anything i can throw at it, i wish to stick with an ffmpeg solution.

i have three questions:

1) is there a php equivalent? i have found a couple that generate PNG images but not one that generates JSON-waveform numeric arrays

2) are there any significant advantages of going with the node-based solution rather than a php based solution (assuming there is a php based solution)?

3) is there a way using CLI ffmpeg/ffprobe to generate a json-waveform ? i saw all the -show_ options (-show_data, -show_streams, -show_frames) but nothing looked like it produced what i am looking for.

the json-waveform needs to be in this format:

[ 0.0002, 0.001, 0.15, 0.14, 0.356 .... ]

thank you all.

edwardsmarkf
  • 1,387
  • 2
  • 16
  • 31
  • http://stackoverflow.com/questions/6807388/call-nodejs-scripts-from-html-pages - micha posted very interesting idea of using node CGI. – edwardsmarkf Mar 04 '15 at 19:41
  • update: node CGI is working perfectly. but i would still be interested in knowing if there is a PHP solution. also, i am still very interested in the CLI question. – edwardsmarkf Mar 04 '15 at 22:23
  • could you find how to generate json-waveform in this format [ 0.0002, 0.001, 0.15, 0.14, 0.356 .... ]?? – ND17 Aug 07 '15 at 09:46
  • hi nd17 - i am afraid this one was beyond me and i gave up. there is probably an easy way to get this information using just ffmpeg but i dont know what that would be. – edwardsmarkf Aug 08 '15 at 17:19

2 Answers2

0

it sounds as if there is a conflict with the way my server is handling cgi. i am using virtualmin and am using the following setting:

PHP script execution mode: CGI wrapper (run as virtual server owner)

after much research, it appears that using pure node.js is more lightweight rather than using a shell executable. i was able to have some success merely by putting a schbang line to call node, but having a node.js script always memory resident is probably the way to go.

edwardsmarkf
  • 1,387
  • 2
  • 16
  • 31
0

For anyone in the future looking to do this with RN:

// convert the file to pcm
await RNFFmpeg.execute(`-y  -i ${filepath}  -acodec pcm_s16le -f s16le -ac 1 -ar 1000 ${pcmPath}`)
// you're reading that right, we're reading the file using base64 only to decode the base64, because RN doesnt let us read raw data
const pcmFile = Buffer.from(await RNFS.readFile(pcmPath, 'base64'), 'base64')
let pcmData = []
// byte conversion pulled off stack overflow
for(var i = 0 ; i < pcmFile.length ; i = i + 2){
  var byteA = pcmFile[i];
  var byteB = pcmFile[i + 1];
  var sign = byteB & (1 << 7);
  var val = (((byteA & 0xFF) | (byteB & 0xFF) << 8)); // convert to 16 bit signed int
  if (sign) { // if negative
    val = 0xFFFF0000 | val;  // fill in most significant bits with 1's
  }
  pcmData.push(val)
}
// pcmData is the resulting waveform array
Dale_Plante
  • 876
  • 1
  • 7
  • 15