jsmpeg icon indicating copy to clipboard operation
jsmpeg copied to clipboard

JSMpeg not playing audio when websocket stream is used

Open nikshay-psts opened this issue 3 years ago • 3 comments

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

nikshay-psts avatar Dec 28 '22 08:12 nikshay-psts

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 avatar Jul 26 '24 09:07 Xbai-hang

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

  • had problem: ffmpeg -i rtsp://**** -f mpegts -c:v mpeg1video -ca: mp2 -ar 16000
  • solved problem: ffmpeg -i rtsp://**** -f mpegts -c:v mpeg1video -ca: mp2 -ar 32000

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.

Xbai-hang avatar Jul 27 '24 01:07 Xbai-hang

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.

phoboslab avatar Jul 27 '24 09:07 phoboslab