mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:36:30 +00:00
fix ai detection bugs #1
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace Azaion.Annotator.Extensions;
|
||||
|
||||
public static class RectangleFExtensions
|
||||
{
|
||||
public static double Area(this RectangleF rectangle) => rectangle.Width * rectangle.Height;
|
||||
}
|
||||
@@ -36,13 +36,13 @@ public class VLCFrameExtractor(LibVLC libVLC)
|
||||
public async IAsyncEnumerable<(TimeSpan Time, Stream Stream)> ExtractFrames(string mediaPath,
|
||||
[EnumeratorCancellation] CancellationToken manualCancellationToken = default)
|
||||
{
|
||||
var videoFinishedCancellationToken = new CancellationTokenSource();
|
||||
var videoFinishedCancellationSource = new CancellationTokenSource();
|
||||
|
||||
_mediaPlayer = new MediaPlayer(libVLC);
|
||||
_mediaPlayer.Stopped += (s, e) => videoFinishedCancellationToken.CancelAfter(1);
|
||||
_mediaPlayer.Stopped += (s, e) => videoFinishedCancellationSource.CancelAfter(1);
|
||||
|
||||
using var media = new Media(libVLC, mediaPath);
|
||||
await media.Parse(cancellationToken: videoFinishedCancellationToken.Token);
|
||||
await media.Parse(cancellationToken: videoFinishedCancellationSource.Token);
|
||||
var videoTrack = media.Tracks.FirstOrDefault(x => x.Data.Video.Width != 0);
|
||||
_width = videoTrack.Data.Video.Width;
|
||||
_height = videoTrack.Data.Video.Height;
|
||||
@@ -58,9 +58,9 @@ public class VLCFrameExtractor(LibVLC libVLC)
|
||||
_mediaPlayer.Play(media);
|
||||
_frameCounter = 0;
|
||||
var surface = SKSurface.Create(new SKImageInfo((int) _width, (int) _height));
|
||||
var token = videoFinishedCancellationToken.Token;
|
||||
var videoFinishedCT = videoFinishedCancellationSource.Token;
|
||||
|
||||
while (!(FramesQueue.IsEmpty && token.IsCancellationRequested) && !manualCancellationToken.IsCancellationRequested)
|
||||
while ( !(FramesQueue.IsEmpty && videoFinishedCT.IsCancellationRequested || manualCancellationToken.IsCancellationRequested))
|
||||
{
|
||||
if (FramesQueue.TryDequeue(out var frameInfo))
|
||||
{
|
||||
@@ -80,9 +80,10 @@ public class VLCFrameExtractor(LibVLC libVLC)
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), token);
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), videoFinishedCT);
|
||||
}
|
||||
}
|
||||
FramesQueue.Clear(); //clear queue in case of manual stop
|
||||
_mediaPlayer.Stop();
|
||||
_mediaPlayer.Dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user