3

So I'm building a program that requires that I take a video and convert it to audio. I'm currently streaming the audio directly to the browser via node.js, but I've run into a major problem: I don't know how to find out how many bytes my audio is. As a result, the browser keeps throwing net::ERR_CONTENT_LENGTH_MISMATCH when I don't get the right content-length. I've tried several strategies, all of which have failed:

  • Computing the size manually (Seconds * bitrate(kbps) * (1024 / 8)).
    This produces an approximate answer, since I only know the length down to the nearest couple of seconds. Even though I'm relatively close, I still end up getting the same MISMATCH error.

  • Piping the Stream to a buffer, getting the buffer's length, and piping the buffer to the browser
    This works, but it can take 15-20 seconds to load each song. It's incredibly slow and puts a considerably larger load on the server

Taconut
  • 891
  • 3
  • 10
  • 27
  • Are you sure the browser requires a `Content-Length`? Node uses chunked encoding by default as long as you don't manually set `Content-Length` in the response headers. That allows you to send a response if you don't know the length ahead of time. – mscdex Sep 15 '14 at 22:12
  • Yeah well I'd really like to be able to seek through the audio file in question, not to mention show the user how much they have left. I don't suppose there's a way to do that with a dynamic Content-Length? I'm using the default HTML5 Audio API. – Taconut Sep 16 '14 at 01:43
  • Have you found any solution for this @Taconut ? I'm having the same problem – Jakemmarsh Oct 01 '14 at 01:49
  • Well sort of... I passed the length in seconds, which gave me limited functionality. I was able to override the duration like this: `AUDIOOBJECT.__defineGetter__('duration', function() { return DURATION; });` – Taconut Oct 03 '14 at 20:06

0 Answers0