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

Audio is flickering while streaming to Youtube #554

Open
thakurmayu07 opened this issue Nov 21, 2017 · 54 comments
Open

Audio is flickering while streaming to Youtube #554

thakurmayu07 opened this issue Nov 21, 2017 · 54 comments
Labels

Comments

@thakurmayu07
Copy link

I can successfully live stream on youtube by using this library but the audio quality of uploaded video is not so good. It is flickering. How can I solve that?

@begeekmyfriend
Copy link
Owner

I have expanded the PCM sampling buffer. Please try this commit

@thakurmayu07
Copy link
Author

Hi, Thanks for the reply. I did exactly what you have committed but I got BufferOverflowException
Below is the error log report

java.nio.BufferOverflowException
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:264)
at net.ossrs.yasea.SrsEncoder.onGetPcmFrame(SrsEncoder.java:354)
at net.ossrs.yasea.SrsPublisher$2.run(SrsPublisher.java:108)
at java.lang.Thread.run(Thread.java:761)

@thakurmayu07
Copy link
Author

thakurmayu07 commented Nov 22, 2017

Hi, when I set mPcmBuffer byte array size in SrsPublisher.java to 16384 it gives me BufferOverflowException on bb.put(data, 0, size); in onGetPcmFrame(byte[] data, int size) method. But when I set mPcmBuffer size to 4096 it works fine. Please help.

@begeekmyfriend
Copy link
Owner

I am afraid 4096 is the limitation for microphone reading.

@thakurmayu07
Copy link
Author

Yes, you were right. 1 frame of a Stereo 48khz 16bit PCM stream is 4 bytes. So to fix the flickering of sound I changed the audio sampling rate to 16KHz and audio bit rate to 64kbps. Now sound is smooth while streaming.

@begeekmyfriend
Copy link
Owner

But the sampling frequency is 44.1K by default.

@thakurmayu07
Copy link
Author

thakurmayu07 commented Nov 23, 2017

Yes I changed it to 16000 and keep PCM buffer size to 4096

@st4ycool
Copy link

Same problem here.
@thakurmayu07 so, the problem is solved? Can you link a commit?

@begeekmyfriend
Copy link
Owner

begeekmyfriend commented Jan 15, 2018

@st4ycool You may change this line. But do not issue a PR for it is not a universal solution.

@thakurmayu07
Copy link
Author

@st4ycool As @begeekmyfriend has mentioned it, change it to 16000

@st4ycool
Copy link

st4ycool commented Jan 15, 2018

@begeekmyfriend 16khz doesnt really solve the problem. Here is stream with 16khz audio: https://www.youtube.com/watch?v=3ZXoZMTezmk

@thakurmayu07 have you tried to go below 16k? My MediaCodec crashes if there are lower values

@st4ycool
Copy link

It seems to me the issue is in AAC part. ADTS headers writes in some wrong way

@begeekmyfriend
Copy link
Owner

The ADTS writing code is here. Would you please show me anything wrong?

@st4ycool
Copy link

I don't know what exactly wrong, I am trying to solve it for a while. Maybe they are written too often?

@begeekmyfriend
Copy link
Owner

ADTS is only for AAC-LC. It works all right for other players except Youtube. What kind of format of AAC for Youtube? AAC-HE or AAC-HEv2?

@st4ycool
Copy link

No details provided by youtube... does it mean they accept any of them?
https://i.imgur.com/vHgNvC0.jpg
https://support.google.com/youtube/answer/2853702?hl=en

@begeekmyfriend
Copy link
Owner

begeekmyfriend commented Jan 17, 2018

@st4ycool @thakurmayu07 There are two solutions:

  • Comment out these two lines in main branch and see if it is all right on Youtube.
  • Switch to the aac-hev2 branch and see the result.

Note both of two solutions above are not compatible with some old flash media players.

@st4ycool
Copy link

@begeekmyfriend

I tried streaming using both solutions, but it didn't solve issue. But I noticed something very strange:

When I stream LIVE I hear audio flickering, but when youtube saves live stream to videos, it sounds OK. Why?

I was streaming with 4g, and watching my live stream with wired 100mbps, so it's for sure not the bandwidth problem.

It looks like youtube cant decode quickly enough?

@begeekmyfriend
Copy link
Owner

@st4ycool Maybe. Then what about 16K sample rate?

@st4ycool
Copy link

yasea he v2 24000: youtube stream is not starting.
yasea he v2 44100: youtube stream is not starting.
yasea master 16000: stream is ok, audio is ok(I swear yesterday audio was flickering), also youtube says to set audio sampling rate to 41.1khz or 48khz

What can be wrong with youtube when sample rate is 41.1?

@begeekmyfriend
Copy link
Owner

Never sound 41.1K, maybe the best choice is 48K for you...

@st4ycool
Copy link

My bad, I meant 44.1khz, of course.
48k is flickering.

@st4ycool
Copy link

@begeekmyfriend
I still havent found a solution.
Why we have MediaCodec converting PCM to aac, and why we have to add adts manually?

@begeekmyfriend
Copy link
Owner

PCM is the format for voice sampling.
ADTS header is for AAC-LC and necessary for decoding. But it would not be produced automatically by MediaCodec.

@st4ycool
Copy link

st4ycool commented Feb 13, 2018

@begeekmyfriend
I don't see those parts of header in yeasea's writeAdtsHeader: https://i.imgur.com/OOKGZ7c.jpg

P.S. mp4 record sounds great, but it doesn't relate to AAC we are talking about, right?

@st4ycool
Copy link

st4ycool commented Feb 13, 2018

That's how I hear it on youtube stream LIVE:
Recording (35).zip
and that's how it sounds when youtube autosaves live stream to videos: https://youtu.be/339ILW_WgnY?t=26

@begeekmyfriend
Copy link
Owner

begeekmyfriend commented Feb 14, 2018

I forgot to tell you that ADTS is for conventional flash media player which has been abandoned by Youtube.

@st4ycool
Copy link

@begeekmyfriend I can start youtube stream without ADTS, but it sounds same terrible when live.
What can be wrong, keeping in mind that autosaved stream's sound is perfect?

@thakurmayu07
Copy link
Author

@st4ycool @begeekmyfriend Have you found any solution? Live stream with 16K sampling frequency also creates noise when audio is loud or multiple persons are talking. Also I observed that voice is cutting after every 2-3 seconds.

@st4ycool
Copy link

@thakurmayu07 the thing is YouTube can't decode yasea's AAC fast enough to broadcast without audio lags (because auto-saved video is fine). So I think the only solution is to improve/replace the AAC part.

I ve been streaming on facebook and there is no such problem like audio lags.

@thakurmayu07
Copy link
Author

As I can see in SrsEncoder class the audio codec is "audio/mp4a-latm". Can we change it to something else?

@thakurmayu07
Copy link
Author

image

We need this configuration

@begeekmyfriend
Copy link
Owner

begeekmyfriend commented Mar 8, 2018

You can try on your own. I think it is the issue of Youtube not the streaming. @st4ycool has said that streaming on Facebook is OK, right?

@thakurmayu07
Copy link
Author

thakurmayu07 commented Mar 14, 2018

Hi guys, I have found the issue. The library is fantastic, you just need to set latency to normal in YouTube admin panel. For more details : https://support.google.com/youtube/answer/7444635?hl=en

yasea

@st4ycool
Copy link

@thakurmayu07 genius. How could it have been so easy? Wow! Thank you!
Tell me how you decided to try adjust some settings?

I always thought it was something with audio codecs. Sorry, @begeekmyfriend , your codecs are shiny!

@begeekmyfriend
Copy link
Owner

Unfortunately I do not get access to Youtube quite conveniently in China you know it...

@st4ycool
Copy link

@begeekmyfriend I totally forgot about China firewall.
Thanks for support.

@thakurmayu07
Copy link
Author

@st4ycool I was going in details about the requirements of video stream. There I found latency settings. I changed that from admin panel and boom! everything works like charm.

@begeekmyfriend This library is awesome. As we understand the issue and come to know that library doesn't do anything wrong, you can close this thread now.

@begeekmyfriend
Copy link
Owner

@thakurmayu07 Better keep it open and let someone know it.

@thakurmayu07
Copy link
Author

@begeekmyfriend Yes, Sure.

@huongtran84
Copy link

Hi guys, I have found the issue. The library is fantastic, you just need to set latency to normal in YouTube admin panel. For more details : https://support.google.com/youtube/answer/7444635?hl=en

yasea

But I still need low latency and ultra low latency because of An ultra-low-latency stream further reduces the time it takes for video to be visible to viewers, making interaction with viewers easier.If I use normal latency long time.

@maniacs-engineerica
Copy link

@thakurmayu07 , I am trying to stream to Youtube too, but it is not working. The logcat is no showing errors, so it seems to work fine. I think the problem is regarding the authentication. How do you push to the rtmp link being authenticated?

Thanks in advance.

@huongtran84
Copy link

long time I still not resolve audio flicker while using youtube with ultra low latency mode.any one help me.

@kboskin
Copy link

kboskin commented Jan 6, 2019

getting same trouble with AWS MediaLive service. When streaming from obs everything seems to be fine

@begeekmyfriend
Copy link
Owner

@KostyaBoss please check out the configuration settings on AWS MediaLive service and try more times.

@kboskin
Copy link

kboskin commented Jan 6, 2019

@begeekmyfriend thanks for quick responding. Maybe you know what exactly should I configure? Stub with this issue for 2 days right now

@begeekmyfriend
Copy link
Owner

@KostyaBoss In China it is hard to connect with AWS. The reason you know...

@kboskin
Copy link

kboskin commented Jan 21, 2019

@begeekmyfriend after some research I've found that the problem is in default google encoder. If I am setting force to harware everything goes fine. Btw it also fixes YouTube problem. But it works only on some devices (for ex Samsung) which have their own encoder. How do you think, is it possible to make some expanding and install custom encoder on runtime?

@begeekmyfriend
Copy link
Owner

@KostyaBoss Your issue is out of my knowledge but the information you provided might be very valuable for others.

@mhackeras
Copy link

mhackeras commented Apr 9, 2019

by searching and using some of the examples above.. audio is not fine. still same problem..
but i am looking into this!

@ghost
Copy link

ghost commented May 28, 2019

@KostyaBoss I found that useSoftEncoder in SrsEncoder class is false by default.

private boolean useSoftEncoder = false;

Is this the forcing that you're talking about?
Unfortunately useSoftEncoder = false does not work for me, audio is still flickering.

Any other ideas?

N.B.: I'm trying to stream to AWS MediaLive service

@mhackeras
Copy link

@axelbartolomei did you try enable it and test?

@heaveninfosoft
Copy link

@thakurmayu07 how to live stream to youtube>?? i cant please help me

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

No branches or pull requests

8 participants