-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
HLS: Rewrite HLS(espaciallly audio-only) for aac. #547
Comments
The problem with the loud sound has been identified. It is caused by the sampling rate, which results in timestamps that cannot be evenly divided, leading to errors. Safari is more accurate, hence the popping sound. The verification is as follows: first, consider a sampling rate of 8000Hz. An AAC frame consists of 1024 samples, so one AAC frame is:
The SRS configuration is as follows:
Transcode using FFMPEG to output audio at 16KHZ.
When accessing http://localhost:8080/live/livestream.html with Safari, it can be observed that there is no audio distortion. When transcoding, output the audio at 44100Hz.
You can hear a "popping" or "crackling" noise every 4 seconds or so. It happens with each piece, but you have to listen carefully to notice it. What is the reason? At 44100Hz, each AAC frame is:
If rounded, each frame will have an error of 0.2ms. Safari is more sensitive, so problems are more likely to occur. How to solve this problem? NGINX combines multiple AAC frames into one TS Packet and then calculates the accumulated time. If calculating the time for each frame directly:
This way, the error can be reduced to 1/90. For example, the information of an audio is:
However, the result recalculated based on the number of samples is:
After 200ms:
As a result, there was no more popping sound.
|
It seems that there is no need to encapsulate pure audio HLS in AAC format, TS is fine.
|
Note that although this improvement can prevent HLS audio explosion, it may generate a large number of very small segments in HLS due to timestamp issues. Refer to #1506. The solution is to add a configuration to disable this improvement and use the original timestamps for direct conversion, which may still result in HLS audio explosion issues.
Using AAC sampling conversion, without using the original timestamps, there are no HLS audio explosion issues, but there may be abnormal slicing problems:
|
Wiki: https://github.com/ossrs/srs/wiki/v3_CN_DeliveryHLS#hls-audio-corrupt https://github.com/ossrs/srs/wiki/v3_EN_DeliveryHLS#hls-audio-corrupt
|
The AAC audio stream of HLS needs to recalculate the timestamps, so this part of HLS needs to be rewritten, especially the pure audio part. Currently, there are no issues when mixing HLS audio and video streams, probably because there is video as a reference. However, pure audio streams will have crackling noise, which is caused by the gaps between audio packet aggregation. Apple replied that AAC should be used instead of TS, and the timestamps need to be recalculated.
For a detailed understanding of AAC audio standards and MP3 standards, you can refer to SRS3.
TRANS_BY_GPT3
The text was updated successfully, but these errors were encountered: