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

Post your working scripts, libraries and tools
malcev
Posts: 654
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: 654
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: 1356
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: 654
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: 1356
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: 654
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: 1356
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: 1408
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)"
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
burque505
Posts: 1356
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: 1408
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
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
malcev
Posts: 654
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: 1356
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: 654
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: 1356
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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: kerenua and 32 guests