postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
839 stars 91 forks source link

Synchronization of system output with streamed content #2220

Open vigneshpai2003 opened 9 months ago

vigneshpai2003 commented 9 months ago

What do you need help with?

Currently, I am using ffmpeg -f pulse -i default -f mp3 - | atvremote ... stream_file=- to pipe the system output to pyatv. However this has synchronization issues, the audio playing from my Homepod mini (17.0) is approximately a 6 seconds behind the corresponding video on my pc. My guess is that ~4 sec are due to ffmpeg and ~2 sec are due to pyatv.

Is there anyway to to reduce this synchronization problem on ffmpeg or pyatv side? 6 seconds are too much for standard audio-video synchronization settings on many media players.

postlund commented 9 months ago

I believe you are roughly correct in that delay. As I'm not well acquainted with ffmpeg and all the settings you can tinker with, I can't give you a good answer. I would expect that you can decrease the latency in ffmpeg with some settings (probably related to buffer sizes). It would technically be possible to lower latency in pyatv a bit, I don't know how things would be behave if you do. It's something I could expose as a setting and let people tinker with however.

The only reasonable solution to me would be to use a video player that allows for audio/video delays, like VLC for instance. It would not work in general cases, like video in a web browser though.