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

Post your working scripts, libraries and tools for AHK v1.1 and older
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

27 Jan 2020, 05:37

Such situation means that PC is slow and You need to decrease FPS.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

29 Jan 2020, 01:58

Fixed inaccurate frame allocation algorithm.
Now consumes more CPU, but this is IMHO OK for real-time encoding.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

29 Jan 2020, 14:48

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
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

30 Jan 2020, 02:19

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.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

30 Jan 2020, 09:08

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
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

02 Feb 2020, 12:47

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)
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

02 Feb 2020, 13:53

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
User avatar
TheDewd
Posts: 1507
Joined: 19 Dec 2013, 11:16
Location: USA

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

06 Feb 2020, 16:05

hardware-encoder - NVIDIA H.264 Encoder MFT

Cannot find Audio device - "CABLE Output (VB-Audio Virtual Cable)"
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

06 Feb 2020, 16:27

@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
User avatar
TheDewd
Posts: 1507
Joined: 19 Dec 2013, 11:16
Location: USA

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

06 Feb 2020, 16:46

@burque505,

Excellent!

Code: Select all

done
125 captured
0 frames dropped
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

15 Feb 2020, 07:47

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.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

15 Feb 2020, 09:11

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
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

15 Feb 2020, 22:16

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)
?
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

16 Feb 2020, 09:07

@malcev, both of your fixes work fine for me.
Thanks!
Regards,
burque505
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

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

26 Sep 2020, 16:34

@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)").
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

26 Sep 2020, 17:09

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.
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

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

01 Oct 2020, 12:13

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
chella1cm
Posts: 2
Joined: 19 Jun 2016, 22:22

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

30 Apr 2022, 09:17

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)

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble and 124 guests