Audio streaming server with files in S3 Bucket

Asked

Viewed 108 times

0

I’m developing a web service on Node Js to be consumed by a streaming app. My audio files are hosted on AWS S3 Bucket. So far so good, I can play the songs in the app. But the big problem is the consumption of data that my users may have when streaming, each file has its own size and this will surely save nothing on users' mobile data consumption.

I used the request to pick up the music stored in S3 and then do .pipe(res) for streaming in the app. I can’t find a solution (or maybe I’m not doing it correctly) that will allow me to transcode in the file to normalize and reduce the size while streaming, other than with examples of locally stored files.

I found the fluent-ffmpeg And it was perfect, at least in normalization and reduction, but with that lib streaming fails and starts over and over again what can ruin users' mobile data. Below is an excerpt of the code and an illustrative image of what happens while the music 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 })

inserir a descrição da imagem aqui

Any ideas? I appreciate your help ;)

1 answer

0

  • thank you for answering. AWS Elemental Mediaconvert, converts all my content from my Bucket or would convert the content I select, such as Amazon Elastic Transcoder works?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.