Skip to content

Instantly share code, notes, and snippets.

@ahorn42
Last active August 31, 2023 07:14
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahorn42/505cae6edcd9657ed6f02ee7508a0995 to your computer and use it in GitHub Desktop.
Save ahorn42/505cae6edcd9657ed6f02ee7508a0995 to your computer and use it in GitHub Desktop.
A small powershell script to allow to record and play back a part of your screen with VLC to allow partial screen sharing in communication tools like Teams.
function Share-PartialScreen {
[CmdletBinding(DefaultParameterSetName='Preset')]
Param(
[Parameter(Mandatory = $false)]
[string] $preset,
[Parameter(Mandatory = $false)]
[int] $Width = 1920,
[Parameter(Mandatory = $false)]
[int] $Height = 1080
)
switch ($preset) {
"720p" {
$Width = 1280
$Height = 720
}
"1080p" {
$Width = 1920
$Height = 1080
}
}
$id = Start-Process -FilePath "C:\Program Files\VideoLAN\VLC\vlc.exe" -ArgumentList "screen:// --screen-fps=30 --live-caching=300 --screen-width=$Width --screen-height=$Height --no-embedded-video --no-video-deco --qt-start-minimized" -PassThru
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
[reflection.assembly]::LoadWithPartialName( "System.Drawing")
$pen = New-Object Drawing.Pen red
$brushRed = New-Object Drawing.SolidBrush red
$brushWhite = New-Object Drawing.SolidBrush white
$font = New-Object Drawing.Font "Arial", 14
$form = New-Object Windows.Forms.Form
$form.TransparencyKey = $form.BackColor
$form.WindowState = 'Maximized'
$form.FormBorderStyle = 'None'
$form.TopMost = $true
$formGraphics = $form.createGraphics()
$form.add_paint(
{
$formGraphics.DrawRectangle($pen, 0, 0, $Width + 1, $Height + 1)
$formGraphics.FillRectangle($brushRed, $Width + 1, 0, 60, 30)
$formGraphics.DrawString("close", $font, $brushWhite, $Width + 5, 3)
}
)
$form.Add_Click({$form.Close()})
$form.ShowDialog() # display the dialog
Stop-Process $id
}
@szambetti
Copy link

U da real MVP - (Microsoft valuable partner :) ) for creating this - saves my life on teams widescreen

@ByPS128
Copy link

ByPS128 commented Mar 25, 2022

I also appreciate this script. I often share the screen in our developer Teams video conferences and I had trouble sharing the entire desktop with the purchase of a widescreen.

@thomyg
Copy link

thomyg commented May 4, 2022

Tried your script today, but the shared screen just stays black on the other side. I see mouse movement, but other than that just black.

Any ideas? Thank you!

@ahorn42
Copy link
Author

ahorn42 commented May 9, 2022

Tried your script today, but the shared screen just stays black on the other side. I see mouse movement, but other than that just black.

Any ideas? Thank you!

Sounds like an issue with the screen recording in VLC, maybe you tried to share a window that is not capturable (like DRM protected video files)? Or maybe you accidentally arranged the (at the beginning) empty VLC playback window (the one you select to share) in away you are recoding the playback window again and it stayed black? Try moving another window over it, but you should have seen some mouse ghost images if the playback window is reshared, as it results in some kind of infinity mirror like.

@FonzTech
Copy link

You can add --screen-left and --screen-top to VLC start command to record your screen with an offset. But you have also translate "Paint" operations to that offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment