Video capture issues
Re: Video capture issues
Ok, my escapi.pbi was incomplete, works nice now
Re: Video capture issues
I am looking for a screen capture/recorder program to accomplish this. Any recommendations?I wrote a program using PB and ESCAPI 3.0 which processes the lift, gamma and gain of the video and renders it to the screen. It also has a scope.
Is there any way to do anything with the output of my program besides render it to the screen, like record it (with audio)?
I have had problems with OBS Studio locking up my machine after several hours of running, such that I have to power the machine down and up again.
Re: Video capture issues
You can't find any better than OBS
Help Needed: Video Capture
Here is an ambitious video/webcam capture program. The basic functionality is all there, but it performs poorly.
The frame rate appears to be slow resulting in jerky motion, and it makes my CPU labor with the fan funning at high speed.
I have tried various tricks to make it more responsive but to no avail. Now I'm out of tricks. Perhaps some of the experts here can improve on my code?
Pressing F11 toggles between full-screen and scope views. The native resolution is 720P at the moment.
When I run OBS Studio using the same hardware, the motion is nice and smooth and the CPU doesn't labor, so clearly my hardware is up to the task.
Hopefully the solution isn't "port it to C/C++").
Thank you.
The frame rate appears to be slow resulting in jerky motion, and it makes my CPU labor with the fan funning at high speed.
I have tried various tricks to make it more responsive but to no avail. Now I'm out of tricks. Perhaps some of the experts here can improve on my code?
Pressing F11 toggles between full-screen and scope views. The native resolution is 720P at the moment.
When I run OBS Studio using the same hardware, the motion is nice and smooth and the CPU doesn't labor, so clearly my hardware is up to the task.
Hopefully the solution isn't "port it to C/C++").
Thank you.
Code: Select all
;WORKS WITH ESCAPI ;REQUIRES 32-BIT PUREBASIC
;LAST MODIFIED 5/9/2023
InitKeyboard()
InitSprite()
result = ExamineDesktops(): Global V_RES = DesktopHeight(0): Global H_RES = DesktopWidth(0)
SCRNH = V_RES: SCRNW = H_RES
Global fullScreen
Global recordingNow
Global clip = #True
;Global whiteClip = 235 ;100 IRE
;Global whiteClip = 239 ;102 IRE
Global whiteClip = 246 ;105 IRE
;Global whiteClip = 254 ;108 IRE
std$ = "SDR"
;"HLG" OR "SDR" OR "HDR"
Enumeration
#GAINGAD = 1;GAIN GADGET
#GAMMA;GAMMA GADGET
#PEDESTAL;PEDESTAL GADGET
#GAINTEXT
#PEDTEXT
#GAMMATEXT
EndEnumeration
;#UNITY = 0.5
#KR = 0.2126:#KG = 0.7152:#KB = 0.0722 ;REC.709
;PRESETS
gain.d = 1.2
gamma.d = 0.95: factor.d = 255/Pow(255,gamma)
pedestal.d = -4
IncludeFile "escapi.pbi"
Global HEIGHT = (V_RES / 2)-40
Global WIDTH = HEIGHT * 16 / 9
;Global WIDTH = (H_RES / 2)-40
Global WIDTHM1 = WIDTH - 1
Global HEIGHTM1 = V_RES - 1
Procedure Graticule_720(std$)
DrawingMode(#PB_2DDrawing_Default)
;BLACK
lum = 16
LineXY(68,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff);BLACK
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(540,(640 - lum*2)-45, "0%", $ffffff)
;DrawText(6,(640 - lum*2)-45, " 0%", $ffffff)
;lum = 246 ;105 IRE
;LineXY(68,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff);BLACK
;LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
;GAMMA
If std$ = "HLG" Or std$ = "HDR"
lum = 397 / 4 ;HLG
LineXY(36,(255 - lum) + 52, WIDTH-45,(255 - lum) + 52,$00ffff)
DrawText(600,(255 - lum) + 42,"38", $ffffff)
;DrawText(2,(255 - lum) + 44,"397", $ffffff)
DrawText(6,(255 - lum) + 42, "18%", $ffffff)
ElseIf std$ = "SDR"
lum = 104; 40 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "40%", $ffffff)
;DrawText(6,(640 - lum*2)-45, "18%", $ffffff)
lum = 82; 30 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "30%", $ffffff)
lum = 38; 10 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "10%", $ffffff)
lum = 169; 70 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "70%", $ffffff)
lum = 213; 90 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "90%", $ffffff)
lum = 60; 20 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45 , "20%", $ffffff)
lum = 147 ;60 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45, "60%", $ffffff)
lum = 191; 80 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45, "80%", $ffffff)
lum = 126; 50 IRE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(525,(640 - lum*2)-45, "50%", $ffffff)
EndIf
;HLG 90% REFLECTANCE
If std$ = "HLG" Or std$ = "HDR"
;lum = 235
;LineXY(36,(640 - lum*2), WIDTH-45,(640 - lum*2),$00ffff)
;DrawText(600,(510 - lum) + 84, "100", $ffffff)
;DrawText(6,(510 - lum) + 84,"90%", $ffffff)
ElseIf std$ = "SDR"
lum = 235 ;90% REFLECTANCE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45, $00ffff)
DrawText(525,(640 - lum*2)-45, "100%", $ffffff)
;DrawText(6,(640 - lum*2)-45, "90%", $ffffff)
EndIf
;DrawText(6, 90, "REFL.", $ffffff)
;DrawText(600, 90, "IRE", $ffffff)
EndProcedure
Procedure Graticule_1080(std$)
DrawingMode(#PB_2DDrawing_Default)
;BLACK
lum = 16
LineXY(68,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff);BLACK
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(6,(440 - lum*2)-45, "0", $ffffff)
;DrawText(6,(640 - lum*2)-45, " 0%", $ffffff)
;GAMMA
If std$ = "HLG" Or std$ = "HDR"
lum = 397 / 4 ;HLG
LineXY(36,(255 - lum) + 52, WIDTH-45,(255 - lum) + 52,$00ffff)
DrawText(600,(255 - lum) + 42,"38", $ffffff)
;DrawText(2,(255 - lum) + 44,"397", $ffffff)
DrawText(6,(255 - lum) + 42, "18%", $ffffff)
ElseIf std$ = "SDR"
lum = 104
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(600,(640 - lum*2)-45 , "40", $ffffff)
DrawText(6,(640 - lum*2)-45, "18%", $ffffff)
lum = 82
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(600,(640 - lum*2)-45, "30", $ffffff)
lum = 126
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45,$00ffff)
DrawText(600,(640 - lum*2)-45, "50", $ffffff)
EndIf
;WHITE
;HLG 90% REFLECTANCE
If std$ = "HLG" Or std$ = "HDR"
;lum = 235
;LineXY(36,(640 - lum*2), WIDTH-45,(640 - lum*2),$00ffff)
;DrawText(500,(510 - lum) + 84, "100", $ffffff)
;DrawText(6,(510 - lum) + 84,"90%", $ffffff)
ElseIf std$ = "SDR"
lum = 235 ;90% REFLECTANCE
LineXY(36,(640 - lum*2)-45, WIDTH-45,(640 - lum*2)-45, $00ffff)
DrawText(600,(640 - lum*2)-45, "100", $ffffff)
DrawText(6,(640 - lum*2)-45, "90%", $ffffff)
EndIf
DrawText(6, 90, "REFL.", $ffffff)
DrawText(600, 90, "IRE", $ffffff)
EndProcedure
LoadFont(1,"arial",13,#PB_Font_Bold);FOR SCOPE GRATICULE
;LoadFont(2,"arial",22);FOR GADGETS
LoadFont(2,"arial",21);FOR GADGETS
device = 0
count = setupESCAPI()
If count = 0
MessageRequester("Error", "Unable to initialize ESCAPI. Use 32-bit version")
End
EndIf
;name$ = Space(255)
getCaptureDeviceName(device, @name$, 255)
bufSize = H_RES * V_RES * 4
scp.SimpleCapParams
scp\mWidth = H_RES
scp\mHeight = V_RES
scp\mTargetBuf = AllocateMemory(bufSize)
If initCapture(device, @scp) = #False
MessageRequester("Error", "Unable to initialize webcam.")
End
EndIf
image = CreateImage(1, WIDTH, V_RES - 66, 24) ;SCOPE
image2 = CreateImage(2, H_RES,V_RES, 24);CAMERA
OpenWindow(2,0,0, H_RES, V_RES,"Monitor", #PB_Window_BorderLess) ;FULL-SCREEN WINDOW
AddKeyboardShortcut(2,#PB_Shortcut_F11,#PB_Shortcut_F11) ;F11 FOR FULL SCREEN
AddKeyboardShortcut(2,#PB_Shortcut_Space,#PB_Shortcut_Space) ;SPACE BAR TO STOP/START RECORDING
AddKeyboardShortcut(2, #PB_Shortcut_Control|#PB_Shortcut_Q, 113);CTL Q TO QUIT
AddKeyboardShortcut(2, #PB_Shortcut_Escape,27);ESC TO QUIT
OpenWindowedScreen(WindowID(2),0,0,H_RES,V_RES,0,0,0,#PB_Screen_SmartSynchronization)
;MAIN WINDOW
OpenWindow(1,72,0, WIDTH*2, V_RES - 66,"Waveform", #PB_Window_SystemMenu)
AddKeyboardShortcut(1,#PB_Shortcut_F11,#PB_Shortcut_F11) ;F11 FOR FULL SCREEN
AddKeyboardShortcut(1,#PB_Shortcut_Space,#PB_Shortcut_Space) ;SPACE BAR TO STOP/START RECORDING
AddKeyboardShortcut(1, #PB_Shortcut_Control|#PB_Shortcut_Q, 113);CTL Q TO QUIT
AddKeyboardShortcut(1, #PB_Shortcut_Escape,27);ESC TO QUIT
If V_RES = 720
SpinGadget(#GAINGAD, WIDTH * 1.5, 15,200,48,0,100)
SpinGadget(#GAMMA,WIDTH * 1.5, 65,200,48,0,100)
SpinGadget(#PEDESTAL,WIDTH * 1.5, 115,200,48,0,100)
SetGadgetFont(#GAINGAD,FontID(2))
SetGadgetFont(#PEDESTAL,FontID(2))
SetGadgetFont(#GAMMA,FontID(2))
SetGadgetText(#GAINGAD,StrD(gain,2))
SetGadgetText(#GAMMA,StrD(gamma,2))
SetGadgetText(#PEDESTAL,StrD(pedestal,2))
TextGadget(#GAINTEXT,WIDTH * 1.1,20,200,48,"GAIN")
TextGadget(#PEDTEXT,WIDTH * 1.1,70,200,48,"GAMMA")
TextGadget(#GAMMATEXT,WIDTH * 1.1,120,200,48,"PEDESTAL")
TextGadget(11,WIDTH * 1.1,180,600,48,"WHITE: 100%")
TextGadget(12,WIDTH * 1.1,220,600,48,"18% GRAY: 40%")
TextGadget(13,WIDTH * 1.1,260,600,48,"BLACK: 0%")
SetGadgetFont(#GAINTEXT,FontID(2))
SetGadgetFont(#PEDTEXT,FontID(2))
SetGadgetFont(#GAMMATEXT,FontID(2))
SetGadgetFont(11,FontID(2))
SetGadgetFont(12,FontID(2))
SetGadgetFont(13,FontID(2))
OpenWindowedScreen(WindowID(1),0,0,H_RES,V_RES,0,0,0,#PB_Screen_SmartSynchronization)
ElseIf V_RES = 1080
EndIf
;setCaptureProperty(DEVICE,#CAPTURE_ZOOM,0,#VideoProcAmp_Flags_Manual)
;setCaptureProperty(DEVICE,#CAPTURE_BRIGHTNESS,0.5,#VideoProcAmp_Flags_Manual); INITIALIZE TO UNITY
Quit = #False
Repeat
doCapture(device)
Delay(1)
event = WindowEvent()
If event = #PB_Event_CloseWindow
Quit = #True
Break
ElseIf event = #PB_Event_Gadget
If EventGadget() = #GAINGAD
If EventType() = #PB_EventType_Up:gain + 0.01
ElseIf EventType() = #PB_EventType_Down:gain - 0.01
EndIf
SetGadgetText(#GAINGAD,StrD(gain,2))
ElseIf EventGadget() = #GAMMA
If EventType() = #PB_EventType_Up:gamma - 0.05
ElseIf EventType() = #PB_EventType_Down:gamma + 0.05
EndIf
factor.d = 255/Pow(255,gamma)
SetGadgetText(#GAMMA,StrD(gamma,2))
ElseIf EventGadget() = #PEDESTAL
If EventType() = #PB_EventType_Up:pedestal + 1
ElseIf EventType() = #PB_EventType_Down:pedestal - 1
EndIf
SetGadgetText(#PEDESTAL,StrD(pedestal,2))
EndIf
ElseIf event = #PB_Event_Menu
menuItem = EventMenu()
If menuitem = #PB_Shortcut_F11
If fullScreen <> #False
fullScreen = #False:ShowCursor_(#True)
SetActiveWindow(1)
Else
fullScreen = #True:ShowCursor_(#False)
SetActiveWindow(2)
EndIf
ElseIf menuitem = #PB_Shortcut_Space
Debug "space bar"
EndIf
EndIf
;SCOPE
If fullScreen = #False
StartDrawing(ImageOutput(1))
DrawingFont(FontID(1))
Box(0,0,WIDTH, V_RES*2,#Black) ;BLANK SCOPE
If V_RES = 720: Graticule_720(std$)
ElseIf V_RES = 1080: Graticule_1080(std$)
EndIf
;StopDrawing()
*readBufr = scp\mTargetBuf
;DRAW SCOPE
For y = 0 To HEIGHTM1: For x = 0 To WIDTHM1
r = (PeekA(*readBufr+2))
g = (PeekA(*readBufr+1))
b = (PeekA(*readBufr))
rf.d = r * gain
gf.d = g * gain
bf.d = b * gain
r=(Pow(rf,gamma) * factor) + PEDESTAL
If clip = #True And r > whiteClip:r=whiteClip:EndIf;clip at 105 IRE
If r < 16:r=16:EndIf;clip
g=(Pow(gf,gamma) * factor) + PEDESTAL
If clip = #True And g > whiteClip:g=whiteClip:EndIf;clip at 105 IRE
If g < 16:g=16:EndIf;clip
b=(Pow(bf,gamma) * factor) + PEDESTAL
If clip = #True And b > whiteClip:b=whiteClip:EndIf;clip at 105 IRE
If b < 16:b=16:EndIf;clip
;DRAW SCOPE
lum.d = (r*#KR) + (g*#KG) + (b*#KB)
;lum = 235;CALIBRATE
Plot(x/2*0.75+70, (640 - lum*2)-45, $00cc00)
*readBufr + 4
Next
hm1 - pitch
Next
StopDrawing()
;DRAW CAMERA
*readBufr = scp\mTargetBuf
;DRAW CAMERA
StartDrawing(ImageOutput(2))
For y = 0 To V_RES - 1: For x = 0 To H_RES - 1
r = (PeekA(*readBufr+2))
g = (PeekA(*readBufr+1))
b = (PeekA(*readBufr))
rf.d = r * gain
gf.d = g * gain
bf.d = b * gain
r=(Pow(rf,gamma) * factor) + PEDESTAL
If clip = #True And r > whiteClip:r=whiteClip:EndIf;clip at 105 IRE
If r < 16:r=16:EndIf;clip
g=(Pow(gf,gamma) * factor) + PEDESTAL
If clip = #True And g > whiteClip:g=whiteClip:EndIf;clip at 105 IRE
If g < 16:g=16:EndIf;clip
b=(Pow(bf,gamma) * factor) + PEDESTAL
If clip = #True And b > whiteClip:b=whiteClip:EndIf;clip at 105 IRE
If b < 16:b=16:EndIf;clip
Plot(x, y, RGB(r,g,b));MONITOR IS SLIGHTLY UNDERSCANNED
*readBufr + 4
Next
hm1 - pitch
Next
;LineXY(0,568 * 9/16,568,568*9/16,#Green)
;Debug WIDTH 568
StopDrawing()
Else ;FULLSCREEN = TRUE
;DRAW CAMERA TO IMAGE3
*readBufr = scp\mTargetBuf
StartDrawing(ImageOutput(2))
;Box(0,0,SCRNW,SCRNH,#Green)
;Goto skip
For y = 0 To V_RES - 1: For x = 0 To H_RES - 1
r = (PeekA(*readBufr+2))
g = (PeekA(*readBufr+1))
b = (PeekA(*readBufr))
rf.d = r * gain
gf.d = g * gain
bf.d = b * gain
r=(Pow(rf,gamma) * factor) + PEDESTAL
If clip = #True And r > whiteClip:r=whiteClip:EndIf;clip at 105 IRE
If r < 16:r=16:EndIf;clip
g=(Pow(gf,gamma) * factor) + PEDESTAL
If clip = #True And g > whiteClip:g=whiteClip:EndIf;clip at 105 IRE
If g < 16:g=16:EndIf;clip
b=(Pow(bf,gamma) * factor) + PEDESTAL
If clip = #True And b > whiteClip:b=whiteClip:EndIf;clip at 105 IRE
If b < 16:b=16:EndIf;clip
Plot(x, y, RGB(r,g,b));MONITOR IS SLIGHTLY UNDERSCANNED
*readBufr + 4
Next
hm1 - pitch
Next
skip:
StopDrawing()
EndIf
If fullScreen = #False
;StartDrawing(WindowOutput(1))
StartDrawing(ScreenOutput())
DrawImage(ImageID(1),0,0);DRAW SCOPE TO SCREEN
;If V_RES = 720:DrawImage(ImageID(2),568,300,1280,360):EndIf;DRAW CAMERA TO SCREEN
If V_RES = 720:DrawImage(ImageID(2),568,300,640,360):EndIf;DRAW CAMERA TO SCREEN
StopDrawing()
SetActiveWindow(1)
Else ;FULL SCREEN
;StartDrawing(WindowOutput(2))
StartDrawing(ScreenOutput())
DrawImage(ImageID(2),0,0);DRAW CAMERA TO SCREEN
StopDrawing()
SetActiveWindow(2)
EndIf
StopDrawing()
FlipBuffers()
;Delay(1)
Until quit <> #False
;StopDrawing()
deinitCapture(device)
FreeImage(1):FreeImage(2)
FreeMemory(scp\mTargetBuf)
CloseWindow(1)
End
[code]
Re: Help Needed: Video Capture
You will have the same problem, because the problem is not the languaje, but the code and the lack of hardware acceleration one.
I don't know nothing about that, but you *must* use the video card to get smooth video.
BTW Icant run your code, I think my escapi.pbi is outdated again?
Re: Video capture issues
I didn't think of using the video card's hardware acceleration. That's probably it.
The pbi file hasn't changed since I last posted it in this thread, so it should run for you.
Thanks for your interest.
The pbi file hasn't changed since I last posted it in this thread, so it should run for you.
Thanks for your interest.
Re: Video capture issues
No run for me, the program hangs, I must kill it from the task manager, because I can't do anything.
On the Debug window I get:
Unsupported function: initCaptureWithOptions
Error while getting some dll functions.
On the Debug window I get:
Unsupported function: initCaptureWithOptions
Error while getting some dll functions.
Re: Video capture issues
[DISREGARD]
Last edited by chris319 on Wed May 10, 2023 5:39 pm, edited 1 time in total.
Re: Video capture issues
All I can say is "it works for me".
Do you have escapi.dll installed?
Do you get a line number where it's hanging?
Re: Video capture issues
Yes, also, the previous example you posted here works nice.
No, now I see the dots graph and nothing on the other window, also the windows hourglass is here and the program doesn't respond.
I don't want to bother you, I only run it by curiosity
Re: Video capture issues
[DISREGARD]
Last edited by chris319 on Fri May 12, 2023 5:25 pm, edited 1 time in total.
Re: Video capture issues
Not for you in what sense?Caronte3D wrote: ↑Fri May 12, 2023 7:30 am Not for me
Take a look:
https://drive.google.com/file/d/1BrNWpF ... share_link
I can't access your Google drive.
Re: Video capture issues
What version of PB are you using?
Can you see your camera using another program?
Can you see your camera using another program?