The easiest solution is to use your computer's accurate clock to time the frames. This means, if your video is at 30 FPS, you will have gone through exactly 3000 frames after 100 seconds. But your monitor might not be refreshing at exactly 60 FPS, it might be targetting the 59.94 standard, or it might be targetting 60 FPS but with a clock that's a bit less accurate than your computer's, so every now and then, you get a stutter as a video frame has to shown for 1 refresh interval longer or shorter than it should.
What we could do instead is to calculate a fixed pattern to display frames. If your monitor is 30Hz and the video is 30 FPS, we show exactly one video frame for every monitor refresh. If your monitor is 60Hz and the video is 30 FPS, show each video frame for 2 monitor refreshes. If the monitor is 30Hz and the video is 60 FPS, skip every other video frame. This will already introduce some deviation from the "ideal" timing if your display clock isn't super accurate. And if the monitor is 59.94Hz, that's probably close enough to 60 that we want to show each frame of 30 FPS video exactly twice, but that means the video is playing at 99.9% of its intended speed.
10 seconds over 20 minutes is a surprisingly big gap though. Playing every frame of 30 FPS video twice on a 59.94Hz monitor would net a 1.2 second deviation over 20 minutes.
EDIT: Why the downvotes? Everything here is correct according to my understanding of the situation after implementing video playback software and working with other people's. If anything is wrong, please correct me, don't just silently downvote.
The issue with framerate mismatch is a fundamentally different one, in that it's not a synchronization problem. It's the result of a non-integral ratio between display frames and playback frames, and exists regardless of clock source. So it's the harder of the two to deal with, and is worse in magnitude too at several slipped frames per minute with e.g. 29.976fps vs. 30fps. In the classical approach, this simply results in frames getting doubled or skipped, since it's not tracking the video rate at all, it just asks for the display to be updated at its frame-time, and the display system will either get a chance to show it or not. The slightly more refined approach is to play back at the closest integral ratio (e.g. play 29.976fps video at 30fps on a 60fps display), and resample the audio to match this new rate, but again this is computationally expensive and complicated.
mpv team has a good writeup: https://github.com/mpv-player/mpv/wiki/Display-synchronizati...
And unless you're using some kind of variable refresh rate, the monitor always, always refreshes on a fixed interval. It doesn't do any "synchronizing a stream of frames to the display refresh rate". But with VSync, you can synchronize your software with the display refreshes, which is how you can decide to draw every frame twice and that sort of stuff.
On some embedded platforms, if you can't get a precise clock you need from clock subystem, or massage the display mode timing to fit whatever pixel clock you can generate, you may be running your display at 34 FPS instead of 60 FPS if you're not careful eneough. And you'll barely notice unless you measure it, or try to play video or do anything else sensitive to timing.
How is that "better than pulse ever did"? The only issue I had with PulseAudio on several machines in last decade or so was Bluetooth A2DP connection being very capricious.
I have recently switched to PipeWire and it actually improved Bluetooth, but I had to disable Wireplumber's libcamera backend because it made it regularly eat 100% of RAM. No complaints after doing that. Crackling noises or desynchronized video playback would instantly take it into "unacceptable" territory.
Sounds like you have severe issues with both PA and PW. Maybe your hardware is the problem?
The "I hate Pulse Audio and especially Lennart" crowd tends to want to either go back to "Alsa" or tried at some point to install the old OSS drivers and then gave up.
This means trying to configure dmix to work properly, trying to configure your audio outputs with tools like 'alsamixer' and things of that nature.
This is about a 100% guaranteed approach to screwing up audio in Linux. For years it is what unsuspecting newbies were told by "really smart people" on the internet when faced when any sort of audio issue and all it really does is ensure that their OS audio is going to turn into a dumpster fire.
The only way to fix it is to aggressively find your "custom" audio settings for every application, find all the alsa configuration files and delete them. And then find out where your distribution saves your alsa mixer settings between reboots and link them to /dev/null and reboot.
Audio settings of this nature are very persistent and nothing Pulseaudio or Pipewire can do to help you fix it.
To me it's a low-feature deterministic stack that rarely does what I don't want it to.
But I haven't introduced a bunch of fuel for the fire like bluetooth audio devices either... to each their own.
Well, yeah, since when pulse showed up and started breaking people's audio it effectively replaced alsa (even though they kind of operate at different layers). So if you didn't like that, of course the solution was to rip out Poettering's bugfest and revert to alsa. Thankfully at some point pulse stabilized a lot and in my experience tends to just work out of the box these days, but people tend to have their habits set by the early versions that were pushed out before they were ready.
It's "better than Pulse ever did" because they do not have the same hardware as you, and because whatever they had before was worse.
Lesson 2 about discussing technical issues on the internet: other posters almost certainly do not have the same hardware as you.
(this is also relevant when it comes to discussing software performance - the fact that Slack loads in 5 seconds on your desktop does not make it "fast", because the entire internet does not have your desktop)
Thanks for reiterating my point, I guess.
> Sounds like you have severe issues with both PA and PW. Maybe your hardware is the problem?
Seconding this! My experience with PA and PW has been basically identical to yours. If possible, GP, try some different hardware! You shouldn't have to put up with that crap.
Pulse would cause games to crash or not even start (i know this because switching to pipewire resolved that), for example. Pulse, for me, was beyond broken on every machine I used it, in some capacity. PipeWire is, too, but in a way that doesnt ruin my day ;)
Sure, could be, though my hardware is quite common.
I've opened two bugs, and two times he fixed them personally in less than a week, which is incredible for an open source project of that size.
This one breaks audio and video in virtual machines:
https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/46...
The effects of this one vary:
https://gitlab.freedesktop.org/pipewire/wireplumber/-/merge_...
For me it breaks audio in Chrome and VLC:
It was issues with Pulse I wanted to know more about. Low latency is obviously not it's forté, otherwise it just works, for me that is.
Yes, for example, the zoom app is now one of the most widely relied on apps for connecting people over networks. To get its audio output to fairly represent the input (e.g. for musical content), the input client is supposed to use the 'original audio' setting. That setting is not yet available on the linux version of zoom. On the output end, the audio is a mess, sounding as if somewhere along the way a handshake has turned into a fistfight.
Audio is complicated. Another example: an ordinary amateur, part-time, casual guitarist might nowadays play with thousands of dollars of pedals and processors plugged into his signal path. He gets this to work by plugging and unplugging those devices and their cables in various configurations until everything sounds best. Try providing that level of flexibility in software with reasonable default settings for all of the myriad of applications and environments in which one might try to apply computer audio.
2060: PipeWire11 is being deprecated and replaced with a compositing audio server named Weyband
Like at the end of the day option 2 is still "ALSA just works".
That is the regular desktop user. If you do any for of audio processing (pod casting, music recording) you may have a large number of different inputs and output connected, and want to do mixing of some sort. Likewise if you do videos you may have more than one "webcam" that you want to mix. These are fairly common use cases (many people have a dream of being a musician or an actor, and so have this type of setup that they are trying to use in the efforts to make it big)
The correct answer to that specific question: as a sane default, all sound should now go through the headphones. That's a sane default on the Iphone, probably on Macbooks, and it also happens to be the one that at least a stock Gnome or Ubuntu desktop chooses. In fact I have trouble thinking of a saner default than that one!
Forgetting about sane defaults seems to be a common problem in FOSS communication. It's unfortunate, because describing something as unknowable can convince a new developer to avoid inspecting the code around that particular problem.
E.g., it took a long time for Gnome to get the sane default I describe above. I'd bet that lurking in the appropriate mailing list history is at least one didactic post from an audio developer explaining how we can never truly know what a user's preferred setup could be.
-Per-application volume control
-Seamless hardware switching mid-stream (plug in headphones)
-Different channel configurations into the same device simultaneously
-Cross-application volume ducking
Also ALSA cannot do other nice things, like switching audio output when you plug an USB audio card.
JACK exists becase some people need low latency and dynamic control over non-trivial audio routing.
pipewire attempts to bring the best of both worlds and make it container friendly for security purposes.
Wouldn't latency be lower if the application would access audio card directly without any daemons in between?
This is a clear case of when ideology won over an objectively better product to the detriment of all users for more than a decade.
I don't mourn the loss of OSS.
Also with OSS you still can't seamlessly switch between devices, bluetooth or arbitrary signal routing between apps. So, no... good riddance.
I also just use raw ALSA. It's there anyway, it works, and I don't need more daemons (I don't need NetworkManager either).
That said, I've had daily issues with it, from it slowing video playback (weirdly, by about 10 seconds over 20 minutes or so, only noticable when watching something synchronized with someone else), over crackling noises with speakers when no audio is playing, to straight up lags and skips every few seconds with certain devices.
Audio on linux is a complete joke, and I'm glad pipewire is there to tackle it.