Skip to content

[file-diet] Split FfmpegVideoRecorder into focused partial files#9465

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/file-diet-refactor-ffmpegvideorecorder
Draft

[file-diet] Split FfmpegVideoRecorder into focused partial files#9465
Copilot wants to merge 2 commits into
mainfrom
copilot/file-diet-refactor-ffmpegvideorecorder

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

FfmpegVideoRecorder.cs had grown to 723 lines, mixing lifecycle orchestration, ffmpeg process handling, and Windows window-capture interop. This change refactors the type into focused files with partial classes while preserving behavior and internal API usage.

  • File-diet refactor

    • Moved VideoSegment into VideoSegment.cs as a standalone data model.
    • Converted FfmpegVideoRecorder to partial and split concerns across files.
  • Lifecycle/API surface kept in main file

    • FfmpegVideoRecorder.cs now holds core fields/properties and lifecycle orchestration (Start, StopAsync, PruneSegments, ConcatAsync).
    • Main file reduced to <300 lines for easier navigation.
  • Process management extracted

    • Added FfmpegVideoRecorder.ProcessManagement.cs for ffmpeg invocation/output handling and argument construction:
      • RunFfmpegAsync, WaitForExitAsync, TryKill, DetachAndDispose, OnFfmpegOutput, ClearRecentFfmpegOutput, FindFfmpeg, BuildSegmentArguments, BuildDefaultInput
      • Segment parsing/diagnostics methods remain on the same type and are callable from the main partial.
  • Windows capture/interop isolated

    • Added FfmpegVideoRecorder.WindowCapture.cs for DPI-aware window region detection and P/Invoke:
      • TryGetCurrentProcessWindowRegion, TrySetPerMonitorDpiAwareThread, EnumerateCandidateWindows, nested NativeMethods
// Main file
internal sealed partial class FfmpegVideoRecorder { /* lifecycle */ }

// Process/file split
internal sealed partial class FfmpegVideoRecorder
{
    private string BuildDefaultInput() { /* ... */ }
}

// Windows-specific split
internal sealed partial class FfmpegVideoRecorder
{
    private static bool TryGetCurrentProcessWindowRegion(out int x, out int y, out int width, out int height) { /* ... */ }
}

Copilot AI requested review from Copilot and removed request for Copilot June 26, 2026 19:29
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 26, 2026 19:42
Copilot AI changed the title [WIP] Refactor FfmpegVideoRecorder.cs into smaller files [file-diet] Split FfmpegVideoRecorder into focused partial files Jun 26, 2026
Copilot AI requested a review from Evangelink June 26, 2026 19:43
Comment on lines +130 to +131
{
}
Comment on lines +154 to +155
{
}
Comment on lines +40 to +55
foreach (string line in lines)
{
string[] parts = line.Split(',');
if (parts.Length < 3
|| !double.TryParse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out double start)
|| !double.TryParse(parts[2], NumberStyles.Float, CultureInfo.InvariantCulture, out double end))
{
continue;
}

string path = Path.IsPathRooted(parts[0]) ? parts[0] : Path.Combine(directory, parts[0]);
if (File.Exists(path) && new FileInfo(path).Length > 0)
{
segments.Add(new VideoSegment(path, start, end));
}
}
public static readonly IntPtr DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = new(-4);

[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
public static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex);
public static extern int GetSystemMetrics(int nIndex);

[DllImport("user32.dll")]
public static extern IntPtr SetThreadDpiAwarenessContext(IntPtr dpiContext);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
IntPtr previousDpiContext = TrySetPerMonitorDpiAwareThread();
try
{
int screenWidth = NativeMethods.GetSystemMetrics(NativeMethods.SM_CXSCREEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants