Comments (4)
Hey, I'm glad you find useful :)
The audio sync is the most difficult part! I'm doing it by syncing audio samples with the video frames. At the beginning of Screamer you can see the following code:
// Audio
audioFlowTicks = DateTime.UtcNow.Ticks;
long audioDelayTicks = delayTicks;
if (decoder.hasAudio)
if (vFrame.timestamp + audioExternalDelay < decoder.aStreamInfo.startTimeTicks || vFrame.timestamp + audioExternalDelay > decoder.aStreamInfo.durationTicks)
audioDelayTicks = -10000000; // Force Resync Later (Audio Paused)
> else ResynchAudio(vFrame.timestamp - audioExternalDelay, true);
After I make sure that Audio/Video queues are filled with the right timestamps and synced I keep track of audioDelayTicks/delayTicks. Those (delayTicks) are actually how much "off time" are currently the video frames and when they are much enough we reset them to the the current timestamp. But when the video frames are going off we don't reset audio directly (audioDelayTicks), in that way we would have to do it all the time. So when the distance is more than 220ms it will do the re-sync.
In that way you make sure that your video frames and your audio samples will be screamed almost at the same "allowed" time frame.
After that I use audioFlowBytes/ audioBytesPerSecond which are configured based on the audio configuration / sample ratio etc...
audioBytesPerSecond =(int)( _RATE * (_BITS / 8.0) * _CHANNELS);
to make sure that I will send the flow in the same rate that the audio player requires to keep the audio queue low (which means memory low). But even after all that, I still had a problem with the audio player (naudio). Each audio player has a different way that it works :) It means that NAudio requires some time/bytes to load its buffer before play. That's why you will see the comment...
const int NAUDIO_DELAY_MS = -330; // Probably waits to fill it's buffer? had to use this for sync https://www.youtube.com/watch?v=ucZl6vQ_8Uo
Finally, there are more thinks that you could add to make it better. For example, you could sync during silence. So the listeners will not notice the difference.
Hope that helped, but if not you could check more details about audio sync here:
from flyleaf.
Thank you very much for your answer.
from flyleaf.
No problem dude. You made me look back again the code and I found a couple of issues, check out my latest commit for details!
from flyleaf.
Let me check your new commit.
Thank you again.
from flyleaf.
Related Issues (20)
- Flyleafhost: Overlap & Transparency HOT 5
- There is a small black dot when FlyleafHost is initialized With Collapsed
- WinUI Memory Leak & Possible Fix HOT 1
- Overlays / Stats HOT 2
- Brilliant library, but I'm struggling with limited doco... HOT 12
- ShowFrame(0) does not work anymore in 3.7.42 HOT 3
- How can I tell if a file stream has a valid/playable audio and/or video stream? HOT 1
- Player.TogglePlayPause() doesn't restart from the pause point HOT 14
- Hello, may I ask how to play such data? HOT 2
- Unable to trap attempt to play an invalid video file HOT 3
- FlyLeaf libraries and DPI challenges HOT 7
- May I ask if it is possible to restore the function of resuming playback without reconnecting the old version after interrupting the stream? HOT 1
- System. AccessionViolationException when ShowFramePrev HOT 2
- When multiple players play the same file, the sound may be louder or softer HOT 1
- Play Delay HOT 1
- Play Delay HOT 9
- if i want to save i frames only how can i do? HOT 1
- To get thumbnail of the video on seek bar HOT 1
- How to send commands directly to FFMPEG engine while video is loaded and playing HOT 3
- about key redefine~ HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flyleaf.