Compare commits

..

No commits in common. "18928a23f9aec9eb785104fa11a22716053441ca" and "e18d043b78aae5d54649648545203c38516955aa" have entirely different histories.

19 changed files with 133 additions and 599 deletions

View File

@ -1,21 +0,0 @@
using System.Globalization;
using Avalonia.Data.Converters;
namespace Splitter_UI.Converters;
public sealed class RotationAngleToIconConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
90 => "\uf2f9", // FA7 (fa-rotate-left / fa-arrow-rotate-left / fa-undo)
180 => "\uf2f1", // FA7 (fa-sync-alt)
270 => "\uf2ea", // FA7 (fa-rotate-right / fa-arrow-rotate-right / fa-redo)
_ => null
};
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}

View File

@ -1,13 +0,0 @@
using System.Globalization;
using Avalonia.Data.Converters;
namespace Splitter_UI.Converters;
public sealed class ZeroToBoolConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> (value is int i && i == 0);
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}

View File

@ -2,17 +2,10 @@
namespace Splitter_UI.Models;
public class PreviewData
public sealed class PreviewData
{
public Avalonia.Media.Imaging.Bitmap? Frame { get; }
public IReadOnlyList<Rect> DetectedBoxes { get; }
public Rect? CropRect { get; }
public PreviewData(Avalonia.Media.Imaging.Bitmap? frame, IReadOnlyList<Rect> boxes, Rect? crop)
{
Frame = frame;
DetectedBoxes = boxes;
CropRect = crop;
}
}
public Avalonia.Media.Imaging.Bitmap? Frame { get; init; }
public IReadOnlyList<Rect> FaceBoxes { get; init; } = [];
public IReadOnlyList<Rect> BodyBoxes { get; init; } = [];
public Rect? CropRect { get; init; }
}

View File

@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Media;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Splitter_UI;
@ -32,28 +31,12 @@ internal sealed class Program
services.AddTransient<StatusBarViewModel>();
services.AddTransient<LogPaneViewModel>();
// splitter services
services.AddSingleton<UltraFaceDetector>();
services.AddSingleton<YoloOnnxObjectDetector>();
services.AddSingleton( x => new SingleThreadedDetector<UltraFaceDetector>(x.GetRequiredService<UltraFaceDetector>()) );
services.AddSingleton( x => new SingleThreadedDetector<YoloOnnxObjectDetector>(x.GetRequiredService<YoloOnnxObjectDetector>()));
services.AddSingleton<Func<string, IObjectDetector>>( x => detectorName =>
{
return detectorName switch
{
"face" => x.GetRequiredService<SingleThreadedDetector<UltraFaceDetector>>(),
"body" => x.GetRequiredService<SingleThreadedDetector<YoloOnnxObjectDetector>>(),
_ => new DummyDetector()
};
});
services.AddSingleton<splitter.ILogger, GlobalLogger>();
// Domain services (your pipeline)
services.AddTransient<IFileProbeService, FileProbeService>();
services.AddTransient<IThumbnailService, ThumbnailService>();
services.AddTransient<IFileProbeService, FileProbeService>();
services.AddTransient<IThumbnailService, ThumbnailService>();
services.AddSingleton<IAutoDecisionService, AutoDecisionService>();
services.AddSingleton<IProcessingService, ProcessingService>();
services.AddSingleton<ILogService, LogService>();
services.AddSingleton<IProcessingService, ProcessingService>();
services.AddSingleton<ILogService, LogService>();
services.AddSingleton<IFileJobFactory, FileJobFactory>();

View File

@ -1,43 +0,0 @@
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Media.Imaging;
using OpenCvSharp;
namespace Splitter_UI.Services;
public static class AvaloniaBitmapExtensions
{
public static Mat ToMatContinuous(this Bitmap bmp)
{
var w = bmp.PixelSize.Width;
var h = bmp.PixelSize.Height;
var stride = w * 4;
var size = h * stride;
var buffer = new byte[size];
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
bmp.CopyPixels(
new PixelRect(0, 0, w, h),
handle.AddrOfPinnedObject(),
size,
stride);
return Mat.FromPixelData(h, w, MatType.CV_8UC4, buffer);
}
finally
{
handle.Free();
}
}
public static Mat ToMatBgrContinuous(this Bitmap bmp)
{
using var bgra = bmp.ToMatContinuous();
var bgr = new Mat();
Cv2.CvtColor(bgra, bgr, ColorConversionCodes.BGRA2BGR);
return bgr;
}
}

View File

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenCvSharp;
namespace Splitter_UI.Services;
internal class DummyDetector : IObjectDetector
{
public List<(Rect box, splitter.Point2f center)> DetectAll(Mat frameCont) => [];
public void Dispose() {}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Splitter_UI.Services;
internal class GlobalLogger(ILogService _logService) : ILogger
{
public void ClearProgress(int progressLevel) { }
public void DrawProgress(string name, int progressLine, double progress, TimeSpan eta, double speed) { }
public void Log(string prefix, ConsoleColor color, string msg)
{
_logService.Write($"[{prefix}] {msg}");
}
}

View File

@ -5,5 +5,5 @@ namespace Splitter_UI.Services;
public interface IThumbnailService
{
Task<Bitmap?> CreateThumbnailAsync(string file, VideoInfo probe, TimeSpan? skip = null, int? width = null, int? height = null, int? rotateDegree = null);
Task<Bitmap?> CreateThumbnailAsync(string file, VideoInfo probe);
}

View File

@ -1,23 +0,0 @@
using OpenCvSharp;
namespace Splitter_UI.Services;
public class SingleThreadedDetector<T>(IObjectDetector _detector) : IObjectDetector
where T : IObjectDetector
{
private Lock _lock = new();
public List<(Rect box, splitter.Point2f center)> DetectAll(Mat frameCont)
{
lock (_lock)
{
return _detector.DetectAll(frameCont);
}
}
public void Dispose()
{
if ( _detector is IDisposable d )
d.Dispose();
}
}

View File

@ -7,55 +7,41 @@ namespace Splitter_UI.Services;
public sealed class ThumbnailService : IThumbnailService
{
private const int _thumbWidth = 160;
private const int _thumbHeight = 90;
private readonly int _thumbWidth = 160;
private readonly int _thumbHeight = 90;
private readonly byte [] _bgrBuffer = new byte[_thumbWidth * _thumbHeight * 3];
private readonly byte [] _bgraBuffer = new byte[_thumbWidth * _thumbHeight * 4];
// Reusable buffer for BGR24 → 3 bytes per pixel
private readonly byte[] _bgrBuffer;
private readonly byte[] _bgraBuffer;
public async Task<Bitmap?> CreateThumbnailAsync(
string file,
VideoInfo probe,
TimeSpan? skip = null,
int? width = null,
int? height = null,
int? rotateDegree = null)
public ThumbnailService()
{
width ??= _thumbWidth;
height ??= _thumbHeight;
skip ??= TimeSpan.Zero;
// buffer for BGR24 → 3 bytes per pixel
var canUseStaticBuffers =
width.Value == _thumbWidth &&
height.Value == _thumbHeight;
var bgrBuffer = canUseStaticBuffers ? _bgrBuffer : new byte[width.Value * height.Value * 3];
var bgraBuffer = canUseStaticBuffers ? _bgraBuffer : new byte[width.Value * height.Value * 4];
_bgrBuffer = new byte[_thumbWidth * _thumbHeight * 3];
_bgraBuffer = new byte[_thumbWidth * _thumbHeight * 4];
}
public async Task<Bitmap?> CreateThumbnailAsync(string file, VideoInfo probe)
{
// Decode a single frame using ffmpeg → raw BGR24 into _bgrBuffer
bool ok = await DecodeFrameAsync(bgrBuffer, file, skip.Value, width.Value, height.Value, rotateDegree);
bool ok = await DecodeFrameAsync(file);
if (!ok)
return null;
// Convert BGR24 → BGRA32
ConvertBgrToBgra(bgrBuffer, bgraBuffer, width.Value, height.Value);
ConvertBgrToBgra(_bgrBuffer, _bgraBuffer, _thumbWidth, _thumbHeight);
// Create Avalonia Bitmap
return CreateBitmap(bgraBuffer, width.Value, height.Value, rotateDegree == 90 || rotateDegree == 270);
return CreateBitmap(_bgraBuffer, _thumbWidth, _thumbHeight);
}
private static async Task<bool> DecodeFrameAsync(byte [] bgrBuffer, string file, TimeSpan skip, int width, int height, int? rotateDegree)
private async Task<bool> DecodeFrameAsync(string file)
{
var rotationStr = TrackingSplitter.GetRorationArg(rotateDegree);
// ffmpeg command: decode one frame, resize, output raw BGR24
var args =
$"-ss {skip.TotalSeconds} -t 0.1 -i \"{file}\" " +
$"-ss 0 -t 0.1 -i \"{file}\" " +
"-an -sn " +
$"-vf \"scale={width}:{height}:force_original_aspect_ratio=decrease," +
$"pad={width}:{height}:(ow-iw)/2:(oh-ih)/2,format=bgr24{rotationStr}\" " +
$"-vf \"scale={_thumbWidth}:{_thumbHeight}:force_original_aspect_ratio=decrease," +
$"pad={_thumbWidth}:{_thumbHeight}:(ow-iw)/2:(oh-ih)/2,format=bgr24\" " +
"-f rawvideo -";
var psi = new ProcessStartInfo
@ -71,14 +57,14 @@ public sealed class ThumbnailService : IThumbnailService
var p = new Process { StartInfo = psi };
p.Start();
int needed = bgrBuffer.Length;
int needed = _bgrBuffer.Length;
int read = 0;
using var stdout = p.StandardOutput.BaseStream;
while (read < needed)
{
int r = await stdout.ReadAsync(bgrBuffer, read, needed - read);
int r = await stdout.ReadAsync(_bgrBuffer, read, needed - read);
if (r == 0)
{
TryKill(p);
@ -115,13 +101,8 @@ public sealed class ThumbnailService : IThumbnailService
}
}
private static unsafe Bitmap CreateBitmap(byte[] bgra, int width, int height, bool isRotated)
private static unsafe Bitmap CreateBitmap(byte[] bgra, int width, int height)
{
if (isRotated)
{
(height, width) = (width, height);
}
int stride = width * 4;
fixed (byte* p = bgra)

View File

@ -2,9 +2,7 @@
using System.Collections.Specialized;
using System.ComponentModel;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace Splitter_UI.ViewModels;
@ -12,8 +10,7 @@ public partial class JobViewModel : ObservableObject
{
public SingleJob Job { get; }
public VideoInfo? Probe { get; set; }
[ObservableProperty]
private PreviewData? _preview = new(null, [], null);
public PreviewData? Preview { get; set; }
public ProgressInfo? Progress { get; set; }
[ObservableProperty]
@ -22,33 +19,11 @@ public partial class JobViewModel : ObservableObject
[ObservableProperty]
private string _suggestedAction = "";
// This updates continuously
[ObservableProperty]
private double _sliderLiveValue;
// This updates only on release
[ObservableProperty]
private double _positionSeconds;
public double DurationSeconds => Probe?.Duration ?? 0;
public IRelayCommand StepForwardCommand { get; }
public IRelayCommand StepBackwardCommand { get; }
private readonly IThumbnailService _thumbnails;
private readonly IFileProbeService _fileProbe;
private readonly DispatcherTimer _debounceTimer;
private readonly Func<string, IObjectDetector> _detectorFactory;
private readonly ILogger _log;
private readonly IThumbnailService _thumbnails;
private readonly IFileProbeService _fileProbe;
public string FileName => Path.GetFileName(Job.InputFile);
public string TextDesc => Probe != null
? $"{Probe.Width}x{Probe.Height}, {TimeSpan.FromSeconds(Probe.Duration).ToString(@"hh\:mm\:ss")}), FPS: {Probe.Fps:F2}, Bitrate: {Probe.Bitrate/1024/1024:F2} MB/s"
: "";
public override string ToString() => $"{FileName} - {TextDesc}";
public ObservableCollection<ParameterEntry> ParametersList { get; }
= new();
@ -113,17 +88,14 @@ public partial class JobViewModel : ObservableObject
{
Job.Rotate = value;
OnPropertyChanged();
Task.Run(CreatePreview);
}
}
public JobViewModel(SingleJob job, IThumbnailService thumbnails, IFileProbeService fileProbe, Func<string, IObjectDetector> detectorFactory, ILogger log)
public JobViewModel(SingleJob job, IThumbnailService thumbnails, IFileProbeService fileProbe)
{
Job = job;
_thumbnails = thumbnails;
_fileProbe = fileProbe;
_detectorFactory = detectorFactory;
_log = log;
Job = job;
_thumbnails = thumbnails;
_fileProbe = fileProbe;
ParametersList.Add(new ParameterEntry("DropoutToleranceFrames", ""));
ParametersList.Add(new ParameterEntry("EmaFactor", ""));
@ -141,14 +113,6 @@ public partial class JobViewModel : ObservableObject
ParametersList.CollectionChanged += OnParametersCollectionChanged;
StepForwardCommand = new RelayCommand(StepForward);
StepBackwardCommand = new RelayCommand(StepBackward);
_debounceTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
_debounceTimer.Tick += DebounceTimerTick;
_ = Task.Run( LoadThumbnailAsync );
}
@ -156,34 +120,8 @@ public partial class JobViewModel : ObservableObject
private async Task LoadThumbnailAsync()
{
Probe = await _fileProbe.ProbeAsync(Job);
Thumbnail = await _thumbnails.CreateThumbnailAsync(Job.InputFile, Probe, rotateDegree: Job.Rotate);
Thumbnail = await _thumbnails.CreateThumbnailAsync(Job.InputFile, Probe);
SuggestedAction = Probe.Rotation == 0 ? "crop" : "rotate";
await CreatePreview();
}
private async Task CreatePreview()
{
if ( Probe == null)
return;
try
{
var frame = await _thumbnails.CreateThumbnailAsync(Job.InputFile, Probe, TimeSpan.FromSeconds(PositionSeconds), Probe.Width, Probe.Height, Job.Rotate);
if ( frame == null )
return;
Preview = new PreviewData(frame, [], null);
var detector = _detectorFactory(Job.Detect ?? "");
var detections = detector.DetectAll(frame.ToMatContinuous());
var boxes = detections.Select(x => new Avalonia.Rect(x.box.X, x.box.Y, x.box.Width, x.box.Height)).ToList();
Preview = new PreviewData(frame, boxes, null);
}
catch (Exception ex)
{
_log.LogError($"Error creating preview for {FileName}: {ex.Message}");
}
}
private void OnParameterChanged(object? sender, PropertyChangedEventArgs e)
@ -215,45 +153,4 @@ public partial class JobViewModel : ObservableObject
}
}
private void StepForward()
{
if (DurationSeconds <= 0)
return;
var step = DurationSeconds * 0.1; // 10% of total duration
SliderLiveValue = Math.Min(DurationSeconds, SliderLiveValue + step);
// trigger seek in your playback pipeline here
}
private void StepBackward()
{
if (DurationSeconds <= 0)
return;
var step = DurationSeconds * 0.1; // 10% of total duration
SliderLiveValue = Math.Max(0, SliderLiveValue - step);
// trigger seek in your playback pipeline here
}
partial void OnSliderLiveValueChanged(double value)
{
// Restart debounce timer on every slider update
_debounceTimer.Stop();
_debounceTimer.Start();
}
private void DebounceTimerTick(object? sender, EventArgs e)
{
_debounceTimer.Stop();
// Commit the final value
PositionSeconds = SliderLiveValue;
}
partial void OnPositionSecondsChanged(double value)
{
Task.Run(CreatePreview);
}
}

View File

@ -1,5 +1,4 @@
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Splitter_UI.ViewModels;
@ -8,23 +7,7 @@ public partial class PreviewPaneViewModel : ObservableObject
[ObservableProperty]
private JobViewModel? _selected;
public PreviewData? Preview => Selected?.Preview;
partial void OnSelectedChanged(JobViewModel? oldValue, JobViewModel? newValue)
public PreviewPaneViewModel()
{
if (oldValue != null)
oldValue.PropertyChanged -= SelectedPropertyChanged;
if (newValue != null)
newValue.PropertyChanged += SelectedPropertyChanged;
OnPropertyChanged(nameof(Preview));
}
private void SelectedPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(JobViewModel.Preview))
OnPropertyChanged(nameof(Preview));
}
}

View File

@ -3,15 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Splitter_UI.ViewModels"
xmlns:views="clr-namespace:Splitter_UI.Views"
xmlns:conv="clr-namespace:Splitter_UI.Converters"
xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia"
x:Class="Splitter_UI.Views.FileListView"
x:DataType="vm:FileListViewModel">
<UserControl.Resources>
<conv:ZeroToBoolConverter x:Key="ZeroToBoolConverter"/>
<conv:RotationAngleToIconConverter x:Key="RotationAngleToIconConverter"/>
</UserControl.Resources>
<UserControl.Styles>
<Style Selector="views|FileListView Border#DropZone">
<Setter Property="BorderBrush" Value="Transparent"/>
@ -25,91 +20,75 @@
</UserControl.Styles>
<Border x:Name="DropZone"
Background="#1E1E1E"
Padding="10"
DragDrop.AllowDrop="True"
DragDrop.Drop="OnDrop"
DragDrop.DragOver="OnDragOver"
DragDrop.DragEnter="OnDragEnter"
DragDrop.DragLeave="OnDragLeave">
Background="#1E1E1E"
Padding="10"
DragDrop.AllowDrop="True"
DragDrop.Drop="OnDrop"
DragDrop.DragOver="OnDragOver"
DragDrop.DragEnter="OnDragEnter"
DragDrop.DragLeave="OnDragLeave">
<Grid>
<!-- Empty message -->
<TextBlock Text="Drag files here"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Foreground="#666"
IsVisible="{Binding Files.Count, Converter={StaticResource ZeroToBoolConverter}}"/>
<ScrollViewer>
<ListBox ItemsSource="{Binding Files}"
SelectedItems="{Binding SelectedFiles}"
SelectedItem="{Binding Selected}"
SelectionMode="Multiple"
BorderThickness="0"
Background="Transparent">
<!-- File list -->
<ScrollViewer>
<ListBox ItemsSource="{Binding Files}"
SelectedItems="{Binding SelectedFiles}"
SelectedItem="{Binding Selected}"
SelectionMode="Multiple"
BorderThickness="0"
Background="Transparent">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Styles>
<Style Selector="ListBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="#9A9A9A"/>
<ListBox.Styles>
<Style Selector="ListBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="#9A9A9A"/>
</Style>
</ListBox.Styles>
</ListBox.Styles>
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:JobViewModel">
<Border x:Name="ItemRoot"
Margin="0"
Padding="0"
CornerRadius="4"
Background="#2A2A2A">
<StackPanel MinWidth="160" MaxWidth="160">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:JobViewModel">
<Border x:Name="ItemRoot"
Margin="0"
Padding="0"
CornerRadius="4"
Background="#2A2A2A">
<StackPanel MinWidth="160" MaxWidth="160">
<Border Width="160" Height="90" ClipToBounds="True">
<Grid>
<Image Source="{Binding Thumbnail}"
Stretch="UniformToFill"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Border Width="160" Height="90" ClipToBounds="True">
<Grid>
<Image Source="{Binding Thumbnail}"
Stretch="UniformToFill"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<TextBlock FontFamily="{StaticResource FontAwesome}"
Text="{Binding SuggestedAction, Converter={StaticResource ActionToIconConverter}}"
FontSize="12"
HorizontalAlignment="Right"
Foreground="LimeGreen"/>
</Grid>
</Border>
<TextBlock FontFamily="{StaticResource FontAwesome}"
Text="{Binding SuggestedAction, Converter={StaticResource ActionToIconConverter}}"
FontSize="12"
HorizontalAlignment="Right"
Foreground="LimeGreen"/>
<TextBlock FontFamily="{StaticResource FontAwesome}"
Text="{Binding Rotate, Converter={StaticResource RotationAngleToIconConverter}}"
FontSize="12"
HorizontalAlignment="Left"
Foreground="LimeGreen"/>
</Grid>
</Border>
<TextBlock Text="{Binding FileName}"
TextWrapping="Wrap"
Margin="0,6,0,0"
FontSize="10"/>
<TextBlock Text="{Binding FileName}"
TextWrapping="Wrap"
Margin="0,6,0,0"
FontSize="10"/>
<ProgressBar MinWidth="160"
MaxWidth="160"
Height="10"
Margin="0,4,0,0"
Value="{Binding Progress.Percent}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
<ProgressBar MinWidth="160"
MaxWidth="160"
Height="10"
Margin="0,4,0,0"
Value="{Binding Progress.Percent}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Border>
</UserControl>

View File

@ -12,9 +12,8 @@ x:DataType="vm:InspectorPaneViewModel">
<TextBlock Text="Parameters" FontSize="10" Margin="0,0,0,10" FontWeight="Bold"/>
<!-- InputFile -->
<StackPanel Orientation="Vertical" Spacing="8">
<TextBlock Text="{Binding Selected.FileName}" Width="360" Margin="0,0,0,5" FontStyle="Italic"/>
<TextBlock Text="{Binding Selected.TextDesc}" Width="360" FontSize="10" Margin="0,0,0,10" FontWeight="Bold" Foreground="#676767"/>
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="{Binding Selected.FileName}" Width="360" Margin="0,0,0,10" FontStyle="Italic"/>
</StackPanel>
<!-- Rotate -->
@ -114,22 +113,13 @@ x:DataType="vm:InspectorPaneViewModel">
<DataGrid ItemsSource="{Binding Selected.ParametersList}"
AutoGenerateColumns="False"
HeadersVisibility="Column"
Margin="0,0,20,0"
Height="160">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Key" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}"
FontSize="10"
TextTrimming="CharacterEllipsis"
ToolTip.Tip="{Binding Key}">
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Key"
Binding="{Binding Key}"
Width="*"/>
<DataGridTemplateColumn Header="Value" Width="2*">
<DataGridTemplateColumn.CellTemplate>

View File

@ -6,7 +6,7 @@
x:Class="Splitter_UI.Views.MainWindow"
x:DataType="vm:MainViewModel"
Width="1400"
Height="950"
Height="900"
Title="Splitter UI">
<DockPanel>
@ -20,7 +20,7 @@
DataContext="{Binding LogPane}" />
<!-- Main Content -->
<Grid ColumnDefinitions="2*,3*,430">
<Grid ColumnDefinitions="2*,3*,2*">
<!-- File List -->
<views:FileListView Grid.Column="0"

View File

@ -1,100 +0,0 @@
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Threading;
namespace Splitter_UI.Views;
public sealed class PreviewCanvas : Control
{
public static readonly StyledProperty<PreviewData?> PreviewProperty =
AvaloniaProperty.Register<PreviewCanvas, PreviewData?>(nameof(Preview));
public PreviewData? Preview
{
get => GetValue(PreviewProperty);
set => SetValue(PreviewProperty, value);
}
static PreviewCanvas()
{
PreviewProperty.Changed.AddClassHandler<PreviewCanvas>(
(canvas, args) =>
canvas.OnPreviewChanged(args.OldValue as PreviewData,
args.NewValue as PreviewData));
}
private void OnPreviewChanged(PreviewData? oldValue, PreviewData? newValue)
{
if (oldValue is INotifyPropertyChanged oldNotify)
oldNotify.PropertyChanged -= PreviewPropertyChanged;
if (newValue is INotifyPropertyChanged newNotify)
newNotify.PropertyChanged += PreviewPropertyChanged;
// Always marshal to UI thread
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Render);
}
private void PreviewPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(PreviewData.Frame) ||
e.PropertyName == nameof(PreviewData.DetectedBoxes) ||
e.PropertyName == nameof(PreviewData.CropRect))
{
// Always marshal to UI thread
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Render);
}
}
protected override Size MeasureOverride(Size availableSize) => availableSize;
protected override Size ArrangeOverride(Size finalSize) => finalSize;
public override void Render(DrawingContext context)
{
var preview = Preview;
if (preview?.Frame is null)
return;
var frame = preview.Frame;
var rawW = frame.PixelSize.Width;
var rawH = frame.PixelSize.Height;
var dispW = Bounds.Width;
var dispH = Bounds.Height;
if (dispW <= 0 || dispH <= 0)
return;
var scale = Math.Min(dispW / rawW, dispH / rawH);
var scaledW = rawW * scale;
var scaledH = rawH * scale;
var offsetX = (dispW - scaledW) / 2;
var offsetY = (dispH - scaledH) / 2;
// draw frame
context.DrawImage(frame,
new Rect(0, 0, rawW, rawH),
new Rect(offsetX, offsetY, scaledW, scaledH));
// draw overlays
if (preview.DetectedBoxes is { Count: > 0 })
{
var pen = new Pen(Brushes.Lime, 2);
foreach (var r in preview.DetectedBoxes )
{
var rr = new Rect(
offsetX + r.X * scale,
offsetY + r.Y * scale,
r.Width * scale,
r.Height * scale);
context.DrawRectangle(null, pen, rr);
}
}
}
}

View File

@ -1,57 +1,24 @@
<UserControl
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Splitter_UI.ViewModels"
xmlns:local="clr-namespace:Splitter_UI.Views"
x:Class="Splitter_UI.Views.PreviewPane"
xmlns:vm="clr-namespace:Splitter_UI.ViewModels"
x:DataType="vm:PreviewPaneViewModel">
<Border Background="#202020" Padding="10">
<Grid RowDefinitions="*,Auto">
<local:PreviewCanvas
Grid.Row="0"
Preview="{Binding Preview}" />
<Grid Grid.Row="1"
ColumnDefinitions="Auto,*,Auto"
Margin="0,10,0,0">
<Button Grid.Column="0"
HorizontalAlignment="Left"
Width="24" Height="24"
Padding="0"
Margin="0,0,5,0"
Command="{Binding Selected.StepBackwardCommand}">
<TextBlock FontFamily="{StaticResource FontAwesome}"
Text="&#xf048;"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button>
<Slider Grid.Column="1"
Minimum="0"
Maximum="{Binding Selected.DurationSeconds}"
Value="{Binding Selected.SliderLiveValue, Mode=TwoWay}"
Margin="5,0,5,0" />
<Button Grid.Column="2"
HorizontalAlignment="Right"
Width="24" Height="24"
Padding="0"
Margin="5,0,0,0"
Command="{Binding Selected.StepForwardCommand}">
<TextBlock FontFamily="{StaticResource FontAwesome}"
Text="&#xf051;"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button>
</Grid>
<Grid>
<Image Source="{Binding Selected.Preview.Frame}" Stretch="Uniform"/>
<!-- Optional overlays -->
<ItemsControl ItemsSource="{Binding Selected.Preview.FaceBoxes}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Lime" BorderThickness="2"
Width="{Binding Width}" Height="{Binding Height}"
Canvas.Left="{Binding X}" Canvas.Top="{Binding Y}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>
</UserControl>

View File

@ -1,8 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.VisualTree;
namespace Splitter_UI.Views;
@ -12,5 +8,4 @@ public partial class PreviewPane : UserControl
{
InitializeComponent();
}
}

View File

@ -170,7 +170,16 @@ public class TrackingSplitter : LoggingBase, ISegmentProcessor, IDisposable
var ss = start .ToString("0.###", CultureInfo.InvariantCulture);
var t = length.ToString("0.###", CultureInfo.InvariantCulture);
var rotateStr = GetRorationArg(rotate);
var rotateStr = "";
if (rotate != null)
{
switch (rotate.Value)
{
case 90: rotateStr = ",transpose=1"; break;
case 180: rotateStr = ",transpose=PI"; break;
case 270: rotateStr = ",transpose=2"; break;
}
}
var args =
$"-i \"{inputFile}\" -ss {ss} -t {t} " +
@ -208,22 +217,6 @@ public class TrackingSplitter : LoggingBase, ISegmentProcessor, IDisposable
return p;
}
public static string GetRorationArg(int? rotate)
{
var rotateStr = "";
if (rotate != null)
{
switch (rotate.Value)
{
case 90: rotateStr = ",transpose=1"; break;
case 180: rotateStr = ",transpose=PI"; break;
case 270: rotateStr = ",transpose=2"; break;
}
}
return rotateStr;
}
private Process StartFfmpegEncode(
string inputFile,
string outputFile,