- Notifications
You must be signed in to change notification settings - Fork8
This repository has been moved tohttps://github.com/kirides/go-d3d
License
kirides/screencapture
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository has been moved tohttps://github.com/kirides/go-d3d
I wanted to learn more aboutCOM
interop with Go and create a somewhat usable screen sharing tool
This application uses D3D11IDXGIOutputDuplication
to create a somewhatrealtime desktop presentation
github.com/mattn/go-mjpeg
for mjpeg streaminggithub.com/kbinani/screenshot
for comparison with GDIBitBlt
(slightly modified source, to support re-usingimage.RGBA
)golang.org/x/exp/shiny/driver/internal/swizzle
for faster BGRA -> RGBA conversion (seeshiny LICENSE)github.com/pixiv/go-libjpeg/jpeg
for fast jpeg encoding- enable with
go build -tag jpegturbo
- enable with
Just build the application and run it.It should serve all your monitors on an URL likehttp://127.0.0.1:8023/watch?screen=N
wherescreen=N <- N
is the monitor index, starting at zero (0
).
By changing the lines incmd/example/main.go
regarding the streaming, you can switch between GDIBitBlt
orIDXGIOutputDuplication
// ...framerate:=10fori:=0;i<n;i++ {// ...// streamDisplay(ctx, i, framerate, stream) // <= USE GDI BitBltstreamDisplayDXGI(ctx,i,framerate,stream)// <= USE IDXGIOutputDuplication// captureScreenTranscode(ctx, i, desiredFps)http.HandleFunc(fmt.Sprintf("/mjpeg%d",i),stream.ServeHTTP)}// ...
The code contains the functioncaptureScreenTranscode
which allows you to record theselected screen directly into ffmpeg and transcode it to h264 in an mp4 container.
Performanceis not optimized to 100%, there are still thing that could be improved.
- only copying the dirty-rectangles (less GPU<->CPU communication)
- faster swizzle implementation using AVX/2 (less time for converting the BGRA texture)
- profile ... profile ... profile
Overall the current implementation is about 2-5x faster than GDIBitBlt
(depending on the resolution,the higher the bigger the difference) and uses a lot less resources for cases where there arent any changes to the screen.
To make use ofIDXGIOutput5::DuplicateOutput1
, an application has to provide support forPerMonitorV2
DPI-Awareness (Windows 10 1703+)This is usually done by providing an my-executable.exe.manifest file either next to the executable, or as an embedded resource.
In this application there are calls toIsValidDpiAwarenessContext
andSetThreadDpiAwarenessContext
which circumvent the requirement.
About
This repository has been moved tohttps://github.com/kirides/go-d3d