Page 2 of 4

Re: Image Sequence Recorder

Posted: 15 Dec 2019, 09:47
by burque505
@Hellbent, you mentioned in a post above that you might add in a checkbox that would prevent you from accidentally recording over something. That would be fantastic.
Best regards,
burque505

Re: Image Sequence Recorder

Posted: 15 Dec 2019, 10:27
by Hellbent
burque505 wrote:
15 Dec 2019, 09:47
@Hellbent, you mentioned in a post above that you might add in a checkbox that would prevent you from accidentally recording over something. That would be fantastic.
Best regards,
burque505
I think that I might actually also add a option to append as well (start from the last count).
Might be another day or two before I have the time to do the edit though.

Re: Image Sequence Recorder

Posted: 15 Dec 2019, 10:31
by burque505
Appending would be great too. Looking forward to it.

Re: Image Sequence Recorder

Posted: 15 Dec 2019, 13:18
by malcev
Hellbent wrote:
15 Dec 2019, 07:29
The CPU usage is down to 25%, but the video is inverted (upside down).
I updated code.
If You will get inverted video or do not get video at all - I think that it means that Your computer cannot hardware encode h264.
Then comment this line - hardware_encoding := true.
With directx11 and hardware encoding my Cpu is loaded no more than 1%.
With software encoding about 6%.

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 03:58
by AHKStudent
malcev wrote:
14 Dec 2019, 22:53
I fixed examples.
On Directx12 it generates a 0kb video file, this would be neat if it can work for 12 as well :thumbup:

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 05:13
by malcev
Try to comment "hardware_encoding := true".

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 05:55
by AHKStudent
malcev wrote:
16 Dec 2019, 05:13
Try to comment "hardware_encoding := true".
that fixed it and cpu was only 4%

file size was 1.3mb for the 5 seconds

what would be the main settings to change to lower file size?

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 06:02
by malcev

Code: Select all

video_bitrate := 2000000

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 06:14
by AHKStudent
malcev wrote:
16 Dec 2019, 06:02

Code: Select all

video_bitrate := 2000000
thanks,

Re: Image Sequence Recorder

Posted: 16 Dec 2019, 21:01
by malcev
Updated codes for capturing region and mouse cursor.

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 07:23
by AHKStudent
malcev wrote:
16 Dec 2019, 21:01
Updated codes for capturing region and mouse cursor.
thats nice, it helps with file size a lot

is there a way to use ahk with directx to capture from the webcam?

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 07:51
by malcev
I do not have webcam and it is not interested to me to implent it.
If You need it You can convert this example to ahk:
https://docs.microsoft.com/en-us/windows/win32/medfound/mfcapturetofile-sample

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 07:56
by AHKStudent
malcev wrote:
17 Dec 2019, 07:51
I do not have webcam and it is not interested to me to implent it.
If You need it You can convert this example to ahk:
https://docs.microsoft.com/en-us/windows/win32/medfound/mfcapturetofile-sample
Thank you, maybe one day when I have the knowledge :ugeek:

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 08:03
by malcev
May be for You it will be easier to capture with opencv:
https://autohotkey.com/board/topic/67418-webcam-avi-webcam-png-etc-etc/

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 08:15
by AHKStudent
malcev wrote:
17 Dec 2019, 08:03
May be for You it will be easier to capture with opencv:
https://autohotkey.com/board/topic/67418-webcam-avi-webcam-png-etc-etc/
thanks, opencv is 200mb and to make portable directx would be so much lighter and better

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 08:50
by malcev
1) You do not need directx for capture from webcam.
Capturing goes through directshow.
2) As I understand code You need only 2 dlls from OpenCv - it is about 4mb.
Some examples using OpenCV in AHK:
https://www.autohotkey.com/boards/viewtopic.php?p=299604#p299604
Also, You can search directshow UDF, or some examples of webcam capture in AutoIt (They have more user libraries than Autohotkey) and then transfer it to ahk.

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 08:58
by AHKStudent
thank you ill read about it now

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 13:18
by rommmcek
This is great thread!
Spoiler
Here is my contribution:
Edit: Added option to set recording duration.
Edit2: Coordinats are now rounded to output even width/height, added Inputbox to enter/change output file.
Edit3:
- Frame is not hidden at the recording start (can be hidden at any time later via Esc as usual)
- Fixed bug which causes sometimes to record a one pixel edge of a frame due to outward rounding (now inward)
- Inputboxes F3 and F5 are now available only when frame is visible
Edit4, Edit5 new: F5 long press: List of audio devices to set/unset (changed!)
Edit6, 7: Updated to fix (by malcev) sound off sync, and broken frame resize plus minor quirks:
Edit8: Added F2 (long press) to capture whole screen without setting the frame and rearranged some of the hotkeys.
Instructions

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 15:59
by malcev
coordinats should be rounded to 10 pixels (otherwise crash is very likely)
I think it depends on encoder.
I test my code and results are:
If I use hardware GPU encoder Nvidia than should be:

Code: Select all

(x2-x1>32) and (y2-y1>16)
If I use software encoder than should be

Code: Select all

(x2-x1>32) and (y2-y1>32) and (mod(x2-x1, 2) = 0) and (mod(y2-y1, 2) = 0)
On Win7 if I use software encoder should be

Code: Select all

(x2-x1>=64) and (y2-y1>=64) and (mod(x2-x1, 2) = 0) and (mod(y2-y1, 2) = 0)
How can one know beforehand if PC is capable of hardware_encoding and what equipment is required for that?
It is difficult question and the answer is not clear for me.
You can try to use this code: (by TeaDrinker)

Code: Select all

MFT_CATEGORY_VIDEO_ENCODER  := "{F79EAC7D-E545-4387-BDEE-D647D7BDE42A}"
MFMediaType_Video           := "{73646976-0000-0010-8000-00AA00389B71}"
MFVideoFormat_H264          := "{34363248-0000-0010-8000-00AA00389B71}"
MFVideoFormat_ARGB32       := "{00000015-0000-0010-8000-00aa00389b71}"

MFT_FRIENDLY_NAME_Attribute := "{314FFBAE-5B41-4C95-9C19-4E7D586FACE3}"

MFT_ENUM_FLAG_SYNCMFT       := 0x01
MFT_ENUM_FLAG_ASYNCMFT      := 0x02
MFT_ENUM_FLAG_HARDWARE      := 0x04
MFT_ENUM_FLAG_SORTANDFILTER := 0x40

flags := MFT_ENUM_FLAG_HARDWARE|MFT_ENUM_FLAG_SORTANDFILTER ; указываем нужные флаги из перечисленных

CLSIDFromString(MFT_CATEGORY_VIDEO_ENCODER, GUID_MFT_CATEGORY_VIDEO_ENCODER)
CLSIDFromString(MFMediaType_Video         , GUID_MFMediaType_Video)
CLSIDFromString(MFVideoFormat_H264        , GUID_MFVideoFormat_H264)
CLSIDFromString(MFVideoFormat_ARGB32        , GUID_MFVideoFormat_ARGB32)

VarSetCapacity(MFT_REGISTER_TYPE_INFO_In, 32, 0)
DllCall("RtlMoveMemory", "Ptr", &MFT_REGISTER_TYPE_INFO_In, "Ptr", &GUID_MFMediaType_Video, "Ptr", 16)
DllCall("RtlMoveMemory", "Ptr", &MFT_REGISTER_TYPE_INFO_In + 16, "Ptr", &GUID_MFVideoFormat_ARGB32, "Ptr", 16)

VarSetCapacity(MFT_REGISTER_TYPE_INFO, 32, 0)
DllCall("RtlMoveMemory", "Ptr", &MFT_REGISTER_TYPE_INFO, "Ptr", &GUID_MFMediaType_Video, "Ptr", 16)
DllCall("RtlMoveMemory", "Ptr", &MFT_REGISTER_TYPE_INFO + 16, "Ptr", &GUID_MFVideoFormat_H264, "Ptr", 16)

if (A_PtrSize = 8) {
   res := DllCall("Mfplat\MFTEnumEx", "Ptr", &GUID_MFT_CATEGORY_VIDEO_ENCODER
                                    , "UInt", flags
                                    , "Ptr", &MFT_REGISTER_TYPE_INFO_In, "Ptr", &MFT_REGISTER_TYPE_INFO
                                    , "PtrP", ppMFTActivate, "UIntP", numMFTActivate, "UInt")
}
else {
   res := DllCall("Mfplat\MFTEnumEx", "UInt64", NumGet(GUID_MFT_CATEGORY_VIDEO_ENCODER, 0, "UInt64")
                                    , "UInt64", NumGet(GUID_MFT_CATEGORY_VIDEO_ENCODER, 8, "UInt64")
                                    , "UInt", flags
                                    , "Ptr", &MFT_REGISTER_TYPE_INFO_In, "Ptr", &MFT_REGISTER_TYPE_INFO
                                    , "PtrP", ppMFTActivate, "UIntP", numMFTActivate, "UInt")
}

if !numMFTActivate {
   MsgBox, Не найдено
   Return
}

CLSIDFromString(MFT_FRIENDLY_NAME_Attribute, GUID_MFT_FRIENDLY_NAME_Attribute)

Loop % numMFTActivate {
   IMFActivate := NumGet(ppMFTActivate + (A_Index - 1)*A_PtrSize)

   ; здесь используем методы IMFActivate
   
   res := VTable(IMFActivate, GetAllocatedString := 13).Call("Ptr", &GUID_MFT_FRIENDLY_NAME_Attribute, "PtrP", pwszValue, "UIntP", len, "UInt")
   names .= StrGet(pwszValue, len, "UTF-16") . "`n"
   DllCall("ole32\CoTaskMemFree", "Ptr", pwszValue)
   ObjRelease(IMFActivate)
}
DllCall("ole32\CoTaskMemFree", "Ptr", ppMFTActivate)
MsgBox, % names

CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID)
      throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res))
   Return &CLSID
}

VTable(ppv, idx)  {
   Return Func("DllCall").Bind(NumGet(NumGet(ppv + 0) + A_PtrSize*idx), "Ptr", ppv)
}
But it shows nothing on PC which uses Nvidia GPU hardware encoder.
How did you manage to use Directx12, what one would need to use it?
This code does not use directx12.
Directx12 has different API.
And also there are a lot of parameters of h264 encoder that can optimize speed/quality/cpu consumption.
https://docs.microsoft.com/en-us/windows/win32/medfound/h-264-video-encoder

Re: Image Sequence Recorder

Posted: 17 Dec 2019, 16:48
by AHKStudent
@rommmcek @malcev

I have directx12 on windows 10 and I set hardware_encoding to false and it works great