Audio streaming server with files in S3 bucket

I am developing a web service in Node Js to be consumed by an app to stream. My audio files are hosted on AWS S3 bucket. So far everything is fine, I can play the songs in the app. But the big problem is in the consumption of data that my users may have when streaming, each file has its size and this will certainly save nothing on the consumption of mobile data of users.

I used request to take the music stored in S3 and then I do .pipe(res) to make the streaming happen in the app. I can't find a solution( or maybe I'm not doing it correctly) that allows me to transcode the file to normalize and reduce the size while streaming, other than with examples with locally stored files.

I found the fluent-ffmpeg and it was perfect, at least in the normalization and reduction, but with this lib the streaming fails and resumes over and over again what can give users ' mobile data cable. Below is an excerpt of the code and an illustrative image of what happens while the song plays:

    res.writeHead(200, {
        'Content-Type': 'audio/mpeg',
        'Content-Length': size - startByte,
        'Transfer-Encoding': 'chuncked',
        'Cache-Control': "no-cache",
        'Connection': 'Keep-Alive'
    });

    ffmpeg(assetUrl)
    //.withDuration(60)
    //.seek(30)
    .format("mp3")
    .audioQuality(5)
    .withNoVideo()
    .audioBitrate(96)
    .audioChannels(2)
    .audioFrequency(44100)
    .audioFilters([
        {
            filter: 'volume',
            options: ['0.4']
        },
        {
            filter: 'silencedetect',
            options: { n: '-50dB', d: 5 }
        }
    ])
    .on('end', function(err) {
        console.log('done!', err)
    })
    .on('error', function(err) {
        console.log('an error: ' + err);
    })
    .stream().pipe(res, { end: true })

insert the description of the image here

Any ideas? Thank you for help;)

Author: C-lio Garcia, 2019-01-15

1 answers

There are other services that can do the conversion, so you don't have to do it in your app.

AWS Elemental MediaConvert: https://aws.amazon.com/mediaconvert /

Amazon Elastic Transcoder: https://aws.amazon.com/elastictranscoder /

 0
Author: Julio Faerman, 2019-01-20 00:03:07