phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.38k stars 1.43k forks source link

JSMpeg not playing audio when websocket stream is used #411

Open nikshay-psts opened 1 year ago

nikshay-psts commented 1 year ago

I am streaming RTSP stream to web browser using ffmpeg with help of a websocket relay in node js as per the example given here https://github.com/phoboslab/jsmpeg

FFMPEG command used: ffmpeg -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 -f mpegts -c:a mp2 -c:v mpeg1video http://127.0.0.1:5100/stream_from_ffmpeg

The video is playing good, but no audio, if i open the same RTSP URL above in vlc, the video plays along with the audio

Xbai-hang commented 4 months ago

I have the same problem. When I used the project node-rtsp-stream, JSMpeg don't play audio. But When I used the project: rtsp2web, JSMpeg played audio.

They all used the command: ffmpeg -i rtsp://**** -f mpegts -c:v mpeg1video -ca: mp2

So I think maybe this problem isn't caused by JSMPeg.

And I want to know if you solved this problem. If can, please tell me. Thank you.

Xbai-hang commented 4 months ago

I found the situation which caused this problem. Here are my ffmpeg options:

I test the sampling rate: 16000、22050、32000、44100、48000。

My raw stream sampling rate is 16khz、and when I set the option -ar to 32000 and higher, I heard the audio sound.

I hope this can help you.

phoboslab commented 4 months ago

That's interesting. JSMpeg just uses the WebAudio createBuffer() function for audio, which should work with allmost all sample rates:

All browsers must support sample rates in at least the range 8,000 Hz to 96,000 Hz.

My assumption is that this issue is caused by a locked audio context. The test if WebAudio needs to be unlocked (testing only if we're running on iOS devices) is no longer true. All browsers start out with a locked context now. Proper unlocking is only handled by the VideoElement.

So, I'm not sure why the change in sample rate would fix that for you.