stephen / airsonos

:musical_note: AirPlay to Sonos
MIT License
2.1k stars 255 forks source link

Synchronized Sound Output #44

Open ghost opened 10 years ago

ghost commented 10 years ago

When I stream a movie or just when I hit next song on Spotify there's a delay of 0.5s I can't watch a movie when the sound is not sync correctly.

My sonos play5 is connected by ethernet and the laptop is on the Wifi.

I think we can fix this by starting the playback at 0:05s ahead instead of 0:00. Any ideas?

fordjam commented 9 years ago

I've also experienced this, but this seems to be isolated to streaming audio from my mac. when i stream from an ios device there is no lag / delay. Is there any way to fix this?

picsoung commented 9 years ago

It comes from the Airplay standard, no ?

sp90 commented 9 years ago

Anyone working on solving this issue, or is it actually the video that needs to be delayed, because the sonos is that much slower?

odcinek commented 9 years ago

Can confirm, on ipad ios 7.1.2. Interestingly, plex and direct safari video playback are affected, but youtube is not.

odcinek commented 9 years ago

@stephen could you provide some context on this? After cursory look at teh code it looks more like a https://github.com/stephen/nodetunes issue

jiji2x commented 9 years ago

Hi all

I am experiencing the same issue when streaming from my iMac. Any fix I can implement in order to have video and sound synchronized?

Other than that, thanks for the Airsonos development, it's great.

peteruithoven commented 9 years ago

I also agree that the video should be slightly delayed. Syncing that is probably difficult since airsonos can't control specific applications like VLC. You can delay the video of VLC quite easilly yourself with the the F and G keys.

bugs181 commented 8 years ago

This issue is due to https://github.com/stephen/nodetunes/issues/40

I believe the issue comes down to one or more of the following:

  1. nodetunes not parsing the rtptime from RTP-Info header
  2. The RTP sequence number
  3. timing packets (I don't believe nodetunes handles this)
  4. sync packets (I don't believe nodetunes handles this either)
  5. Incorrect parsing of the RECORD request (it includes initial RTP sequence number and initial RTP timestamp)

I don't understand the AirPlay protocol well enough and have only been looking into the matter for less than 2 days.

More info Sync Packets:

Sync packets are sent once per second to the control port. They are used to correlate the RTP timestamps currently used in the audio stream to the NTP time used for clock synchronization.

Timing Packets: Timing packets are used to synchronize a master clock for audio. This is useful for clock recovery and precise synchronization of several devices playing the same audio stream.

jonbid commented 8 years ago

i have the same issue. when i play a video on my iphone, the sound starts a few seconds later. there's no sync. if there was a solution to this, then this would seriously be the best app ever.

jonbid commented 8 years ago

ok, so I've been playing around with this. it seems the delay is 4.7 seconds. so using video playback apps on iOS that let you adjust the delay makes things work perfectly.

I am using VLC for iOS to playback files that use DTS codec (movies... this is one of the only apps that supports this codec) and AVplayerHD for everything else. then I adjust the audio delay in each app to -4.7 and the audio and video is now in sync.

only issue now is playing videos from a web browser/YouTube.

axbmcuser commented 8 years ago

Question regarding audio sync/delay:

For a long time, using AirSonos on a clean RPi2 - using a iOS6-iPad (YouTube App Video Playback) has been almost in sync. You could watch the video on the iPad and the sound send via AirPlay to the Sonos (Play:1) was only slightly(!) out of sync (talking about 0,5 seconds or so). After not using the setup for some month - today - this is not possible anymore because of the approx 4 seconds delay.

What has changed? Does it have to do with the never Sonos Software Versions? (Nothing else seems to have changed. The AirSonos setup is exactly the same, so is the iPad)

Thanks.

jonbid commented 8 years ago

it would take the dev doing some work to get things to sync with youtube etc... not sure he cares :/

knubie commented 8 years ago

I'm fairly certain most of the delay is caused by streaming with shoutcast. The audio needs to be encoded to mp3 server-side before it's streamed, which can take 500~1000ms, then you have the client playback buffer, which can add several seconds depending on the client. @axbmcuser I imagine, all else being the same, that Sonos increased the playback buffer.

jonbid commented 8 years ago

think there is a workaround?

jonbid commented 8 years ago

apple is now selling Sonos in apple stores, so i think there probably will be airplay support eventually in a new model.

knubie commented 8 years ago

@jonbid I don't think so. In order to play anything you need to send two requests to the Sonos, one to queue up the song, and another to play it. Together they add up to 200~300ms, which is better, but still not good enough for video.

If there was some way to skip the queue step, it might work, as that was typically <100ms in my tests.

knubie commented 8 years ago

Actually, on second thought I guess it doesn't really matter how long it takes to queue it up. I'll keep looking into it.

jonbid commented 8 years ago

what ive been doing is using VLCplayer to playback videos and then adjusting the audio sync a few seconds slower to get the video/audio in sync... but its kind of irritating having to do that every time. and playing back videos in a web browser is still out of sync. wish there was a simpler solution.

knubie commented 8 years ago

@jonbid If you're using silverlight to stream video (e.g. netflix) there is a 'hidden' menu you can open to adjust a/v synchronization. But like you said, it's pretty inconvenient.

tzm41 commented 7 years ago

I have been trying to use my Mac connected to speakers via headphone jacks with Sonos in the back of the room as surround speaker, but no luck because of the delay. Any help would be appreciated!

knubie commented 7 years ago

@stef-germany You should open a bounty on https://www.bountysource.com/ I would consider contributing, I'm sure others would as well.

nulloxide commented 7 years ago

no way to fix the 4 sec delay yet?

jonbid commented 7 years ago

sonos announced today that airplay is coming to sonos in 2018, so this will no longer be needed.

axbmcuser commented 7 years ago

Great news!