<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Запись веб-камеры с Microsoft Media Foundation]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=17659&amp;type=atom" />
	<updated>2023-03-12T02:45:55Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=17659</id>
		<entry>
			<title type="html"><![CDATA[AHK: Запись веб-камеры с Microsoft Media Foundation]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=157096#p157096" />
			<content type="html"><![CDATA[<p>Вэбкамеры нету, поэтому проверял на виртульном источнике.<br />Для работы нужно вписать название videodevice.<br />Если оно будет выводить звук, то звук также будет записываться.<br />Чтобы брать звук с другого устройства, нужно раскоментировать и указать audiodevice.<br />Чтобы вывести в клипбоард все устройства записи,&nbsp; нужно раскоментировть, ShowAllDevicesNames := true<br />Чтобы убрать превью нужно закоментировать previewWindow := true.<br />Чтобы установить размер превью окна нужно поменять значение previewWindowWidth := 400.<br />Если закоментировать previewWindowWidth := 400, то размер превью-окна будет таким же, как и размер захваченного видео.<br /></p><div class="codebox"><pre><code>file := &quot;test.mp4&quot;
video_bitrate := 2000000
duration := 5
videodevice := &quot;e2eSoft VCam&quot;
; audiodevice := &quot;CABLE Output (VB-Audio Virtual Cable)&quot;
previewWindow := true
previewWindowWidth := 400
; ShowAllDevicesNames := true



setbatchlines -1
LOAD_DLL_Mf_Mfplat_Mfreadwrite()
MFStartup(version := 2, MFSTARTUP_FULL := 0)
if (ShowAllDevicesNames != 1)
{
   VarSetCapacity(MFT_REGISTER_TYPE_INFO, 32, 0)
   DllCall(&quot;RtlMoveMemory&quot;, &quot;ptr&quot;, &amp;MFT_REGISTER_TYPE_INFO, &quot;ptr&quot;, MF_GUID(GUID, &quot;MFMediaType_Video&quot;), &quot;ptr&quot;, 16)
   DllCall(&quot;RtlMoveMemory&quot;, &quot;ptr&quot;, &amp;MFT_REGISTER_TYPE_INFO + 16, &quot;ptr&quot;, MF_GUID(GUID, &quot;MFVideoFormat_H264&quot;), &quot;ptr&quot;, 16)
   hardware_encoder := MFTEnumEx(MF_GUID(GUID, &quot;MFT_CATEGORY_VIDEO_ENCODER&quot;), MFT_ENUM_FLAG_HARDWARE := 0x04|MFT_ENUM_FLAG_SORTANDFILTER := 0x40, 0, &amp;MFT_REGISTER_TYPE_INFO)
   if (hardware_encoder != &quot;&quot;)
   {
      MFCreateAttributes(pMFAttributes, 4)
      IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS&quot;), true)
   }
   else
      MFCreateAttributes(pMFAttributes, 3)
   IMFAttributes_SetGUID(pMFAttributes, MF_GUID(GUID, &quot;MF_TRANSCODE_CONTAINERTYPE&quot;), MF_GUID(GUID1, &quot;MFTranscodeContainerType_MPEG4&quot;))
   IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_SINK_WRITER_DISABLE_THROTTLING&quot;), true)
   IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_LOW_LATENCY&quot;), true)
   MFCreateSinkWriterFromURL(file, 0, pMFAttributes, pSinkWriter)
   Release(pMFAttributes)
   pMFAttributes := &quot;&quot;
}

deviceError := WidthMax := HeightMax := FpsMax := BitrateMax := StreamNumberVideo := TypeNumberVideo := NUM_CHANNELSMax := BITS_PER_SAMPLEMax := SAMPLES_PER_SECONDMax := BYTES_PER_SECONDMax := StreamNumberAudio := TypeNumberAudio := VideoSources := AudioSources := InputVideoTransformMax := &quot;&quot;
loop 2
{
   if (A_Index = 1)
      LookingSource := &quot;video&quot;
   else
      LookingSource := &quot;audio&quot;
   %LookingSource%basedevice := %LookingSource%device
   MFCreateAttributes(pMFAttributes%LookingSource%, 1)
   IMFAttributes_SetGUID(pMFAttributes%LookingSource%, MF_GUID(GUID, &quot;MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE&quot;), MF_GUID(GUID1, &quot;MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_&quot; SubStr(LookingSource, 1, 3) &quot;CAP_GUID&quot;))
   MFEnumDeviceSources(pMFAttributes%LookingSource%, pppSourceActivate, pcSourceActivate)
   Loop % pcSourceActivate
   {
      IMFActivate := NumGet(pppSourceActivate + (A_Index - 1)*A_PtrSize)
      devicename := IMFActivate_GetAllocatedString(IMFActivate, MF_GUID(GUID, &quot;MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME&quot;))
      if (ShowAllDevicesNames = 1)
      {
         basedevicename := devicename
         loop
         {
            if !InStr(%LookingSource%devicenames, &quot;&quot;&quot;&quot; devicename &quot;&quot;&quot;`r`n&quot;)
               break
            devicename := basedevicename &quot;[&quot; A_Index+1 &quot;]&quot;
         }
         %LookingSource%devicenames .= &quot;&quot;&quot;&quot; devicename &quot;&quot;&quot;`r`n&quot;
      }
      else
      {
         if RegexMatch(%LookingSource%device, &quot;\[(\d)]$&quot;, match) and (devicename = RegexReplace(%LookingSource%device, &quot;\[\d]$&quot;))
         {
            match1--
            if (match1 = 0)
               %LookingSource%device := devicename
            else
               %LookingSource%device := devicename &quot;[&quot; match1 &quot;]&quot;
         }
         if (devicename = %LookingSource%device) and (MediaSource%LookingSource% = &quot;&quot;)
            IMFActivate_ActivateObject(IMFActivate, IMFMediaSource := &quot;{279a808d-aec7-40c8-9c6b-a6b492c78a66}&quot;, MediaSource%LookingSource%)
      }
      Release(IMFActivate)
      IMFActivate := &quot;&quot;
   }
   DllCall(&quot;ole32\CoTaskMemFree&quot;, &quot;ptr&quot;, pppSourceActivate)
   Release(pMFAttributes%LookingSource%)
   pMFAttributes%LookingSource% := &quot;&quot;
   if (ShowAllDevicesNames = 1)
   {
      if (%LookingSource%devicenames = &quot;&quot;)
         %LookingSource%devicenames .= &quot;None`r`n&quot;
      %LookingSource%devicenames := LookingSource &quot;:`r`n&quot; %LookingSource%devicenames
      if (A_Index = 1)
         Continue
      msgbox % clipboard := videodevicenames &quot;`r`n&quot; audiodevicenames
      ExitApp
   }
   if (MediaSource%LookingSource% = &quot;&quot;) or (deviceError != &quot;&quot;)
   {
      if (MediaSource%LookingSource% = &quot;&quot;)
         deviceError .= &quot;Cannot find &quot; LookingSource &quot; device - &quot;&quot;&quot; %LookingSource%basedevice &quot;&quot;&quot;`n&quot;
      if (A_Index = 1) and (audiodevice != &quot;&quot;)
         Continue
      msgbox % deviceError
      ExitApp
   }
   if (A_Index = 1)
   {
      if (hardware_encoder != &quot;&quot;)
      {
         MFCreateAttributes(pMFAttributes, 3)
         IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS&quot;), true)
      }
      else
         MFCreateAttributes(pMFAttributes, 2)
      IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_LOW_LATENCY&quot;), true)
      IMFAttributes_SetUINT32(pMFAttributes, MF_GUID(GUID, &quot;MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN&quot;), true)
   }
   MFCreateSourceReaderFromMediaSource(MediaSource%LookingSource%, pMFAttributes, SourceReader)
   loop
   {
      n := A_Index - 1
      if (IMFSourceReader_GetNativeMediaType(SourceReader, n, 0, ppMediaType) = &quot;MF_E_INVALIDSTREAMNUMBER&quot;)
      {
         if (LookingSource = &quot;video&quot;)
            VideoStreamCount := n
         break
      }
      Release(ppMediaType)
      ppMediaType := &quot;&quot;
      loop
      {
         k := A_Index - 1
         if (IMFSourceReader_GetNativeMediaType(SourceReader, n, k, ppMediaType) = &quot;MF_E_NO_MORE_TYPES&quot;)
            break
         IMFAttributes_GetGUID(ppMediaType, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), pguidValue)
         if (LookingSource = &quot;video&quot;) and (MemoryDifference(&amp;pguidValue, MF_GUID(GUID, &quot;MFMediaType_Video&quot;), 16) = 0)
         {
            IMFAttributes_GetGUID(ppMediaType, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), pguidValueSubType)
            VideoSources .= Format(&quot;0x{:x}&quot;, NumGet(pguidValueSubType, 0, &quot;int&quot;)) &quot;`n&quot; 
            if (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_I420&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_IYUV&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_NV12&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_YUY2&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_YV12&quot;), 16) = 0)
               InputVideoTransformCurrent := &quot;WithoutTransform&quot;
            else if ((MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_RGB24&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_RGB32&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_RGB555&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_RGB565&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_AYUV&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_NV11&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_UYVY&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_Y41P&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_Y41T&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_Y42T&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_YVU9&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_YVYU&quot;), 16) = 0)) and (InputVideoTransformMax != &quot;WithoutTransform&quot;)
               InputVideoTransformCurrent := &quot;WithTransform&quot;
            else
               InputVideoTransformCurrent := &quot;&quot;
            if (InputVideoTransformCurrent != &quot;&quot;)
            {
               IMFAttributes_GetUINT64(ppMediaType, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
               IMFAttributes_GetUINT64(ppMediaType, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
               if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_AVG_BITRATE&quot;), AVG_BITRATE) = &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
                  AVG_BITRATE := 0
               WidthCurrent := FRAME_SIZE &gt;&gt; 32
               HeightCurrent := 0xFFFFFFFF &amp; FRAME_SIZE
               FpsCurrent := (FRAME_RATE&gt;&gt;32)/(0xFFFFFFFF &amp; FRAME_RATE)
               BitrateCurrent := AVG_BITRATE
               if ((InputVideoTransformMax = &quot;WithTransform&quot;) and (InputVideoTransformCurrent = &quot;WithoutTransform&quot;)) or (WidthCurrent &gt; WidthMax) or ((WidthCurrent = WidthMax) and (HeightCurrent &gt; HeightMax)) or ((WidthCurrent = WidthMax) and (HeightCurrent = HeightMax) and (FpsCurrent &gt; FpsMax)) or ((WidthCurrent = WidthMax) and (HeightCurrent = HeightMax) and (FpsCurrent = FpsMax) and (BitrateCurrent &gt; BitrateMax))
               {
                  InputVideoTransformMax := InputVideoTransformCurrent
                  WidthMax := WidthCurrent
                  HeightMax := HeightCurrent
                  FpsMax := FpsCurrent
                  BitrateMax := BitrateCurrent
                  StreamNumberVideo := n
                  TypeNumberVideo := k
               }
            }
         }
         if ((LookingSource = &quot;audio&quot;) or (audiodevice = &quot;&quot;)) and (MemoryDifference(&amp;pguidValue, MF_GUID(GUID, &quot;MFMediaType_Audio&quot;), 16) = 0)
         {
            IMFAttributes_GetGUID(ppMediaType, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), pguidValueSubType)
            AudioSources .= Format(&quot;0x{:x}&quot;, NumGet(pguidValueSubType, 0, &quot;int&quot;)) &quot;`n&quot;
            if (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFAudioFormat_PCM&quot;), 16) = 0) or (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFAudioFormat_Float&quot;), 16) = 0)
            {
               if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_AUDIO_AVG_BYTES_PER_SECOND&quot;), BYTES_PER_SECOND) = &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
                  BYTES_PER_SECOND := 0
               if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_AUDIO_BITS_PER_SAMPLE&quot;), BITS_PER_SAMPLE) = &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
                  BITS_PER_SAMPLE := 0
               if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_AUDIO_SAMPLES_PER_SECOND&quot;), SAMPLES_PER_SECOND) = &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
                  SAMPLES_PER_SECOND := 0
               if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_AUDIO_NUM_CHANNELS&quot;), NUM_CHANNELS) = &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
                  NUM_CHANNELS := 0
               if (InStr(A_OSVersion, &quot;W&quot;) and (((NUM_CHANNELSMax != 1) and (NUM_CHANNELSMax != 2) and (NUM_CHANNELS &gt; 0)) or ((NUM_CHANNELSMax = 1) and (NUM_CHANNELS = 2)))) or (!InStr(A_OSVersion, &quot;W&quot;) and (((NUM_CHANNELSMax &lt; 2) and (NUM_CHANNELS &gt; NUM_CHANNELSMax)) or ((NUM_CHANNELSMax = 2) and (NUM_CHANNELS = 6)) or ((NUM_CHANNELSMax &gt; 2) and (NUM_CHANNELSMax != 6) and ((NUM_CHANNELS = 2) or (NUM_CHANNELS = 6))))) or ((NUM_CHANNELS = NUM_CHANNELSMax) and (BITS_PER_SAMPLEMax != 16) and ((BITS_PER_SAMPLE = 16) or (BITS_PER_SAMPLE &gt; BITS_PER_SAMPLEMax))) or ((NUM_CHANNELS = NUM_CHANNELSMax) and (BITS_PER_SAMPLE = BITS_PER_SAMPLEMax) and (SAMPLES_PER_SECONDMax != 44100) and (SAMPLES_PER_SECONDMax != 48000) and ((SAMPLES_PER_SECOND = 44100) or (SAMPLES_PER_SECOND &gt; SAMPLES_PER_SECONDMax))) or ((SAMPLES_PER_SECONDMax != 48000) and (SAMPLES_PER_SECOND = 48000)) or ((NUM_CHANNELS = NUM_CHANNELSMax) and (BITS_PER_SAMPLE = BITS_PER_SAMPLEMax) and (SAMPLES_PER_SECOND = SAMPLES_PER_SECONDMax) and (BYTES_PER_SECOND &gt; BYTES_PER_SECONDMax))
               { 
                  if (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFAudioFormat_PCM&quot;), 16) = 0)
                     MFAudioFormat := &quot;MFAudioFormat_PCM&quot;
                  else
                     MFAudioFormat := &quot;MFAudioFormat_Float&quot;
                  NUM_CHANNELSMax := NUM_CHANNELS
                  BITS_PER_SAMPLEMax := BITS_PER_SAMPLE
                  SAMPLES_PER_SECONDMax := SAMPLES_PER_SECOND
                  BYTES_PER_SECONDMax := BYTES_PER_SECOND
                  StreamNumberAudio := n
                  TypeNumberAudio := k
               }
            }
         }
         Release(ppMediaType)
         ppMediaType := &quot;&quot;
      }
   }
   if (audiodevice != &quot;&quot;)
   {
      Release(SourceReader)
      SourceReader := &quot;&quot;
   }
   if (audiodevice = &quot;&quot;) or (A_Index = 2)
   {
      if (StreamNumberVideo = &quot;&quot;)
      {
         Sort, VideoSources, U
         msgbox % &quot;Current VideoSources not supported:`n&quot; VideoSources
         ExitApp
      }
      if (A_Index = 2)
      {
         if (StreamNumberAudio != &quot;&quot;)
            StreamNumberAudio += VideoStreamCount
         else
         {
            Sort, AudioSources, U
            msgbox % &quot;Current AudioSources not supported:`n&quot; AudioSources
            ExitApp
         }
         MFCreateCollection(MFCollection)
         IMFCollection_AddElement(MFCollection, MediaSourceVideo)
         IMFCollection_AddElement(MFCollection, MediaSourceAudio)
         MFCreateAggregateSource(MFCollection, AggSource)
         Release(MFCollection)
         MFCollection := &quot;&quot;
         MFCreateSourceReaderFromMediaSource(AggSource, pMFAttributes, SourceReader)
      }
      IMFSourceReader_SetStreamSelection(SourceReader, MF_SOURCE_READER_ALL_STREAMS := 0xFFFFFFFE, false)
      IMFSourceReader_SetStreamSelection(SourceReader, StreamNumberVideo, true)
      if (StreamNumberAudio != &quot;&quot;)
         IMFSourceReader_SetStreamSelection(SourceReader, StreamNumberAudio, true)
      IMFSourceReader_GetNativeMediaType(SourceReader, StreamNumberVideo, TypeNumberVideo, ppMediaType)
      IMFAttributes_GetGUID(ppMediaType, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), pguidValueSubType)
      IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_INTERLACE_MODE&quot;), INTERLACE_MODE)
      IMFAttributes_GetUINT64(ppMediaType, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
      IMFAttributes_GetUINT64(ppMediaType, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
      IMFAttributes_GetUINT64(ppMediaType, MF_GUID(GUID, &quot;MF_MT_PIXEL_ASPECT_RATIO&quot;), ASPECT_RATIO)
      if (IMFAttributes_GetUINT32(ppMediaType, MF_GUID(GUID, &quot;MF_MT_DEFAULT_STRIDE&quot;), DEFAULT_STRIDE) != &quot;MF_E_ATTRIBUTENOTFOUND&quot;)
         DEFAULT_STRIDE := DEFAULT_STRIDE&lt;&lt;32&gt;&gt;32
      else
         MFGetStrideForBitmapInfoHeader(NumGet(pguidValueSubType, 0, &quot;uint&quot;), WidthMax, DEFAULT_STRIDE)
      Release(ppMediaType)
      Release(pMFAttributes)
      ppMediaType := pMFAttributes := &quot;&quot;
      if (audiodevice = &quot;&quot;)
         break
   }
}
msgbox % &quot;hardware-encoder - &quot; ((hardware_encoder != &quot;&quot;) ? hardware_encoder : &quot;none&quot;)

loop 2   ; 1 - input, 2 - output
{
   MFCreateMediaType(pMediaTypeVideo%A_Index%)
   IMFAttributes_SetGUID(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Video&quot;))
   if (A_Index = 1)
      IMFAttributes_SetGUID(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), &amp;pguidValueSubType)
   else
   {
      IMFAttributes_SetGUID(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFVideoFormat_H264&quot;))
      IMFAttributes_SetUINT32(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_AVG_BITRATE&quot;), video_bitrate)
   }
   IMFAttributes_SetUINT32(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_INTERLACE_MODE&quot;), INTERLACE_MODE)
   IMFAttributes_SetUINT64(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
   IMFAttributes_SetUINT64(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
   IMFAttributes_SetUINT64(pMediaTypeVideo%A_Index%, MF_GUID(GUID, &quot;MF_MT_PIXEL_ASPECT_RATIO&quot;), ASPECT_RATIO)
}
IMFSinkWriter_AddStream(pSinkWriter, pMediaTypeVideo2, videoStreamIndex)
if (IMFSinkWriter_SetInputMediaType(pSinkWriter, videoStreamIndex, pMediaTypeVideo1, 0) = &quot;MF_E_INVALIDMEDIATYPE&quot;)
{
   LOAD_DLL_Colorcnv()
   VideoTransform := 1
   MFCalculateImageSize(MF_GUID(GUID, &quot;MFVideoFormat_YUY2&quot;), WidthMax, HeightMax, cbOutBytesVideo)
   loop 2   ; 1 - input, 2 - output
   {
      MFCreateMediaType(pMedia%A_Index%)
      IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Video&quot;))
      if (A_Index = 1)
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), &amp;pguidValueSubType)
      else
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFVideoFormat_YUY2&quot;))
      IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_INTERLACE_MODE&quot;), INTERLACE_MODE)
      IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
      IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
      IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_PIXEL_ASPECT_RATIO&quot;), ASPECT_RATIO)
   }
   pTransformVideo := ComObjCreate(CLSID_CColorConvertDMO := &quot;{98230571-0087-4204-b020-3282538e57d3}&quot;, IID_IMFTransform := &quot;{bf94c121-5b05-4e6f-8000-ba598961414d}&quot;)
   IMFTransform_SetInputType(pTransformVideo, 0, pMedia1, 0)
   IMFTransform_SetOutputType(pTransformVideo, 0, pMedia2, 0)
   IMFTransform_GetInputStatus(pTransformVideo, 0, mftStatus)
   if (mftStatus != 1)   ; MFT_INPUT_STATUS_ACCEPT_DATA
   {
      msgbox IMFTransform_GetInputStatus TransformVideo not accept data
      ExitApp
   }
   IMFTransform_ProcessMessage(pTransformVideo, MFT_MESSAGE_COMMAND_FLUSH := 0, 0)
   IMFTransform_ProcessMessage(pTransformVideo, MFT_MESSAGE_NOTIFY_BEGIN_STREAMING := 0x10000000, 0)
   IMFTransform_ProcessMessage(pTransformVideo, MFT_MESSAGE_NOTIFY_START_OF_STREAM := 0x10000003, 0)
   IMFSinkWriter_SetInputMediaType(pSinkWriter, videoStreamIndex, pMedia2, 0)
   Release(pMedia1)
   Release(pMedia2)
   pMedia1 := pMedia2 := &quot;&quot;
}
IMFSourceReader_SetCurrentMediaType(SourceReader, StreamNumberVideo, 0, pMediaTypeVideo1)
Release(pMediaTypeVideo1)
Release(pMediaTypeVideo2)
pMediaTypeVideo1 := pMediaTypeVideo2 := &quot;&quot;

if (StreamNumberAudio != &quot;&quot;)
{
   if (NUM_CHANNELSMax = 0)
      NUM_CHANNELS := 1
   else if (NUM_CHANNELSMax &gt; 2) and (NUM_CHANNELSMax &lt; 6)
      NUM_CHANNELS := 2
   else if (NUM_CHANNELSMax &gt;= 6)
   {
      if !InStr(A_OSVersion, &quot;W&quot;)
         NUM_CHANNELS := 6
      else
         NUM_CHANNELS := 2
   }
   if (SAMPLES_PER_SECONDMax &lt; 44100)
      SAMPLES_PER_SECOND := 44100
   else if (SAMPLES_PER_SECONDMax &gt; 44100)
      SAMPLES_PER_SECOND := 48000
   loop 2   ; 1 - input, 2 - output
   {
      MFCreateMediaType(pMediaTypeAudio%A_Index%)
      IMFAttributes_SetGUID(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Audio&quot;))
      if (A_Index = 1)
         IMFAttributes_SetGUID(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFAudioFormat_PCM&quot;))
      else
      {
         IMFAttributes_SetGUID(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFAudioFormat_AAC&quot;))
         IMFAttributes_SetUINT32(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_AVG_BYTES_PER_SECOND&quot;), 20000)
      }
      IMFAttributes_SetUINT32(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_BITS_PER_SAMPLE&quot;), 16)
      IMFAttributes_SetUINT32(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_SAMPLES_PER_SECOND&quot;), SAMPLES_PER_SECOND)
      IMFAttributes_SetUINT32(pMediaTypeAudio%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_NUM_CHANNELS&quot;), NUM_CHANNELS)
   }
   IMFSinkWriter_AddStream(pSinkWriter, pMediaTypeAudio2, audioStreamIndex)
   if (IMFSinkWriter_SetInputMediaType(pSinkWriter, audioStreamIndex, pMediaTypeAudio1, 0) = &quot;MF_E_INVALIDMEDIATYPE&quot;)
   {
      msgbox IMFSinkWriter_SetInputMediaType audio error
      ExitApp
   }
   if (IMFSourceReader_SetCurrentMediaType(SourceReader, StreamNumberAudio, 0, pMediaTypeAudio1) = &quot;MF_E_TOPO_CODEC_NOT_FOUND&quot;)
   {
      LOAD_DLL_Resampledmo_Mfaacenc()
      AudioTransform := 1
      cbOutBytesAudio := 100000
      loop 2   ; 1 - input, 2 - output
      {
         MFCreateMediaType(pMedia%A_Index%)
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Audio&quot;))
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, MFAudioFormat))
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_BITS_PER_SAMPLE&quot;), BITS_PER_SAMPLEMax)
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_NUM_CHANNELS&quot;), NUM_CHANNELSMax)
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_SAMPLES_PER_SECOND&quot;), SAMPLES_PER_SECONDMax)
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_BLOCK_ALIGNMENT&quot;), NUM_CHANNELSMax*BITS_PER_SAMPLEMax//8)
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_AUDIO_AVG_BYTES_PER_SECOND&quot;), SAMPLES_PER_SECONDMax*NUM_CHANNELSMax*BITS_PER_SAMPLEMax//8)
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_ALL_SAMPLES_INDEPENDENT&quot;), true)
         if (A_Index = 1)
            MFAudioFormat := &quot;MFAudioFormat_PCM&quot;, BITS_PER_SAMPLEMax := 16, NUM_CHANNELSMax := NUM_CHANNELS, SAMPLES_PER_SECONDMax := SAMPLES_PER_SECOND
      }
      spTransformUnk := ComObjCreate(CLSID_CResamplerMediaObject := &quot;{f447b69e-1884-4a7e-8055-346f74d6edb3}&quot;, IID_IUnknown := &quot;{00000000-0000-0000-C000-000000000046}&quot;)
      pTransformAudio := ComObjQuery(spTransformUnk, IID_IMFTransform := &quot;{bf94c121-5b05-4e6f-8000-ba598961414d}&quot;)
      spResamplerProps := ComObjQuery(spTransformUnk, IID_IWMResamplerProps := &quot;{E7E9984F-F09F-4da4-903F-6E2E0EFE56B5}&quot;)
      IWMResamplerProps_SetHalfFilterLength(spResamplerProps, 60)
      IMFTransform_SetInputType(pTransformAudio, 0, pMedia1, 0)
      IMFTransform_SetOutputType(pTransformAudio, 0, pMedia2, 0)
      IMFTransform_GetInputStatus(pTransformAudio, 0, mftStatus)
      if (mftStatus != 1)   ; MFT_INPUT_STATUS_ACCEPT_DATA
      {
         msgbox IMFTransform_GetInputStatus TransformAudio not accept data
         ExitApp
      }
      IMFTransform_ProcessMessage(pTransformAudio, MFT_MESSAGE_COMMAND_FLUSH := 0, 0)
      IMFTransform_ProcessMessage(pTransformAudio, MFT_MESSAGE_NOTIFY_BEGIN_STREAMING := 0x10000000, 0)
      IMFTransform_ProcessMessage(pTransformAudio, MFT_MESSAGE_NOTIFY_START_OF_STREAM := 0x10000003, 0)
      Release(pMedia1)
      Release(pMedia2)
      pMedia1 := pMedia2 := &quot;&quot;
   }
   Release(pMediaTypeAudio1)
   Release(pMediaTypeAudio2)
   pMediaTypeAudio1 := pMediaTypeAudio2 := &quot;&quot;
}
IMFSinkWriter_BeginWriting(pSinkWriter)

if (previewWindow = 1)
{
   previewWidthMax := WidthMax
   previewHeightMax := HeightMax
   MFCalculateImageSize(MF_GUID(GUID, &quot;MFVideoFormat_RGB32&quot;), previewWidthMax, previewHeightMax, cbOutBytesPreview)
   if (previewWindowWidth != &quot;&quot;)
   {
      if (previewHeightMax &gt;= previewWidthMax) and (previewWindowWidth &lt; 34)
         previewWindowWidth := 34
      else if (previewHeightMax &lt; previewWidthMax) and (previewWindowWidth/previewWidthMax*previewHeightMax &lt; 34)
         previewWindowWidth := ceil(34*previewWidthMax/previewHeightMax)
      if (mod(previewWindowWidth, 2) != 0)
         previewWindowWidth++
      previewHeightMax := ceil(previewHeightMax*previewWindowWidth/previewWidthMax)
      if (mod(previewHeightMax, 2) != 0)
         previewHeightMax++
      previewWidthMax := previewWindowWidth
      MFCalculateImageSize(MF_GUID(GUID, &quot;MFVideoFormat_RGB32&quot;), previewWidthMax, previewHeightMax, cbOutBytesPreview%previewWindowWidth%)
      LOAD_DLL_Vidreszr()
      loop 2   ; 1 - input, 2 - output
      {
         MFCreateMediaType(pMedia%A_Index%)
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Video&quot;))
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFVideoFormat_RGB32&quot;))
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_INTERLACE_MODE&quot;), INTERLACE_MODE)
         if (A_Index = 1)
            IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
         else
            IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), (previewWidthMax&lt;&lt;32)|previewHeightMax)
         IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
         IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_PIXEL_ASPECT_RATIO&quot;), ASPECT_RATIO)
      }
      pResizePreview := ComObjCreate(CLSID_CResizerDMO := &quot;{1ea1ea14-48f4-4054-ad1a-e8aee10ac805}&quot;, IID_IMFTransform := &quot;{bf94c121-5b05-4e6f-8000-ba598961414d}&quot;)
      IMFTransform_SetInputType(pResizePreview, 0, pMedia1, 0)
      IMFTransform_SetOutputType(pResizePreview, 0, pMedia2, 0)
      IMFTransform_GetInputStatus(pResizePreview, 0, mftStatus)
      if (mftStatus != 1)   ; MFT_INPUT_STATUS_ACCEPT_DATA
      {
         msgbox IMFTransform_GetInputStatus ResizePreview not accept data
         ExitApp
      }
      IMFTransform_ProcessMessage(pResizePreview, MFT_MESSAGE_COMMAND_FLUSH := 0, 0)
      IMFTransform_ProcessMessage(pResizePreview, MFT_MESSAGE_NOTIFY_BEGIN_STREAMING := 0x10000000, 0)
      IMFTransform_ProcessMessage(pResizePreview, MFT_MESSAGE_NOTIFY_START_OF_STREAM := 0x10000003, 0)
      Release(pMedia1)
      Release(pMedia2)
      pMedia1 := pMedia2 := &quot;&quot;
   }

   gui, new, hwndhGui
   gui, show, w%previewWidthMax% h%previewHeightMax%

   VarSetCapacity(D2D1_RENDER_TARGET_PROPERTIES, 28, 0)
   NumPut(DXGI_FORMAT_B8G8R8A8_UNORM := 87, D2D1_RENDER_TARGET_PROPERTIES, 4, &quot;int&quot;)   ; pixelFormat.format
   NumPut(D2D1_ALPHA_MODE_IGNORE := 3, D2D1_RENDER_TARGET_PROPERTIES, 8, &quot;int&quot;)   ; pixelFormat.alphaMode
   NumPut(D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE := 0x00000002, D2D1_RENDER_TARGET_PROPERTIES, 20, &quot;int&quot;)  ; usage

   VarSetCapacity(D2D1_HWND_RENDER_TARGET_PROPERTIES, 12+A_PtrSize, 0)
   NumPut(hGui, D2D1_HWND_RENDER_TARGET_PROPERTIES, 0, &quot;ptr&quot;)   ; hwnd
   NumPut(previewWidthMax, D2D1_HWND_RENDER_TARGET_PROPERTIES, A_PtrSize, &quot;uint&quot;)   ; pixelSize.width
   NumPut(previewHeightMax, D2D1_HWND_RENDER_TARGET_PROPERTIES, A_PtrSize+4, &quot;uint&quot;)   ; pixelSize.height

   VarSetCapacity(D2D1_BITMAP_PROPERTIES, 16, 0)
   NumPut(DXGI_FORMAT_B8G8R8A8_UNORM := 87, D2D1_BITMAP_PROPERTIES, 0, &quot;int&quot;)   ; pixelFormat.format
   NumPut(D2D1_ALPHA_MODE_IGNORE := 3, D2D1_BITMAP_PROPERTIES, 4, &quot;int&quot;)   ; pixelFormat.alphaMode

   LOAD_DLL_d2d1()
   D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED := 0, IID_ID2D1Factory := &quot;{06152247-6f50-465a-9245-118bfd3b6007}&quot;, 0, factory)
   ID2D1Factory_CreateHwndRenderTarget(factory, &amp;D2D1_RENDER_TARGET_PROPERTIES, &amp;D2D1_HWND_RENDER_TARGET_PROPERTIES, renderTarget)
   ID2D1HwndRenderTarget_CreateBitmap(renderTarget, previewWidthMax, previewHeightMax, 0, 0, &amp;D2D1_BITMAP_PROPERTIES, d2dBitmap)
   if (MemoryDifference(&amp;pguidValueSubType, MF_GUID(GUID, &quot;MFVideoFormat_RGB32&quot;), 16) != 0)
   {
      LOAD_DLL_Colorcnv()
      PreviewTransform := 1
      loop 2   ; 1 - input, 2 - output
      {
         MFCreateMediaType(pMedia%A_Index%)
         IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_MAJOR_TYPE&quot;), MF_GUID(GUID1, &quot;MFMediaType_Video&quot;))
         if (A_Index = 1)
            IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), &amp;pguidValueSubType)
         else
            IMFAttributes_SetGUID(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), MF_GUID(GUID1, &quot;MFVideoFormat_RGB32&quot;))
         IMFAttributes_SetUINT32(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_INTERLACE_MODE&quot;), INTERLACE_MODE)
         IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_SIZE&quot;), FRAME_SIZE)
         IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_FRAME_RATE&quot;), FRAME_RATE)
         IMFAttributes_SetUINT64(pMedia%A_Index%, MF_GUID(GUID, &quot;MF_MT_PIXEL_ASPECT_RATIO&quot;), ASPECT_RATIO)
      }
      pTransformPreview := ComObjCreate(CLSID_CColorConvertDMO := &quot;{98230571-0087-4204-b020-3282538e57d3}&quot;, IID_IMFTransform := &quot;{bf94c121-5b05-4e6f-8000-ba598961414d}&quot;)
      IMFTransform_SetInputType(pTransformPreview, 0, pMedia1, 0)
      IMFTransform_SetOutputType(pTransformPreview, 0, pMedia2, 0)
      IMFTransform_GetInputStatus(pTransformPreview, 0, mftStatus)
      if (mftStatus != 1)   ; MFT_INPUT_STATUS_ACCEPT_DATA
      {
         msgbox IMFTransform_GetInputStatus TransformPreview not accept data
         ExitApp
      }
      IMFTransform_ProcessMessage(pTransformPreview, MFT_MESSAGE_COMMAND_FLUSH := 0, 0)
      IMFTransform_ProcessMessage(pTransformPreview, MFT_MESSAGE_NOTIFY_BEGIN_STREAMING := 0x10000000, 0)
      IMFTransform_ProcessMessage(pTransformPreview, MFT_MESSAGE_NOTIFY_START_OF_STREAM := 0x10000003, 0)
      Release(pMedia1)
      Release(pMedia2)
      pMedia1 := pMedia2 := &quot;&quot;
   }
}

CaptureStart := start := &quot;&quot;
CaptureDuration := duration*1000
loop
{
   IMFSourceReader_ReadSample(SourceReader, MF_SOURCE_READER_ANY_STREAM := 0xFFFFFFFE, 0, ActualStreamIndex, StreamFlags, Timestamp, pSample)
   if (ActualStreamIndex = StreamNumberVideo)
   {
      ActualStreamIndex := videoStreamIndex
      ActualStream := &quot;Video&quot;
   }
   else
   {
      ActualStreamIndex := audioStreamIndex
      ActualStream := &quot;Audio&quot;
   }
   if (CaptureStart = &quot;&quot;) and (pSample != 0) and (ActualStreamIndex = videoStreamIndex)
   {
      CaptureStart := 1
      TimestampStart := Timestamp
      start := A_TickCount
   }
   if CaptureStart
   {
      if (pSample != 0)
      {
         if (gap%ActualStreamIndex% = 1)
         {
            IMFAttributes_SetUINT32(pSample, MF_GUID(GUID, &quot;MFSampleExtension_Discontinuity&quot;), true)
            gap%ActualStreamIndex% := &quot;&quot;
         }
         IMFSample_SetSampleTime(pSample, Timestamp - TimestampStart)
         if ((VideoTransform = 1) and (ActualStreamIndex = videoStreamIndex)) or ((AudioTransform = 1) and (ActualStreamIndex = audioStreamIndex))
         {
            IMFSample_GetSampleDuration(pSample, llSampleDuration)
            loop
            {
               if (IMFTransform_ProcessInput(pTransform%ActualStream%, 0, pSample, 0) != &quot;MF_E_INVALIDREQUEST&quot;)
                  break
            }
            MFCreateSample(pSample1)
            VarSetCapacity(MFT_OUTPUT_DATA_BUFFER, 4*A_PtrSize, 0)
            NumPut(pSample1, MFT_OUTPUT_DATA_BUFFER, A_PtrSize, &quot;ptr&quot;)
            MFCreateMemoryBuffer(cbOutBytes%ActualStream%, pBuffer1)
            IMFSample_AddBuffer(pSample1, pBuffer1)
            IMFTransform_ProcessOutput(pTransform%ActualStream%, 0, 1, &amp;MFT_OUTPUT_DATA_BUFFER, processOutputStatus)
            if (ActualStreamIndex = videoStreamIndex) and (DEFAULT_STRIDE &lt; 0)
            {
               MFCreateMemoryBuffer(cbOutBytesVideo, pBuffer2)
               loop 2
                  IMFMediaBuffer_Lock(pBuffer%A_Index%, pData%A_Index%, 0, 0)
               MFCopyImage(pData2, WidthMax*2, pData1+(HeightMax-1)*WidthMax*2, WidthMax*-2, WidthMax*2, HeightMax)
               loop 2
                  IMFMediaBuffer_Unlock(pBuffer%A_Index%)
               IMFMediaBuffer_SetCurrentLength(pBuffer2, cbOutBytesVideo)
               MFCreateSample(pSample2)
               IMFSample_AddBuffer(pSample2, pBuffer2)
               IMFSample_SetSampleTime(pSample2, Timestamp - TimestampStart)
               IMFSample_SetSampleDuration(pSample2, llSampleDuration)
               IMFSinkWriter_WriteSample(pSinkWriter, ActualStreamIndex, pSample2)
               Release(pSample2)
               Release(pBuffer2)
               pSample2 := pBuffer2 := &quot;&quot;
            }
            else
            {
               IMFSample_SetSampleTime(pSample1, Timestamp - TimestampStart)
               IMFSample_SetSampleDuration(pSample1, llSampleDuration)
               IMFSinkWriter_WriteSample(pSinkWriter, ActualStreamIndex, pSample1)
            }
            Release(pSample1)
            Release(pBuffer1)
            pSample1 := pBuffer1 := &quot;&quot;
         }
         else
            IMFSinkWriter_WriteSample(pSinkWriter, ActualStreamIndex, pSample)
         if (previewWindow = 1) and (ActualStreamIndex = videoStreamIndex)
         {
            if (PreviewTransform = 1)
            {
               loop
               {
                  if (IMFTransform_ProcessInput(pTransformPreview, 0, pSample, 0) != &quot;MF_E_INVALIDREQUEST&quot;)
                     break
               }
               MFCreateSample(pSample1)
               VarSetCapacity(MFT_OUTPUT_DATA_BUFFER, 4*A_PtrSize, 0)
               NumPut(pSample1, MFT_OUTPUT_DATA_BUFFER, A_PtrSize, &quot;ptr&quot;)
               MFCreateMemoryBuffer(cbOutBytesPreview, pBuffer)
               IMFSample_AddBuffer(pSample1, pBuffer)
               IMFTransform_ProcessOutput(pTransformPreview, 0, 1, &amp;MFT_OUTPUT_DATA_BUFFER, processOutputStatus)
            }
            if (previewWindowWidth != &quot;&quot;)
            {
               loop
               {
                  if (IMFTransform_ProcessInput(pResizePreview, 0, pSample%PreviewTransform%, 0) != &quot;MF_E_INVALIDREQUEST&quot;)
                     break
               }
               MFCreateSample(pSample2)
               VarSetCapacity(MFT_OUTPUT_DATA_BUFFER, 4*A_PtrSize, 0)
               NumPut(pSample2, MFT_OUTPUT_DATA_BUFFER, A_PtrSize, &quot;ptr&quot;)
               MFCreateMemoryBuffer(cbOutBytesPreview%previewWindowWidth%, pBuffer%previewWindowWidth%)
               IMFSample_AddBuffer(pSample2, pBuffer%previewWindowWidth%)
               IMFTransform_ProcessOutput(pResizePreview, 0, 1, &amp;MFT_OUTPUT_DATA_BUFFER, processOutputStatus)
            }
            if (previewWindowWidth = &quot;&quot;) and (PreviewTransform = &quot;&quot;)
               IMFSample_GetBufferByIndex(pSample, 0, pBuffer)
            IMFMediaBuffer_Lock(pBuffer%previewWindowWidth%, pData, 0, 0)
            if (DEFAULT_STRIDE &lt; 0)
            {
               MFCreateMemoryBuffer(cbOutBytesPreview%previewWindowWidth%, pBuffer1)
               IMFMediaBuffer_Lock(pBuffer1, pData1, 0, 0)
               MFCopyImage(pData1, previewWidthMax*4, pData+(previewHeightMax-1)*previewWidthMax*4, previewWidthMax*-4, previewWidthMax*4, previewHeightMax)
               ID2D1Bitmap_CopyFromMemory(d2dBitmap, 0, pData1, previewWidthMax*4)
               IMFMediaBuffer_Unlock(pBuffer1)
               Release(pBuffer1)
               pBuffer1 := &quot;&quot;
            }
            else
               ID2D1Bitmap_CopyFromMemory(d2dBitmap, 0, pData, previewWidthMax*4)
            ID2D1HwndRenderTarget_BeginDraw(renderTarget)
            ID2D1HwndRenderTarget_DrawBitmap(renderTarget, d2dBitmap, 0, 1, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR := 0, 0)
            ID2D1HwndRenderTarget_EndDraw(renderTarget)
            IMFMediaBuffer_Unlock(pBuffer%previewWindowWidth%)
            Release(pBuffer%previewWindowWidth%)
            pBuffer%previewWindowWidth% := &quot;&quot;
            if (pBuffer != &quot;&quot;)
            {
               Release(pBuffer)
               pBuffer := &quot;&quot;
            }
            loop 2
            {
               if (pSample%A_Index% != &quot;&quot;)
               {
                  Release(pSample%A_Index%)
                  pSample%A_Index% := &quot;&quot;
               }
            }
         }
      }
      else if (StreamFlags &amp; MF_SOURCE_READERF_STREAMTICK := 256)
      {
         IMFSinkWriter_SendStreamTick(pSinkWriter, ActualStreamIndex, Timestamp - TimestampStart)
         gap%ActualStreamIndex% := 1
      }
   }
   if (pSample != 0)
   {
      Release(pSample)
      pSample := &quot;&quot;
   }
   if ((A_TickCount - start) &gt;= CaptureDuration)
      break
}
IMFSinkWriter_Finalize(pSinkWriter)
IMFMediaSource_Shutdown(MediaSourceVideo)
Release(MediaSourceVideo)
if (VideoTransform = 1)
{
   Release(pTransformVideo)
   pTransformVideo := VideoTransform := &quot;&quot;
}
if (audiodevice != &quot;&quot;)
{
   if (AudioTransform = 1)
   {
      Release(spResamplerProps)
      Release(pTransformAudio)
      Release(spTransformUnk)
      spResamplerProps := pTransformAudio := spTransformUnk := AudioTransform := &quot;&quot;
   }
   IMFMediaSource_Shutdown(MediaSourceAudio)
   IMFMediaSource_Shutdown(AggSource)
   Release(MediaSourceAudio)
   Release(AggSource)
   MediaSourceAudio := AggSource := &quot;&quot;
}
if (previewWindow = 1)
{
   if (PreviewTransform = 1)
   {
      Release(pTransformPreview)
      pTransformPreview := PreviewTransform := &quot;&quot;
   }
   Release(factory)
   Release(renderTarget)
   Release(d2dBitmap)
   factory := renderTarget := d2dBitmap := &quot;&quot;
}
Release(SourceReader)
Release(pSinkWriter)
SourceReader := MediaSourceVideo := pSinkWriter := &quot;&quot;
MFShutdown()
msgbox done
ExitApp





LOAD_DLL_Mf_Mfplat_Mfreadwrite()
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Mf&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Mf.dll&quot;, &quot;ptr&quot;)
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Mfplat&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Mfplat.dll&quot;, &quot;ptr&quot;)
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Mfreadwrite&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Mfreadwrite.dll&quot;, &quot;ptr&quot;)
}

MFStartup(version, dwFlags)
{
   hr := DllCall(&quot;Mfplat.dll\MFStartup&quot;, &quot;uint&quot;, version, &quot;uint&quot;, dwFlags)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFShutdown()
{
   hr := DllCall(&quot;Mfplat.dll\MFShutdown&quot;)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFTEnumEx(guidCategory, Flags, pInputType, pOutputType)
{
   if (A_PtrSize = 8)
      hr := DllCall(&quot;Mfplat\MFTEnumEx&quot;, &quot;ptr&quot;, guidCategory, &quot;uint&quot;, Flags, &quot;ptr&quot;, pInputType, &quot;ptr&quot;, pOutputType, &quot;ptr*&quot;, pppMFTActivate, &quot;uint*&quot;, pnumMFTActivate)
   else
      hr := DllCall(&quot;Mfplat\MFTEnumEx&quot;, &quot;uint64&quot;, NumGet(guidCategory+0, 0, &quot;uint64&quot;), &quot;uint64&quot;, NumGet(guidCategory+0, 8, &quot;uint64&quot;), &quot;uint&quot;, Flags, &quot;ptr&quot;, pInputType, &quot;ptr&quot;, pOutputType, &quot;ptr*&quot;, pppMFTActivate, &quot;uint*&quot;, pnumMFTActivate)
   loop % pnumMFTActivate
   {
      IMFActivate := NumGet(pppMFTActivate + (A_Index - 1)*A_PtrSize)
      if (A_Index = 1)
         hardware_encoder := IMFActivate_GetAllocatedString(IMFActivate, MF_GUID(GUID, &quot;MFT_FRIENDLY_NAME_Attribute&quot;))
      Release(IMFActivate)
   }
   DllCall(&quot;ole32\CoTaskMemFree&quot;, &quot;ptr&quot;, pppMFTActivate)
   return hardware_encoder
}

MFCreateSinkWriterFromURL(pwszOutputURL, pByteStream, pAttributes, ByRef ppSinkWriter)
{
   hr := DllCall(&quot;Mfreadwrite.dll\MFCreateSinkWriterFromURL&quot;, &quot;str&quot;, pwszOutputURL, &quot;ptr&quot;, pByteStream, &quot;ptr&quot;, pAttributes, &quot;ptr*&quot;, ppSinkWriter)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateSourceReaderFromMediaSource(pMediaSource, pAttributes, ByRef ppSourceReader)
{
   hr := DllCall(&quot;Mfreadwrite.dll\MFCreateSourceReaderFromMediaSource&quot;, &quot;ptr&quot;, pMediaSource, &quot;ptr&quot;, pAttributes, &quot;ptr*&quot;, ppSourceReader)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateMediaType(ByRef ppMFType)
{
   hr := DllCall(&quot;Mfplat.dll\MFCreateMediaType&quot;, &quot;ptr*&quot;, ppMFType)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateAttributes(ByRef ppMFAttributes, cInitialSize)
{
   hr := DllCall(&quot;Mfplat.dll\MFCreateAttributes&quot;, &quot;ptr*&quot;, ppMFAttributes, &quot;uint&quot;, cInitialSize)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateSample(ByRef ppIMFSample)
{
   hr := DllCall(&quot;Mfplat.dll\MFCreateSample&quot;, &quot;ptr*&quot;, ppIMFSample)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateMemoryBuffer(cbMaxLength, ByRef ppBuffer)
{
   hr := DllCall(&quot;Mfplat.dll\MFCreateMemoryBuffer&quot;, &quot;uint&quot;, cbMaxLength, &quot;ptr*&quot;, ppBuffer)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
{
   hr := DllCall(&quot;Mfplat.dll\MFCopyImage&quot;, &quot;ptr&quot;, pDest, &quot;int&quot;, lDestStride, &quot;ptr&quot;, pSrc, &quot;int&quot;, lSrcStride, &quot;uint&quot;, dwWidthInBytes, &quot;uint&quot;, dwLines)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFEnumDeviceSources(pAttributes, ByRef pppSourceActivate, ByRef pcSourceActivate)
{
   hr := DllCall(&quot;Mf.dll\MFEnumDeviceSources&quot;, &quot;ptr&quot;, pAttributes, &quot;ptr*&quot;, pppSourceActivate, &quot;uint*&quot;, pcSourceActivate)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateCollection(ByRef ppIMFCollection)
{
   hr := DllCall(&quot;Mfplat.dll\MFCreateCollection&quot;, &quot;ptr*&quot;, ppIMFCollection)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCreateAggregateSource(pSourceCollection, ByRef ppAggSource)
{
   hr := DllCall(&quot;Mf.dll\MFCreateAggregateSource&quot;, &quot;ptr&quot;, pSourceCollection, &quot;ptr*&quot;, ppAggSource)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSourceReader_SetCurrentMediaType(this, dwStreamIndex, pdwReserved, pMediaType)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;uint&quot;, pdwReserved, &quot;ptr&quot;, pMediaType)
   if hr or ErrorLevel
   {
      if !ErrorLevel
      {
         if ((hr&amp;=0xFFFFFFFF) = 0xC00D5212)   ; MF_E_TOPO_CODEC_NOT_FOUND
            return &quot;MF_E_TOPO_CODEC_NOT_FOUND&quot;
      }
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   }
}

IMFSourceReader_SetStreamSelection(this, dwStreamIndex, fSelected)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;int&quot;, fSelected)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSourceReader_GetNativeMediaType(this, dwStreamIndex, dwMediaTypeIndex, ByRef ppMediaType)
{
   hr := DllCall(NumGet(NumGet(this+0)+5*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;uint&quot;, dwMediaTypeIndex, &quot;ptr*&quot;, ppMediaType)
   if hr or ErrorLevel
   {
      if !ErrorLevel
      {
         if (hr&amp;=0xFFFFFFFF) = 0xC00D36B3   ; MF_E_INVALIDSTREAMNUMBER
            return &quot;MF_E_INVALIDSTREAMNUMBER&quot;
         if (hr&amp;=0xFFFFFFFF) = 0xC00D36B9   ; MF_E_NO_MORE_TYPES
            return &quot;MF_E_NO_MORE_TYPES&quot;
      }
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   }
}

IMFSourceReader_ReadSample(this, dwStreamIndex, dwControlFlags, ByRef pdwActualStreamIndex, ByRef pdwStreamFlags, ByRef pllTimestamp, ByRef ppSample)
{
   hr := DllCall(NumGet(NumGet(this+0)+9*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;uint&quot;, dwControlFlags, &quot;uint*&quot;, pdwActualStreamIndex, &quot;uint*&quot;, pdwStreamFlags, &quot;int64*&quot;, pllTimestamp, &quot;ptr*&quot;, ppSample)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFAttributes_GetGUID(this, guidKey, ByRef pguidValue)
{
   VarSetCapacity(pguidValue, 16, 0)
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;ptr&quot;, &amp;pguidValue)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   return &amp;pguidValue
}

IMFAttributes_GetUINT64(this, guidKey, ByRef punValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+8*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;uint64*&quot;, punValue)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFAttributes_GetUINT32(this, guidKey, ByRef punValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;uint*&quot;, punValue)
   if hr or ErrorLevel
   {
      if !ErrorLevel
      {
         if (hr&amp;=0xFFFFFFFF) = 0xC00D36E6   ; MF_E_ATTRIBUTENOTFOUND
            return &quot;MF_E_ATTRIBUTENOTFOUND&quot;
      }
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   }
}

IMFAttributes_SetUINT32(this, guidKey, unValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+21*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;uint&quot;, unValue)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFAttributes_SetUINT64(this, guidKey, unValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+22*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;uint64&quot;, unValue)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFAttributes_SetGUID(this, guidKey, guidValue)
{
   hr := DllCall(NumGet(NumGet(this+0)+24*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;ptr&quot;, guidValue)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFAttributes_CopyAllItems(this, pDest)
{
   hr := DllCall(NumGet(NumGet(this+0)+32*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, pDest)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFActivate_GetAllocatedString(this, guidKey)
{
   hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, guidKey, &quot;ptr*&quot;, ppwszValue, &quot;uint*&quot;, pcchLength)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   AllocatedString := StrGet(ppwszValue, pcchLength, &quot;UTF-16&quot;)
   DllCall(&quot;ole32\CoTaskMemFree&quot;, &quot;ptr&quot;, ppwszValue)
   return AllocatedString
}

IMFActivate_ActivateObject(this, riid, ByRef ppv)
{
   GUID(riid, riid)
   hr := DllCall(NumGet(NumGet(this+0)+33*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, &amp;riid, &quot;ptr*&quot;, ppv)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSinkWriter_SendStreamTick(this, dwStreamIndex, llTimestamp)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;int64&quot;, llTimestamp)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSinkWriter_AddStream(this, pMediaTypeOut, ByRef pdwStreamIndex)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, pMediaTypeOut, &quot;ptr*&quot;, pdwStreamIndex)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSinkWriter_SetInputMediaType(this, dwStreamIndex, pInputMediaType, pEncodingParameters)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;ptr&quot;, pInputMediaType, &quot;ptr&quot;, pEncodingParameters)
   if hr or ErrorLevel
   {
      if !ErrorLevel
      {
         if (hr&amp;=0xFFFFFFFF) = 0xC00D36B4   ; MF_E_INVALIDMEDIATYPE
            return &quot;MF_E_INVALIDMEDIATYPE&quot;
      }
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   }
}

IMFSinkWriter_BeginWriting(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+5*A_PtrSize), &quot;ptr&quot;, this)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSinkWriter_WriteSample(this, dwStreamIndex, pSample)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwStreamIndex, &quot;ptr&quot;, pSample)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSinkWriter_Finalize(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+11*A_PtrSize), &quot;ptr&quot;, this)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFMediaBuffer_Lock(this, ByRef ppbBuffer, ByRef pcbMaxLength, ByRef pcbCurrentLength)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr*&quot;, ppbBuffer, &quot;uint*&quot;, pcbMaxLength, &quot;uint*&quot;, pcbCurrentLength)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFMediaBuffer_Unlock(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), &quot;ptr&quot;, this)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFMediaBuffer_SetCurrentLength(this, cbCurrentLength)
{
   hr := DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, cbCurrentLength)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFMediaSource_Shutdown(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+12*A_PtrSize), &quot;ptr&quot;, this)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSample_AddBuffer(this, pBuffer)
{
   hr := DllCall(NumGet(NumGet(this+0)+42*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, pBuffer)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSample_GetBufferByIndex(this, dwIndex, ByRef ppBuffer)
{
   hr := DllCall(NumGet(NumGet(this+0)+40*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwIndex, &quot;ptr*&quot;, ppBuffer)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSample_SetSampleTime(this, hnsSampleTime)
{
   hr := DllCall(NumGet(NumGet(this+0)+36*A_PtrSize), &quot;ptr&quot;, this, &quot;int64&quot;, hnsSampleTime)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSample_GetSampleDuration(this, ByRef phnsSampleDuration)
{
   hr := DllCall(NumGet(NumGet(this+0)+37*A_PtrSize), &quot;ptr&quot;, this, &quot;int64*&quot;, phnsSampleDuration)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFSample_SetSampleDuration(this, hnsSampleDuration)
{
   hr := DllCall(NumGet(NumGet(this+0)+38*A_PtrSize), &quot;ptr&quot;, this, &quot;int64&quot;, hnsSampleDuration)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFCollection_AddElement(this, pUnkElement)
{
   hr := DllCall(NumGet(NumGet(this+0)+5*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, pUnkElement)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

LOAD_DLL_Resampledmo_Mfaacenc()
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Resampledmo&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Resampledmo.dll&quot;, &quot;ptr&quot;)
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Mfaacenc&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Mfaacenc.dll&quot;, &quot;ptr&quot;)
}

IMFTransform_GetInputStatus(this, dwInputStreamID, ByRef pdwFlags)
{
   hr := DllCall(NumGet(NumGet(this+0)+19*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwInputStreamID, &quot;uint*&quot;, pdwFlags)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFTransform_ProcessMessage(this, eMessage, ulParam)
{
   hr := DllCall(NumGet(NumGet(this+0)+23*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, eMessage, &quot;uint&quot;, ulParam)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFTransform_ProcessOutput(this, dwFlags, cOutputBufferCount, pOutputSamples, ByRef pdwStatus)
{
   hr := DllCall(NumGet(NumGet(this+0)+25*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwFlags, &quot;uint&quot;, cOutputBufferCount, &quot;ptr&quot;, pOutputSamples, &quot;uint*&quot;, pdwStatus)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFTransform_ProcessInput(this, dwInputStreamID, pSample, dwFlags)
{
   hr := DllCall(NumGet(NumGet(this+0)+24*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwInputStreamID, &quot;ptr&quot;, pSample, &quot;uint&quot;, dwFlags)
   if hr or ErrorLevel
   {
      if !ErrorLevel
      {
         if (hr&amp;=0xFFFFFFFF) = 0xC00D36B2   ; MF_E_INVALIDREQUEST
            return &quot;MF_E_INVALIDREQUEST&quot;
      }
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
   }
}

IMFTransform_GetOutputStreamInfo(this, dwInputStreamID, pStreamInfo)
{
   hr := DllCall(NumGet(NumGet(this+0)+7*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwInputStreamID, &quot;ptr&quot;, pStreamInfo)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFTransform_SetOutputType(this, dwInputStreamID, pType, dwFlags)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwInputStreamID, &quot;ptr&quot;, pType, &quot;uint&quot;, dwFlags)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMFTransform_SetInputType(this, dwInputStreamID, pType, dwFlags)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), &quot;ptr&quot;, this, &quot;uint&quot;, dwInputStreamID, &quot;ptr&quot;, pType, &quot;uint&quot;, dwFlags)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IWMResamplerProps_SetHalfFilterLength(this, lhalfFilterLen)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), &quot;ptr&quot;, this, &quot;int&quot;, lhalfFilterLen)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IMF2DBuffer2_Lock2D(this, ByRef ppbScanline0, ByRef plPitch)
{
   hr := DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr*&quot;, ppbScanline0, &quot;int*&quot;, plPitch)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFGetStrideForBitmapInfoHeader(format, dwWidth, ByRef pStride)
{
   hr := DllCall(&quot;Mfplat.dll\MFGetStrideForBitmapInfoHeader&quot;, &quot;uint&quot;, format, &quot;uint&quot;, dwWidth, &quot;int*&quot;, pStride)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MFCalculateImageSize(guidSubtype, unWidth, unHeight, ByRef pcbImageSize)
{
   hr := DllCall(&quot;Mfplat.dll\MFCalculateImageSize&quot;, &quot;ptr&quot;, guidSubtype, &quot;uint&quot;, unWidth, &quot;uint&quot;, unHeight, &quot;uint*&quot;, pcbImageSize)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MF_GUID(ByRef GUID, name)
{
   static init:=1, _:={}
   if init
   {
      init:=0
      _.MF_MT_MAJOR_TYPE := [0x48eba18e, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f]
      _.MF_MT_SUBTYPE := [0xf7e34c9a, 0x42e8, 0x4714, 0xb7, 0x4b, 0xcb, 0x29, 0xd7, 0x2c, 0x35, 0xe5]
      _.MF_MT_AVG_BITRATE := [0x20332624, 0xfb0d, 0x4d9e, 0xbd, 0x0d, 0xcb, 0xf6, 0x78, 0x6c, 0x10, 0x2e]
      _.MF_MT_INTERLACE_MODE := [0xe2724bb8, 0xe676, 0x4806, 0xb4, 0xb2, 0xa8, 0xd6, 0xef, 0xb4, 0x4c, 0xcd]
      _.MF_MT_FRAME_SIZE := [0x1652c33d, 0xd6b2, 0x4012, 0xb8, 0x34, 0x72, 0x03, 0x08, 0x49, 0xa3, 0x7d]
      _.MF_MT_FRAME_RATE := [0xc459a2e8, 0x3d2c, 0x4e44, 0xb1, 0x32, 0xfe, 0xe5, 0x15, 0x6c, 0x7b, 0xb0]
      _.MF_MT_PIXEL_ASPECT_RATIO := [0xc6376a1e, 0x8d0a, 0x4027, 0xbe, 0x45, 0x6d, 0x9a, 0x0a, 0xd3, 0x9b, 0xb6]
      _.MF_MT_AUDIO_AVG_BYTES_PER_SECOND := [0x1aab75c8, 0xcfef, 0x451c, 0xab, 0x95, 0xac, 0x03, 0x4b, 0x8e, 0x17, 0x31]
      _.MF_MT_AUDIO_BLOCK_ALIGNMENT := [0x322de230, 0x9eeb, 0x43bd, 0xab, 0x7a, 0xff, 0x41, 0x22, 0x51, 0x54, 0x1d]
      _.MF_MT_AUDIO_SAMPLES_PER_SECOND := [0x5faeeae7, 0x0290, 0x4c31, 0x9e, 0x8a, 0xc5, 0x34, 0xf6, 0x8d, 0x9d, 0xba]
      _.MF_MT_AUDIO_BITS_PER_SAMPLE := [0xf2deb57f, 0x40fa, 0x4764, 0xaa, 0x33, 0xed, 0x4f, 0x2d, 0x1f, 0xf6, 0x69]
      _.MF_MT_AUDIO_NUM_CHANNELS := [0x37e48bf5, 0x645e, 0x4c5b, 0x89, 0xde, 0xad, 0xa9, 0xe2, 0x9b, 0x69, 0x6a]
      _.MFT_CATEGORY_VIDEO_ENCODER := [0xf79eac7d, 0xe545, 0x4387, 0xbd, 0xee, 0xd6, 0x47, 0xd7, 0xbd, 0xe4, 0x2a]
      _.MF_TRANSCODE_CONTAINERTYPE := [0x150ff23f, 0x4abc, 0x478b, 0xac, 0x4f, 0xe1, 0x91, 0x6f, 0xba, 0x1c, 0xca]
      _.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS := [0xa634a91c, 0x822b, 0x41b9, 0xa4, 0x94, 0x4d, 0xe4, 0x64, 0x36, 0x12, 0xb0]
      _.MFTranscodeContainerType_MPEG4 := [0xdc6cd05d, 0xb9d0, 0x40ef, 0xbd, 0x35, 0xfa, 0x62, 0x2c, 0x1a, 0xb2, 0x8a]
      _.MFT_FRIENDLY_NAME_Attribute := [0x314ffbae, 0x5b41, 0x4c95, 0x9c, 0x19, 0x4e, 0x7d, 0x58, 0x6f, 0xac, 0xe3]
      _.MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME := [0x60d0e559, 0x52f8, 0x4fa2, 0xbb, 0xce, 0xac, 0xdb, 0x34, 0xa8, 0xec, 0x1]
      _.MF_SINK_WRITER_DISABLE_THROTTLING := [0x08b845d8, 0x2b74, 0x4afe, 0x9d, 0x53, 0xbe, 0x16, 0xd2, 0xd5, 0xae, 0x4f]
      _.MF_LOW_LATENCY := [0x9c27891a, 0xed7a, 0x40e1, 0x88, 0xe8, 0xb2, 0x27, 0x27, 0xa0, 0x24, 0xee]
      _.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE := [0xc60ac5fe, 0x252a, 0x478f, 0xa0, 0xef, 0xbc, 0x8f, 0xa5, 0xf7, 0xca, 0xd3]
      _.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID := [0x14dd9a1c, 0x7cff, 0x41be, 0xb1, 0xb9, 0xba, 0x1a, 0xc6, 0xec, 0xb5, 0x71]
      _.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID := [0x8ac3587a, 0x4ae7, 0x42d8, 0x99, 0xe0, 0x0a, 0x60, 0x13, 0xee, 0xf9, 0x0f]
      _.MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN := [0x56b67165, 0x219e, 0x456d, 0xa2, 0x2e, 0x2d, 0x30, 0x04, 0xc7, 0xfe, 0x56]
      _.MF_MT_ALL_SAMPLES_INDEPENDENT := [0xc9173739, 0x5e56, 0x461c, 0xb7, 0x13, 0x46, 0xfb, 0x99, 0x5c, 0xb9, 0x5f]
      _.MF_MT_DEFAULT_STRIDE := [0x644b4e48, 0x1e02, 0x4516, 0xb0, 0xeb, 0xc0, 0x1c, 0xa9, 0xd4, 0x9a, 0xc6]
      _.MFSampleExtension_Discontinuity := [0x9cdf01d9, 0xa0f0, 0x43ba, 0xb0, 0x77, 0xea, 0xa0, 0x6c, 0xbd, 0x72, 0x8a]
      _.MFMediaType_Video := [0x73646976, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFMediaType_Audio := [0x73647561, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71]
      _.MFAudioFormat_AAC := [0x1610, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFAudioFormat_Float := [0x0003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFAudioFormat_PCM := [0x0001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_H264 := [0x34363248, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]   ; FCC(&quot;H264&quot;) = 0x34363248
      _.MFVideoFormat_I420 := [0x30323449, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_IYUV := [0x56555949, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_NV12 := [0x3231564E, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_YUY2 := [0x32595559, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_YV12 := [0x32315659, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_RGB24 := [0x00000014, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_RGB32 := [0x00000016, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_ARGB32 := [0x00000015, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_RGB555 := [0x00000018, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_RGB565 :=	[0x00000017, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_RGB8 := [0x00000029, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_AYUV := [0x56555941, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_NV11 := [0x3131564e, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_UYVY := [0x59565955, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_V216 := [0x36313276, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_V410 := [0x30313476, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_Y41P := [0x50313459, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_Y41T := [0x54313459, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_Y42T := [0x54323459, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_YVU9 := [0x39555659, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
      _.MFVideoFormat_YVYU := [0x55595659, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71]
   }
   if _.haskey(name)
   {
      p := _[name]
      VarSetCapacity(GUID,16)
      ,NumPut(p.1+(p.2&lt;&lt;32)+(p.3&lt;&lt;48),GUID,0,&quot;int64&quot;)
      ,NumPut(p.4+(p.5&lt;&lt;8)+(p.6&lt;&lt;16)+(p.7&lt;&lt;24)+(p.8&lt;&lt;32)+(p.9&lt;&lt;40)+(p.10&lt;&lt;48)+(p.11&lt;&lt;56),GUID,8,&quot;int64&quot;)
      return &amp;GUID
   }
   else return name
}

GUID(ByRef GUID, sGUID)
{
    VarSetCapacity(GUID, 16, 0)
    return DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;WStr&quot;, sGUID, &quot;Ptr&quot;, &amp;GUID) &gt;= 0 ? &amp;GUID : &quot;&quot;
}

FCC(var)
{
   c := StrSplit(var)
   msgbox % clipboard := Format(&quot;{:#x}&quot;,((Asc(c[1])&amp;255)+((Asc(c[2])&amp;255)&lt;&lt;8)+((Asc(c[3])&amp;255)&lt;&lt;16)+((Asc(c[4])&amp;255)&lt;&lt;24)))
}

Release(this)
{
   DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), &quot;ptr&quot;, this)
   if ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

MemoryDifference(ptr1, ptr2, num)
{
   return DllCall(&quot;msvcrt\memcmp&quot;, &quot;ptr&quot;, ptr1, &quot;ptr&quot;, ptr2, &quot;int&quot;, num) 
}

_Error(val)
{
   msgbox % val
   ExitApp
}

LOAD_DLL_Colorcnv()
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Colorcnv&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Colorcnv.dll&quot;, &quot;ptr&quot;)
}

LOAD_DLL_Vidreszr()
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;Vidreszr&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;Vidreszr.dll&quot;, &quot;ptr&quot;)
}

LOAD_DLL_d2d1()
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;d2d1&quot;)
      DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;, &quot;d2d1.dll&quot;, &quot;ptr&quot;)
}

D2D1CreateFactory(factoryType, riid, pFactoryOptions, ByRef ppIFactory)
{
   hr := DllCall(&quot;d2d1\D2D1CreateFactory&quot;, &quot;uint&quot;, factoryType, &quot;ptr&quot;, GUID(CLSID, riid), &quot;ptr&quot;, pFactoryOptions, &quot;ptr*&quot;, ppIFactory)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID2D1Factory_CreateHwndRenderTarget(this, renderTargetProperties, hwndRenderTargetProperties, ByRef hwndRenderTarget)
{
   hr := DllCall(NumGet(NumGet(this+0)+14*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, renderTargetProperties, &quot;ptr&quot;, hwndRenderTargetProperties, &quot;ptr*&quot;, hwndRenderTarget)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID2D1HwndRenderTarget_CreateBitmap(this, width, height, srcData, pitch, bitmapProperties, ByRef bitmap)
{
   hr := DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), &quot;ptr&quot;, this, &quot;int64&quot;, (height &lt;&lt; 32) | width, &quot;ptr&quot;, srcData, &quot;uint&quot;, pitch, &quot;ptr&quot;, bitmapProperties, &quot;ptr*&quot;, bitmap)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID2D1Bitmap_CopyFromMemory(this, dstRect, srcData, pitch)
{
   hr := DllCall(NumGet(NumGet(this+0)+10*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, dstRect, &quot;ptr&quot;, srcData, &quot;uint&quot;, pitch)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID2D1HwndRenderTarget_BeginDraw(this)
{
   DllCall(NumGet(NumGet(this+0)+48*A_PtrSize), &quot;ptr&quot;, this)
   if ErrorLevel
      _Error(A_ThisFunc &quot; ErrorLevel: &quot; ErrorLevel)
}

ID2D1HwndRenderTarget_EndDraw(this)
{
   hr := DllCall(NumGet(NumGet(this+0)+49*A_PtrSize), &quot;ptr&quot;, this, &quot;uint64*&quot;, tag1, &quot;uint64*&quot;, tag2)
   if hr or ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`ntag1: &quot; tag1 &quot;`ntag2: &quot; tag2 &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID2D1HwndRenderTarget_DrawBitmap(this, bitmap, destinationRectangle, opacity, interpolationMode, sourceRectangle)
{
   hr := DllCall(NumGet(NumGet(this+0)+26*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, bitmap, &quot;ptr&quot;, destinationRectangle, &quot;float&quot;, opacity, &quot;uint&quot;, interpolationMode, &quot;ptr&quot;, sourceRectangle)
   if ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}


/*
; test IMFTransform::GetOutputAvailableType
loop
{
   if (DllCall(NumGet(NumGet(pTransformVideo+0)+14*A_PtrSize), &quot;ptr&quot;, pTransformVideo, &quot;uint&quot;, 0, &quot;uint&quot;, A_Index -1, &quot;ptr*&quot;, ppType) = 0)   ; IMFTransform::GetOutputAvailableType
   {
      IMFAttributes_GetGUID(ppType, MF_GUID(GUID, &quot;MF_MT_SUBTYPE&quot;), pguidValueSubType)
      if (numget(pguidValueSubType, 0, &quot;int&quot;) = 0x32595559)   ; MFVideoFormat_YUY2
         msgbox ok
   }
   else
      msgbox error
}
*/</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=15110">Тема для обсуждения</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-03-12T02:45:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=157096#p157096</id>
		</entry>
</feed>
