# Align two instances of OBS



## kevinmclane (May 15, 2019)

Hey,

I'm not exactly sure the right way to define this.  In FMLE it is called streamsynchronization in Wirecast it is called keyframe align.  I run two redundant computer encoders taking a live feed from a splitter to respective usb3 video capture cards.  I need a way for the two encoders to align somehow using some kind of NTP for UTC reference.  In my case the video is being streamed rtmp to dual wowza servers and transcoded to hls and then joined at akamai in a master playlist.  If this type of setting is not turned on in FMLE or wirecast when the primary encoder connection is broken the stream will stall out and you will be able to grab the backup upon a player refresh.  Without the setting on if you start the two encoders at the same time you will get a seemless failover 1 time.  With this type of setting turned on; the streamsynchronization for FMLE or keyframe align for wirecast you will get seemless failover back and forth no matter when you start or stop the encoders as long as there is enough buffer in the encode of the playlist.  Does anyone know what exactly is going on under the hood and the right questions to ask to begin trying to build such a plug-in for OBS?


----------



## pkv (May 16, 2019)

that's a feature i could work on; from reading this (https://azure.microsoft.com/en-us/blog/azure-media-services-rtmp-support-and-live-encoders/ ) it seems it' just requires the timestamps (not the timecodes) to be set to UTC. I'll need some more info though on how this works in your current setup to better understand. Ping me on obs discord (@pkv)


----------



## pkv (May 17, 2019)

i checked closely the rtmp code; it relies on librtmp with tweaks from Jim (the lead dev). It sets the initial timestamp as UTC epoch (edit: though it's presumably ntp epoch and not linux epoch, which shouldn't matter).
So it's already set as it should be. It will use the time provided by the OS. Just set the clock on the two machines to sync with same ntp server and that should be it. On windows 10 you would go to Settings > region > Additional date, time & regional settings > set time and date > internet time > change settings
Test and report but it should work provided you've synced your machines to same ntp server


----------



## kevinmclane (May 20, 2019)

Thanks for the update.  I will test this week and get back to you.


----------



## kevinmclane (May 3, 2020)

Coming back to this with some more info.  I reached out to telestream support asking what their keyframe align actually does.  Does this additional info help to clarify my question?  Maybe there are a list of settings I can type into the x264 options field that would accomplish this?
Support ticket highlights:

"Hi,
I am interested in what the keyframe align technically does to the stream.  I see the difference in the .ts segments in the browser traffic.  (Wirecast rtmp>wowza hls packetizing).  With it off the numbering starts at media_1.ts.  But with it on the number starts at a very high number.  What is happening to the stream?"

"When Keyframe aligned is checked, it facilitates adaptive bitrate streaming by ensuring that keyframes from multiple streams are in sync, along with the keyframes timestamp, DTS and PTS values.
But this is true only if those other streams also have the option turned on and have the same keyframe interval.
To accomplish this, Wirecast disables scene detection and manually inserts the keyframe at the exact keyframe interval specified. When Keyframe Aligned is enabled, absolute timestamp is also enabled."


----------



## kevinmclane (Sep 3, 2020)

Hi,

I am coming back to this thread with some feedback from Wowza support.  The wowza feature I am trying to feed data to is called  *cupertinoCalculateChunkIDBasedOnTimecode*









						Configure Apple HLS packets for HTTP streaming
					

Configure the CupertinoStreaming segmenter in Wowza Streaming Engine software to split streams into segments for playback on Apple HLS compatible clients.




					www.wowza.com
				




"The key to making it work is absolute timecodes that are aligned to some epoch. Wirecast and FMLE enable this with their alignment and synchronization settings."

Implementing this feature or a plugin would be greatly appreciated.


----------



## wowza_roger (Jan 22, 2021)

Hi,  Kevin has reached out to Wowza Support and the feature that is required is the Absolute Timecodes that is required so that stream timecodes between separate encoders and streams is aligned.


----------



## dodgepong (Jan 22, 2021)

wowza_roger said:


> Hi,  Kevin has reached out to Wowza Support and the feature that is required is the Absolute Timecodes that is required so that stream timecodes between separate encoders and streams is aligned.


Hi Roger, thanks for your comment.

By "Absolute Timecodes" do you mean NTP-synced timestamps? For example, if MISP timestamps were inserted into h264 SEI, would that accomplish this?


----------



## wowza_roger (Jan 25, 2021)

Hi,

It's the actual RTMP timestamp (or extended timestamp) that we are referring to.  It is either synchronised to NTP or some other epoch.  The idea is that it's synchronised between encoders and across encoder restarts so the timecode is alway monotonic.

In Wirecast, it's enabled with the Keyframe Aligned option and in fmle, it was enabled with the streamsynchronization option.  fmle also had an extra option to set the epoch that the timecodes are synchronised on.


----------



## dodgepong (Jan 25, 2021)

So Wowza reads that data from the transport protocol rather than the video stream. Is there a spec we can follow to ensure we implement it the same way as FMLE/Wirecast, if we were to implement it? Or is it just "run Wireshark on FMLE and copy what they do"?


----------

