Slide 1

Slide 1 text

Hello João Portela

Slide 2

Slide 2 text

Real-time Desktop Capture

Slide 3

Slide 3 text

What for? Our clients needed to record what our software is displaying on the monitors, and send those images to their clients. Their current solution uses dedicated hardware. They requested us to integrate this with our current software, into the same hardware that we are currently using.

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Summary ● Record 4 monitors at 1080p@60fps. ● Low to medium performance impact. ● Automatic disk rotation. ○ To multiple disks at the same time (a black-box and to send to their clients) ● Automatic file split (by size or time).

Slide 7

Slide 7 text

Solution Integrate FFMPEG with our software.

Slide 8

Slide 8 text

FFMPEG Pros: ● Out of the box support for multiple encoders ○ NVENC ○ QuickSync ○ x264 ● Command line tool that can be integrated into our system. Cons: ● Not very stable with QuickSync ○ Sometimes you had to try multiple times for it to start. ● Can only record at 30fps ○ Not a deal breaker but undesirable.

Slide 9

Slide 9 text

FFMPEG - Performance Codec CPU (TOTAL) RAM (TOTAL) GPU (NVIDIA) GPU (INTEL) Video Engine Total file size Video duration 2 NVENC + 2 QUICKSYNC 40% 36% 25% 31% 27% 80.02 MB 2 mins 21 secs 2 NVENC + 2 LIBX264 71% 36% 19% 0% 26% 421.45 MB 2 mins 45 secs 2 QUICKSYNC + 2 LIBX264 100% 36% 39% 42% 0% 182.87 MB 2 mins 10 secs 3 QUICKSYNC + 1 NVENC 48% 36% 20% 46% 13% 80.09 MB 2 min 9 secs 4 LIBX264 (very fast) 100% 33% 47%@880MHZ 0% 0% 587.76 MB 2 min 33 secs 4 LIBX264 (ultra fast) 44% 33% 42%@880MHZ 0% 0% 699.48 MB 2 mins 20 secs

Slide 10

Slide 10 text

NOPE It’s never that easy.

Slide 11

Slide 11 text

FFMPEG + Cons: DirectShow can only capture one screen. GDIgrab causes mouse flicker when recording more than one screen.

Slide 12

Slide 12 text

STOP Review technology and assumptions

Slide 13

Slide 13 text

Desktop Recording - the basics ● Desktop Capture ● Video Encoding

Slide 14

Slide 14 text

Capture ● DirectShow ● Windows GDI (gdigrab in ffmpeg) ● NVFBC/NVIFR ○ NVFBC (Frame Buffer Capture) ○ NVIFR (In-band Frame Render) ● DXGI Desktop Duplication

Slide 15

Slide 15 text

Windows GDI «The Microsoft Windows graphics device interface (GDI) enables applications to use graphics and formatted text on both the video display and the printer. Windows-based applications do not access the graphics hardware directly. Instead, GDI interacts with device drivers on behalf of applications.» Old Microsoft technology for interacting with graphics devices.

Slide 16

Slide 16 text

DirectShow «Microsoft® DirectShow® is an architecture for streaming media on the Microsoft Windows® platform. DirectShow provides for high-quality capture and playback of multimedia streams.» Technology used for much more than desktop capture. Our previous ffmpeg solution created a DirectShow stream for the desktop. ffmpeg then consumed it as if it was a capture card stream.

Slide 17

Slide 17 text

NVFBC/NVIFR NVIDIA driver-level capture paths. NVFBC is what shadowplay uses. They’re amazing as they allow us to capture the screen or an application with minimal performance impact. NVFBC - NVIDIA Frame Buffer Capture Captures the framebuffer (front buffer) without any involvement from OpenGL or Direct3D. Directly from the graphics driver. NVIFR - NVIDIA In-band Frame Render Slightly more complicated and less performant than NVFBC, this can capture a single application. This requires changes at the application level.

Slide 18

Slide 18 text

NVFBC/NVIFR Unfortunately: «In new drivers NVIFR and NVFBC are now completely locked by NVIDIA for their internal tools only. Some green(dy) vendor want to artificially limit performance difference between Shadowplay and traditional video capture tools.» Alexey Nicolaychuk aka Unwinder, RivaTuner creator «NvFBC and NvIFR are private APIs that are only available to approved partners for use in remote graphics scenarios.» NVIDIA linux driver release notes.

Slide 19

Slide 19 text

DXGI Desktop Duplication DXGI: Microsoft DirectX Graphics Infrastructure «The desktop duplication API provides remote access to a desktop image for collaboration scenarios. Apps can use the desktop duplication API to access frame-by-frame updates to the desktop. Because apps receive updates to the desktop image in a DXGI surface, the apps can use the full power of the GPU to process the image updates. » ● Only windows 8.1+ ● Way more performant than GDI or D3D9 approaches.

Slide 20

Slide 20 text

Encoding - using H.264 ● NVENC ● QuickSync ● X264

Slide 21

Slide 21 text

NVENC - NVIDIA encoder Pros: ● Encoder used by ShadowPlay ● Runs on the graphics card on dedicated video encoding hardware Cons: ● Can only encode two streams at once.

Slide 22

Slide 22 text

QuickSync Pros: ● Intel encoding technology. ● Uses mostly iGPU ○ Leaving main CPU and main GPU free. Cons: ● Needs CPU model support ● Needs motherboard support

Slide 23

Slide 23 text

x264 Software encoder. Uses a lot of CPU (multiple cores).

Slide 24

Slide 24 text

Options? ● Do it from scratch ● Adapt ffmpeg ○ Add directshow sources for all monitors ○ New frame provider using DXGI Desktop Duplication ● Adapt obs-studio

Slide 25

Slide 25 text

Do it from scratch Too much work, the deadline was close.

Slide 26

Slide 26 text

Adapt ffmpeg Also, too complex. Even compiling it was an headache.

Slide 27

Slide 27 text

obs-studio ● obs-studio worked great when used as a desktop application. ● Out of the box support for QuickSync, NVENC and x264 ● Automatically uses DXGI desktop duplication when on windows 8.1+ Obs-studio is a rewrite of obs with the intention of separating the core functionalities form the UI layer.

Slide 28

Slide 28 text

obs-studio ● libobs exists separately from obs-studio ○ It is not too easy to use since it only has inline documentation. ○ But we can see how it is being used by the GUI ● Works surprisingly well after some initial hurdles.

Slide 29

Slide 29 text

obs-cli

Slide 30

Slide 30 text

obs-cli >obs-cli.exe --help obs-cli Allowed options: -h [ --help ] Show help message --listmonitors List available monitors resolutions --listinputs List available inputs --listencoders List available encoders --listoutputs List available outputs --listaudios List available audios -m [ --monitor ] arg set monitor to be recorded -a [ --audio ] [=arg(=default)] set audio to be recorded (default to mic) -a"device_name" -e [ --encoder ] arg (=obs_x264) set encoder -v [ --vbitrate ] arg (=2500) set video bitrate. suggested values: 1200 for low, 2500 for medium, 5000 for high -o [ --output ] arg set file destination, can be set multiple times for multiple outputs

Slide 31

Slide 31 text

obs-cli - sample command obs-cli.exe --monitor 3 --audio --encoder obs_qsv11 --vbitrate 2500 --output "videoname.mp4"

Slide 32

Slide 32 text

Recorder UI

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Performance

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Documentation Documentation Documentation

Slide 39

Slide 39 text

?