plouf wrote: ↑Fri Mar 22, 2024 9:25 pm
Code: Select all
HideDisplay()
Quit=0
frame=0
BeginAnimStream(1, "test.avi", 1920, 1080,#ANMFMT_MJPEG,{FPS=10})
CreateDisplay(2,{Borderless=True, X=1, Y=1, Width=1,height=1})
OpenDisplay(2)
Function FrameGrab()
desktop_brush = GrabDesktop(Nil)
frame=frame+1
SelectBrush(desktop_brush)
TextOut(0,0,StrStr(frame/10).." sec / frame ="..StrStr(frame),{color=#WHITE})
Circle(MouseX(),MouseY(),10,#RED,{AnchorX = 0.5, AnchorY = 0.5})
WriteAnimFrame(1, desktop_brush)
If IsKeyDown("Esc")
ClearInterval(1)
FinishAnimStream(1)
Quit=1
EndIf
EndFunction
SetInterval(1,FrameGrab,100)
Repeat
WaitEvent()
Until Quit
One quick note about that code. You're keeping every single grabbed brush in memory without freeing them, and you also lose their identifiers, so they just leak in the memory. On Amigaish systems you'll run out of memory pretty quickly, and I guess it must slow down things on systems with virtual memory too
Always remember to test your programs with the Resource Monitor (-resourcemonitor) to see if there's uncontrolled increase of any resource like brushes.
So either add FreeBrush(desktop_brush) after the WriteAnimFrame(1, desktop_brush) line, or use static brush id number which will automatically free ("overwrite") the previous brush. When using Nil as the brush id, you'll get a different identifier every time, which needs some carefulness.