SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
712 stars 100 forks source link

Stream synchronization issue #447

Closed zhishiheng closed 5 months ago

zhishiheng commented 6 months ago

How to play a stream, with four playback interfaces and synchronized playback interfaces. I created four players to play the same stream. At the beginning, the screen was basically synchronized, but over time, it could cause the screen to be out of sync. One of the playback will still get stuck and need to be replayed before it can be played again

Config = new Config();
Config.Video.BackgroundColor = Colors.DarkGray;
Config.Audio.Enabled = false;
Config.Decoder.MaxVideoFrames = 2; 
Config.Demuxer.FormatOpt["fflags"] = "+nobuffer+discardcorrupt"; 
Config.Player.MaxLatency = TimeSpan.FromMilliseconds(500).Ticks;
Config.Demuxer.BufferDuration = TimeSpan.FromSeconds(5).Ticks;

Config2 = new Config();
Config2.Video.BackgroundColor = Colors.DarkGray;
Config2.Audio.Enabled = false;
Config2.Decoder.MaxVideoFrames = 2;
Config2.Demuxer.FormatOpt["fflags"] = "+nobuffer+discardcorrupt";
Config2.Player.MaxLatency = TimeSpan.FromMilliseconds(500).Ticks;
Config2.Demuxer.BufferDuration = TimeSpan.FromSeconds(5).Ticks;

Config3 = new Config();
Config3.Video.BackgroundColor = Colors.DarkGray;
Config3.Audio.Enabled = false;
Config3.Decoder.MaxVideoFrames = 2;
Config3.Demuxer.FormatOpt["fflags"] = "+nobuffer+discardcorrupt";
Config3.Player.MaxLatency = TimeSpan.FromMilliseconds(500).Ticks;
Config3.Demuxer.BufferDuration = TimeSpan.FromSeconds(5).Ticks;

Config4 = new Config();
Config4.Video.BackgroundColor = Colors.DarkGray;
Config4.Audio.Enabled = false;
Config4.Decoder.MaxVideoFrames = 2;
Config4.Demuxer.FormatOpt["fflags"] = "+nobuffer+discardcorrupt";
Config4.Player.MaxLatency = TimeSpan.FromMilliseconds(500).Ticks;
Config4.Demuxer.BufferDuration = TimeSpan.FromSeconds(5).Ticks;

Player = new Player(Config);
Player2= new Player(Config2);
Player3= new Player(Config3);
Player4= new Player(Config4);

Player.Commands.Open.Execute(txt.Text.ToString().Trim());
Player2.Commands.Open.Execute(txt.Text.ToString().Trim());
Player3.Commands.Open.Execute(txt.Text.ToString().Trim());
Player4.Commands.Open.Execute(txt.Text.ToString().Trim());
zhishiheng commented 6 months ago

Is there any good way to solve this problem?

zhishiheng commented 6 months ago

this is the log [Uploading log.txt…]()

SuRGeoNix commented 6 months ago

@zhishiheng Generally speaking is not possible to sync two live feeds (eg. the same exact feed) and have 100% sync accuracy. That's because of the timestamps, it could be possible if their timestamps were based on the actual world time. But currently Flyleaf does not support to sync two different inputs like that. The best way it would be with MaxLatency but if you talk for the same input/stream why do you open it twice and don't just use the replica player?

(Can't see the log but in this case it wouldn't be really helpful)

t3therdev commented 6 months ago

@SuRGeoNix what about syncing the players to an external time reference? I believe ffmpeg has some support for this using ntp timestamps in the rtc sender reports for rtsp . it could be useful for a few different situations and use cases.

SuRGeoNix commented 6 months ago

@t3therdev I've already mention "That's because of the timestamps, it could be possible if their timestamps were based on the actual world time. But currently Flyleaf does not support to sync two different inputs like that."

There is indeed an option in FFmpeg which is "use_wallclock_as_timestamps=1". Never test it though, not sure if it would work as it supposed to (how it could identify the send and time -not the recv- accurately so it can sync different demuxers/streams)

zhishiheng commented 6 months ago

how to use replica player?

SuRGeoNix commented 6 months ago

how to use replica player?

Check the samples