Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to play audio when not playing from beginning of a file. #48

Open
fabslab opened this issue Oct 25, 2013 · 21 comments
Open

Unable to play audio when not playing from beginning of a file. #48

fabslab opened this issue Oct 25, 2013 · 21 comments

Comments

@fabslab
Copy link
Contributor

fabslab commented Oct 25, 2013

I wasn't sure whether to put this issue here or in the MP3.js repo because I was running into this problem while attempting to use it for my demuxer/decoder and not sure if the issue was specific to just the MP3 demuxer.

It seems in order to successfully find the correct demuxer (MP3 in this case) through probing the first chunk of audio data that aurora receives, it must receive the beginning chunk of the actual file being streamed? I'm not entirely sure here because I'm not yet very familiar with the MP3 codec but that's what the code looked like it was doing to me.
I came across this when connecting to a server that started streaming audio data from a continuous source (not a discrete track that had a beginning) and noticing the data was received but a demuxer not found and so there was no playback. I had assumed this would be supported since one of the purposes of the library was to play podcast or radio style streams.
If you could help clarify that would be great.

@devongovett
Copy link
Member

In the case of MP3 it might work. Normally we need the beginning of the file since container formats usually provide format info at the beginning. MP3 is weird in that it doesn't really have a container format, so the demuxer just looks for the first valid MP3 frame. Maybe your chunk sizes aren't big enough? If it doesn't find anything in the first chunk it receives, it won't look further.

Another option, is since you know it is MP3 just skip the demuxer all together and go straight to the decoder. This would require slightly more work on your part, but you could basically subclass the MP3Demuxer (MP3Demuxer.extend) and override the probe class method to just return true, and remember to call AV.Demuxer.register(YourSubclass). Honestly I'm not sure what will happen, I've never tried streaming stuff, so let me know how it goes.

Try increasing your chunk size from (I assume) your custom source first, then try the custom demuxer idea...

@fabslab
Copy link
Contributor Author

fabslab commented Oct 26, 2013

I changed the MP3.js file while testing to just return true in the probe function (for now, instead of extending the class).
Now it tries to decode it but for every chunk it throws the AV.UnderflowError each time. It gets as far as this line
https://github.com/audiocogs/mp3.js/blob/master/src/header.js#L267 in MP3FrameHeader.decode before failing the Stream.prototype.available function in aurora.

@devongovett
Copy link
Member

Yeah sounds like a chunk size issue maybe. Is it possible for you to increase it? What does your source look like?

@fabslab
Copy link
Contributor Author

fabslab commented Oct 27, 2013

Audio is coming from FFmpeg sending the audio through HTTP to a server that's relaying that audio over WebSocket to aurora. Have to experiment with FFmpeg options I think.

@asherawelan
Copy link

I'm working on this same issue:- using ffmpeg, data arrives into mp3.js, but not much else:-
Tried:-
ffmpeg -loglevel debug -re -i mind-explosion-1.mp4 -f mp3 -chunk_size 105k http://127.0.0.1:8081;

Tried with and without -re and changed chunk_size to various sizes, nada. Any advise welcomed.

@asherawelan
Copy link

Server is very simple setup:

var http = require('http');
var connect = require('connect');
var ws = require('ws');

// Consume the ffmpeg audio stream
var audio_consumer = http.createServer( function(req, res) {
    console.log('Audio Stream Connected: ' + req.socket.remoteAddress);
    req.on('data', function(data){
        //When video data arrives, send to all the producer's clients
        for (var i in audio_producer.clients){
            audio_producer.clients[i].send(data, {binary:true});
        };
    });

    req.on('end', function () {
        res.end("Thanks");
    }); 

    req.on('error', function(e) {
        console.log("ERROR ERROR: " + e.message);
    });
}).listen(8081, "127.0.0.1");


var audio_producer = new ws.Server({port: 8071});
audio_producer.on('connection', function(socket) {

    console.log('Audio Client Connected'); 

    socket.on('close', function(code, message){
        console.log( 'Disconnected Audio WebSocket ('+audio_producer.clients.length+' total)' );
    });
});

console.log('Awaiting ws Audio Connections on http://127.0.0.1:8071/');

@devongovett
Copy link
Member

@asherawelan what does your client side code look like? I assume you implemented some sort of web socket source. I've actually never tried this with aurora, so I'm interested in getting this working.

@asherawelan
Copy link

Here it is :)

<html><head>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/aurora.js"></script>
<script type="text/javascript" src="js/aurora-websocket.min.js"></script>
<script type="text/javascript" src="js/mp3.js"></script>

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
    AV.Player.fromWebSocket('ws://vixen.awelan.com:8071').play();
});
//]]>
</script>

</head>
<body>
<div id="container">
MP3 should stream here...
</body>
</html>

@fabslab
Copy link
Contributor Author

fabslab commented Oct 28, 2013

It seems no matter how many bytes are coming through it keeps failing the Stream.prototype.available test. It's often by just 1 byte more.

@devongovett
Copy link
Member

I looked at that code you linked to in mp3.js above where you are seeing the error, and have a possible explanation. That code is looking for the next frame after the current one, which is apparently not loaded yet. Or perhaps because the next frame hasn't been encoded yet since it is streaming, looking for the next frame there is wrong. I'll play around a bit and see if I can figure something out.

@asherawelan
Copy link

You legend! I'm happy to tip you for your time...cheers!

Sent from my iPhone

On 28 Oct 2013, at 04:50, Devon Govett notifications@github.com wrote:

I looked at that code you linked to in mp3.js above where you are seeing the error, and have a possible explanation. That code is looking for the next frame after the current one, which is apparently not loaded yet. Or perhaps because the next frame hasn't been encoded yet since it is streaming, looking for the next frame there is wrong. I'll play around a bit and see if I can figure something out.


Reply to this email directly or view it on GitHub.

@asherawelan
Copy link

Any further news on this? Happy to tip the person who can fix it... cheers!

@rodhoward
Copy link

I would love to know if there is any progress! Streaming live feeds seems like THE reason to use these javascript codecs rather than simply using the browser html5 audio tags. Its the perfect used case except that it isn't working.

@asherawelan
Copy link

I never got it working for live streaming, such a shame...

@asherawelan
Copy link

Bump

@asherawelan
Copy link

Any further progress on this @devongovett - really keen to get this working... Cheers

@pafnat
Copy link

pafnat commented Sep 12, 2014

i'm also interested. is at any solutions?

@fabslab
Copy link
Contributor Author

fabslab commented Sep 30, 2014

I think this is related to what's discussed here audiocogs/mp3.js#12

@CoMMyz
Copy link

CoMMyz commented Jul 14, 2015

Anyone found a solution to this?

Thanks

@driesken
Copy link

driesken commented Apr 5, 2016

I was wondering the same thing. Anyone found a working solution?

I'am able to receive audio packets at browser level, but I don't have any sound.

@DeusExLibris
Copy link

See this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants