sskodje / ScreenRecorderLib

A .NET library for screen recording in Windows, using native Microsoft Media Foundation for realtime encoding to h264 video or PNG images.
MIT License
408 stars 93 forks source link

Fails to record in User Account #276

Closed EmbeddedInc closed 2 months ago

EmbeddedInc commented 9 months ago

We have an application that records properly in an Admin account, but will not record in a user account. For other file writes, we can write to the same location from the app.

The log looks like:

2023-12-05 12:06:23.651 [DEBUG] [RecordingManager.cpp     |  ConfigureOutputDir: 144] >> Video output folder is ready
2023-12-05 12:06:23.667 [DEBUG] [RecordingManager.cpp     |  ConfigureOutputDir: 173] >> Snapshot output folder is ready
2023-12-05 12:06:23.669 [INFO]  [RecordingManager.cpp     |         operator (): 279] >> Starting recording task
2023-12-05 12:06:23.970 [DEBUG] [OutputManager.cpp        |      BeginRecording: 103] >> Sink Writer initialized
2023-12-05 12:06:24.107 [ERROR] [WindowsGraphicsCapture.c |      GetCaptureItem: 356] >> Failed to create capture item for window: error is The remote procedure call failed.
2023-12-05 12:06:24.113 [ERROR] [ScreenCaptureManager.cpp |   CaptureThreadProc: 808] >> Failed to start capture
2023-12-05 12:06:24.117 [ERROR] [ScreenCaptureManager.cpp | ProcessCaptureHRESU:1251] >> Unexpected error, aborting capture: The remote procedure call failed.
2023-12-05 12:06:24.119 [ERROR] [ScreenCaptureManager.cpp |   CaptureThreadProc: 972] >> Fatal error in screen capture, exiting..
2023-12-05 12:06:24.122 [DEBUG] [ScreenCaptureManager.cpp |   CaptureThreadProc: 977] >> Exiting CaptureThreadProc
2023-12-05 12:06:24.478 [DEBUG] [RecordingManager.cpp     |   StartRecorderLoop: 701] >> Changed Recording Status to Recording
2023-12-05 12:06:24.482 [INFO]  [OutputManager.cpp        |   FinalizeRecording: 133] >> Cleaning up resources
2023-12-05 12:06:24.488 [INFO]  [OutputManager.cpp        |   FinalizeRecording: 134] >> Finalizing recording
2023-12-05 12:06:24.537 [DEBUG] [CMFSinkWriterCallback.h  |          OnFinalize:  18] >> CMFSinkWriterCallback::OnFinalize
2023-12-05 12:06:24.541 [DEBUG] [OutputManager.cpp        |   FinalizeRecording: 157] >> Shut down IMFMediaSink
2023-12-05 12:06:24.543 [INFO]  [RecordingManager.cpp     |         operator (): 301] >> Exiting recording task
2023-12-05 12:06:24.553 [DEBUG] [RecordingManager.cpp     | SetRecordingComplet: 404] >> Changed Recording Status to Idle
2023-12-05 12:06:24.557 [DEBUG] [RecordingManager.cpp     | SetRecordingComplet: 432] >> Sent Recording Failed callback
sskodje commented 9 months ago

Hi!

Does this happen when trying to record all windows, or only some? The error is not about rights to create files, but it can't access the window to record.

EmbeddedInc commented 9 months ago

Hi There - Appreciate you getting back to me.

It looks like it is for all windows. I added the two lines as indicated below and got additional errors in the log.

           var sources = new List<RecordingSourceBase>();

            //Added these two lines
            var allRecordableWindows = Recorder.GetWindows();
            sources.Add(allRecordableWindows.FirstOrDefault());

            IntPtr windowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            sources.Add(new WindowRecordingSource(windowHandle));

recorder.log

sskodje commented 9 months ago

Yeah, it should be able to record the window of its own application at the very least, without requiring elevation. I'm a bit stumped here. I've never had an issue where it fails to record without elevation before. I'm finding some info online that it could be related to antivirus misbehaving, if that fits the bill.

EmbeddedInc commented 9 months ago

We don't have any anti-virus running, It is a very isolated PC, not even connected to the internet and running in kiosk mode. IF you can think of any tests I can run - I can try that tomorrow. Thanks for providing support.