im_capture.dll windows video capturing

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

im_capture.dll windows video capturing

Postby D.J.Peters » Nov 23, 2011 6:12

I tested the "im_capture.dll" with C++ from tecgraf IUP GUI project.

homepage: tecgraf

But you can use this fine lib with FB and multiply devices too.

download: im_capture.zip

for help and copyrights take a look in "im_capture.bi"

Joshy
found 2 devices
device[0] 0 - DV3300 Video Camera
device[1] 1 - Conexant 2388x Video Capture

using first device = 0

format[0] 320 x 240 RGB24
format[1] 160 x 120 RGB24
format[2] 640 x 480 RGB24
format[3] 176 x 144 RGB24
format[4] 128 x 96 RGB24
format[5] 320 x 240 MJPG
format[6] 160 x 120 MJPG
format[7] 640 x 480 MJPG
format[8] 176 x 144 MJPG
format[9] 128 x 96 MJPG

use format[2]

Image

Code: Select all

' simple im_capture.dll test
#include "im_capture.bi"

' flip the bottom up image and swap RGB to BGR
sub ConvertRGB24_to_BGR32(pFBImage as any ptr,pBuffer as any ptr,w as integer, h as integer)
  Dim As Integer p
  Dim As Any Ptr src
  Dim As Any Ptr des
  If (pFBImage<>0) and (pBuffer<>0) Then
    p=w*3
    src =pBuffer
    src+=p*(h-1)
    des =pFBImage
    des+=32
    asm
      mov ecx,[h]
      mov ebx,[src]
      mov edi,[des]
      mov edx,[p]
      rgb24loopy:
        push ecx
        mov ecx,[w]
        mov esi,ebx
        rgb24loopx:
          mov al,[esi+0] ' r
          mov [edi+2],al
          mov al,[esi+1] ' g
          mov [edi+1],al
          mov al,[esi+2] ' b
          mov [edi+0],al
          add esi,3
          add edi,4
          dec ecx
        jnz rgb24loopx
        Sub ebx,edx
        pop ecx
      Loop rgb24loopy
    End asm
  End If
End sub

dim as imVideoCapture ptr vc

' creates an IM video capture manager
vc = imVideoCaptureCreate()
if (vc=0) then
  print("No capture device found.")
  beep: sleep :end
end if

' enumerate all devices
dim as integer n = imVideoCaptureDeviceCount()
print "found " & n & " devices"
for i as integer = 0 to n-1
  print "device[" & i & "] " & *imVideoCaptureDeviceDesc(i)
next

' connects the first device = 0
if (imVideoCaptureConnect(vc, 0)=0) then
  imVideoCaptureDestroy(vc)
  print("Can not connect to capture device.")
  beep: sleep :end
end if

print
print "using first device = 0"
print

n=imVideoCaptureFormatCount(vc)
dim as integer w,h,ow,f=-1
dim as zstring ptr d=callocate(255)

' try a 640 x XXX format
for i as integer = 0 to n-1
  if (imVideoCaptureGetFormat(vc,i, @w, @h, d)<>0) then
    print "format[" & i & "] " & w & " x " & h & " " & *d
    if (w>ow) and (w<641) then
      f=i:ow=w
    end if
  end if
next

if (f=-1) then
  imVideoCaptureDisconnect(vc)
  imVideoCaptureDestroy(vc)
  print("Can not get usable format.")
  beep: sleep :end
end if

print
print "use format[" & f & "]"
print

' set our format
imVideoCaptureSetFormat(vc, f)

' starting capturing = 1
if (imVideoCaptureLive(vc, 1)=0) then
  imVideoCaptureDisconnect(vc)
  imVideoCaptureDestroy(vc)
  print("Can not activate capturing.")
  beep: sleep :end
end if

' retrieve curent image size
imVideoCaptureGetImageSize(vc, @w, @h)

screenres w,h,32
windowtitle  w & " x " & h & " any key = quit"
' create FB image
dim as any ptr img    = imagecreate(w,h,0,32)
' create RGB capture buffer
dim as any ptr pixels = callocate(w*h*3)

while inkey=""
  ' capture one RGB frame
  imVideoCaptureFrame(vc, pixels, IM_RGB or IM_PACKED, 1000)
  ' RGB24 to BGR 32
  ConvertRGB24_to_BGR32(img,pixels,w,h)
  put (0,0),img,pset
  sleep 10
wend

' get curent state = -1
if (imVideoCaptureLive(vc, -1)<>0) then
  ' stop capturing = 0
  imVideoCaptureLive(vc, 0)
end if

' disconnect the device
imVideoCaptureDisconnect(vc)
' destroy capture manager
imVideoCaptureDestroy(vc)
Last edited by D.J.Peters on Oct 03, 2017 5:23, edited 1 time in total.
band
Posts: 1
Joined: Dec 15, 2011 8:50

Postby band » Dec 15, 2011 20:39

very good work..
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Postby D.J.Peters » Dec 19, 2011 23:50

Tip:

You can use it in combination of Write32BitPixels()
from the high quality MPG4 Video & Audio encoder i posted in the past.

Joshy

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest