Skip to content

✨ Add iKAT automated FFmpeg session recording#87

Merged
J-MaFf merged 33 commits intomainfrom
Invoke-FFmpegCapture
Mar 26, 2026
Merged

✨ Add iKAT automated FFmpeg session recording#87
J-MaFf merged 33 commits intomainfrom
Invoke-FFmpegCapture

Conversation

@J-MaFf
Copy link
Copy Markdown
Owner

@J-MaFf J-MaFf commented Mar 26, 2026

What does this PR do?

Adds a complete automated screen recording solution for the iKAT RDS server (KFWS6IKAT01.kikkoman.com). When a target user (e.g., dpuerner) logs on, a Task Scheduler task silently launches FFmpeg via a VBScript launcher, captures their entire desktop session, and saves it as an MPEG-TS file. Recording continues until the user logs off, even if FFmpeg is force-killed by Windows at session end.

New files:

  • Scripts/iKAT/Invoke-FFmpegCapture/Invoke-iKATRecording.ps1 — Core recording script: validates user, checks disk space, auto-detects screen dimensions, launches FFmpeg with zero-latency encoding
  • Scripts/iKAT/Invoke-FFmpegCapture/Start-DinaRecording.ps1 — Runner for KFI\dpuerner, targets C:\Recordings, requires 10 GB free
  • Scripts/iKAT/Invoke-FFmpegCapture/Start-DinaRecording.vbs — VBScript launcher (invoked by Task Scheduler to suppress console window flash)
  • Scripts/iKAT/Invoke-FFmpegCapture/Start-JoeyRecording.ps1 — Test runner for KFI\admin-jmaffiola, requires 1 GB free
  • Scripts/iKAT/Invoke-FFmpegCapture/Start-JoeyRecording.vbs — VBScript launcher for Joey's test task
  • Scripts/iKAT/Invoke-FFmpegCapture/Remove-ExpiredRecordings.ps1 — Daily cleanup: deletes .ts recordings older than a configurable retention period
  • Scripts/iKAT/Invoke-FFmpegCapture/Test-Recording.ps1 — Local test harness
  • Scripts/iKAT/Invoke-FFmpegCapture/plan.md — Architecture and design notes
  • Scripts/iKAT/Invoke-FFmpegCapture/test.md — Testing guide
  • Scripts/iKAT/Invoke-FFmpegCapture/log.md — Implementation diary

Scheduled tasks deployed on server (not in repo):

  • iKAT-Record-Dina — triggers on KFI\dpuerner logon, LogonType Interactive, RunLevel Limited
  • iKAT-Record-Joey-Test — triggers on KFI\admin-jmaffiola logon, same settings
  • iKAT-Cleanup-Recordings — runs daily at 2 AM as SYSTEM

Why are we doing this?

Dina (dpuerner) is experiencing intermittent errors in the iKAT application that have been difficult to reproduce and diagnose. This recording system captures her full desktop session so that the exact sequence of actions leading to an error can be reviewed after the fact. Requested by Nate.


How should this be tested?

  1. Log on to KFWS6IKAT01.kikkoman.com as KFI\admin-jmaffiola
  2. Wait ~5 seconds for the task to trigger (or check Task Scheduler to confirm iKAT-Record-Joey-Test is running)
  3. Perform some activity for 1-2 minutes
  4. Log off
  5. Check C:\Recordings — a .ts file should be present with a size proportional to session length
  6. Copy the .ts file locally and open in VLC — confirm full session is captured with no truncation at the end

Key things to verify:

  • Full screen is captured (taskbar visible, no right-side cropping)
  • Recording ends within ~1 second of logoff (not 5-10 seconds early)
  • File is playable immediately after logoff with no repair needed

Any deployment notes?

Prerequisites on target server:

  • FFmpeg installed at C:\ffmpeg\bin\ffmpeg.exe and on system PATH for all users
  • C:\Recordings directory (will be auto-created by the script if absent)
  • PowerShell 7+ (scripts use pwsh.exe)

Task registration: Tasks must be registered with:

  • LogonType Interactive — required to run in the user's actual desktop session (not Session 0)
  • RunLevel Limited — elevation (RunLevel Highest) blocks gdigrab from accessing the RDS desktop

Output format: MPEG-TS (.ts) — chosen because it writes self-contained 188-byte packets with no trailer required. Files are fully playable even if FFmpeg is force-killed at logoff. VLC opens .ts files natively.

FFmpeg encoding flags:

  • -tune zerolatency — disables libx264 lookahead buffer so each frame is flushed immediately (prevents 5-10s data loss at session end)
  • -g 5 — 1-second keyframe interval at 5fps
  • -flush_packets 1 — OS-level flush after every TS packet
  • -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 — enforces even dimensions without resizing (libx264 requirement)

J-MaFf added 30 commits March 16, 2026 13:15
Adds Start-AppRecording.ps1 and Remove-ExpiredRecordings.ps1 to capture intermittent errors dynamically in RemoteApp sessions while managing necessary storage retention. Also includes their respective Pester testing suites.

Closes tracking items.
Moves registry scripts and their respective Pester tests into the iCat project structure.
Adds WriteFolsom.ps1 and dns_check_temp.ps1 test scripts to the working directory.
Adds a pre-configured runner script to execute the FFmpeg capture targeting Dina's iKAT application. Wraps the parameters using splatting for easy Task Scheduler deployment.
Renames start scripts to better reflect their roles. Start-AppRecording becomes Invoke-iKATRecording (the core logic). The wrapper becomes Start-DinaRecording (the user-specific process runner). Updates Pester tests and plan.md to reflect this terminology restructure.
Changes the TargetUser parameter from 'dina' to the actual username 'dpurner' to ensure the session matches correctly.
Adds test.md outlining local console simulations and Task Scheduler dry-runs necessary to validate the FFmpeg capturing script before launching to production.
Changes the termination logic to send a 'q' command to standard input rather than hard-killing the process via Stop-Process to prevent MKV file closure corruption.
Adds the '-pix_fmt yuv420p' argument to the FFmpeg recording string. Without this, gdigrab defaults to yuv444p which is not supported by default Windows 10/11 media players (Movies & TV, WMP) natively, causing playback failures without VLC.
Wraps the process monitoring loop in a try-finally block. Ensures that if the script is hard-stopped via Ctrl+C or a task scheduler kill signal, the 'q' command is still sent to FFmpeg's stream to perfectly flush and save the current MKV.
Adds Test-Recording.ps1 to facilitate local sandbox testing and updates test.md with the latest behavior around UWP background apps (like Notepad) and Ctrl+C interrupt testing.
Updates documentation to match final script names, standard input closing logic, specific UWP background limitations, and Task Scheduler logic.
Removes the app-process trigger loop in favor of recording immediately on logon. The TargetProcess parameter has been dropped entirely. Virtual desktop dimensions are now auto-detected at runtime via System.Windows.Forms.SystemInformation.VirtualScreen to capture all connected monitors. The try/finally graceful shutdown structure is retained and continues to fire correctly on logoff or Task Scheduler termination.
@J-MaFf J-MaFf added enhancement New feature or request feature labels Mar 26, 2026
@J-MaFf J-MaFf self-assigned this Mar 26, 2026
@J-MaFf J-MaFf added infrastructure documentation Improvements or additions to documentation labels Mar 26, 2026
@J-MaFf
Copy link
Copy Markdown
Owner Author

J-MaFf commented Mar 26, 2026

Did some tests on the server during debugging, everything is working as expected now.

@J-MaFf J-MaFf merged commit 5d7b902 into main Mar 26, 2026
1 check failed
@J-MaFf J-MaFf deleted the Invoke-FFmpegCapture branch March 26, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request feature infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant