Page 3 of 4

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 27 Jan 2020, 05:37
by malcev
Such situation means that PC is slow and You need to decrease FPS.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 29 Jan 2020, 01:58
by malcev
Fixed inaccurate frame allocation algorithm.
Now consumes more CPU, but this is IMHO OK for real-time encoding.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 29 Jan 2020, 14:48
by burque505
Hi malcev, thank for continuing to work on this, it's very interesting.
With the code from the first post for Win7, which appears to have been updated quite recently, I get this error:

Code: Select all

IMFSinkWriter_SetInputMediaType error: 
ErrorLevel: 0xc0000005
An empty *.mp4 is produced.
Your code from ~= December 14, 2019 (no sound) is working quite well on Win7.
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 30 Jan 2020, 02:19
by malcev
As I understand this error occurs when You want to capture video with audio?
Try to capture video only.
Sorry, but I do not know why this error occurs to You.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 30 Jan 2020, 09:08
by burque505
I get the same error when I comment out the following lines, if I'm understanding you correctly.

Code: Select all

;audiodevice := "Microphone (HD Webcam C270)"
; x1 := 100, x2 := 1000, y1 := 100, y2 := 500
; ShowAllAudioDevicesNames := true
; CaptureCoordinatesWithCPU := true
; Rotate := true
I will try the Win10 code on Win10 to see if I have better luck.
Thanks again.
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 02 Feb 2020, 12:47
by malcev
Update code in first post.
Add some options, reduce CPU consumption and fix bugs.
@burque505, as I understand from PM, Your hardware encoder does not let use MF_SINK_WRITER_DISABLE_THROTTLING attribute.
Therefore You have 2 choices:
Uncomment "UseSoftwareEncoding := true" to use software encoding.
or
Comment

Code: Select all

IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, "MF_SINK_WRITER_DISABLE_THROTTLING"), true)

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 02 Feb 2020, 13:53
by burque505
Thank you, @malcev. What you say does not surprise me as my video card is over ten years old. I really appreciate you staying on top of this, it's working quite well.
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 06 Feb 2020, 16:05
by TheDewd
hardware-encoder - NVIDIA H.264 Encoder MFT

Cannot find Audio device - "CABLE Output (VB-Audio Virtual Cable)"

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 06 Feb 2020, 16:27
by burque505
@TheDewd, you might try this first:

Code: Select all

file := "test.mp4"
video_bitrate := 2000000
video_fps := 25
duration := 5
capture_cursor := true
;audiodevice := "Microphone (HD Webcam C270)"
; audiodevice := "CABLE Output (VB-Audio Virtual Cable)"
; x1 := 100, x2 := 1000, y1 := 100, y2 := 500
ShowAllAudioDevicesNames := true
; CaptureCoordinatesWithCPU := true
; Rotate := true
You'll get a MsgBox with whatever audio device(s) show up. Then you can comment out the 'ShowAllAudioDevicesNames := true (Edit: epic fail - or set it to 'false', I suppose) and add in 'audiodevice:=' with your device.
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 06 Feb 2020, 16:46
by TheDewd
@burque505,

Excellent!

Code: Select all

done
125 captured
0 frames dropped

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 06 Feb 2020, 16:50
by burque505
:+1:

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 15 Feb 2020, 07:47
by malcev
Update first code.
1) Add quotes when enumerate devices.
2) Add support for enumerating devices with the same name
3) Now You can write ShowAllAudioDevicesNames := false.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 15 Feb 2020, 09:11
by burque505
Hi @malcev, getting this error on Win7 again with the code from 15 February:

Code: Select all

IMFSinkWriter_SetInputMediaType error: 
ErrorLevel: 0xc0000005
Code from 31 January is still working fine.
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 15 Feb 2020, 22:16
by malcev
Strange. Do You get this error after:
Uncomment "UseSoftwareEncoding := true" to use software encoding.
or
Comment

Code: Select all

IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, "MF_SINK_WRITER_DISABLE_THROTTLING"), true)
?

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 16 Feb 2020, 09:07
by burque505
@malcev, both of your fixes work fine for me.
Thanks!
Regards,
burque505

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 26 Sep 2020, 16:34
by DanielToward13
@malcev Thanks for your work. You are well experienced in this field. I would like to ask you a question that I have since long time a go. How some software programs can detect screen recording? Is your code traceable by video protector programs? How those advanced detector programs work? The second question is that how to record the video with system audio not mic? (The ShowAllAudioDevicesNames only shows "Microphone Array (Realtek High Definition Audio)").

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 26 Sep 2020, 17:09
by malcev
How some software programs can detect screen recording?
I do not know, because I have not seen such programs.
I am sure that You can capture anything that You see on screen (there are different API to capture screen)
https://docs.microsoft.com/en-us/previous-versions/technet-magazine/hh241037(v=msdn.10)
how to record the video with system audio not mic?
Install virtual audio device.
https://vb-audio.com/Cable/
BTW, Capturing with directx11 is not good now it can have empty frames.
Someday I will correct it.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 01 Oct 2020, 12:13
by DanielToward13
I disabled the speaker enhancement and it is working now but It crashes without any message when the duration is long. Is there a method to stream the screen?

My settings (DirectX 11 + DXGI (Win10)):

Code: Select all

video_bitrate := 4000000
video_fps := 25
duration := 1800
capture_cursor := true
audiodevice := "Stereo Mix (Realtek High Definition Audio)"
audioDelay := 80
Rotate := true

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 01 Oct 2020, 16:22
by malcev
I just tested it.
For me works OK.

Re: Screen capture to video with Directx9 / Directx11 and Microsoft Media Foundation

Posted: 30 Apr 2022, 09:17
by chella1cm
I cant make the audio work, if I un-comment this "ShowAllAudioDevicesNames := true" line, it just says

Audio:
None

Even if I typed in the Audio device name in the Sound properties dialog box by entering mmsys.cpl, its says "Cannot find audio device - Speakers (Realtek High Definition Audio)". Is there anything else I could do?
(I am using Windows 10 21H2 (Build 19044.1526)