Record desktop screen

Discuss any general programming issues here
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Record desktop screen

Post by papiosaur »

Thanks a lot plouf for this new example!

If you search BeginAnimStreamExt() in Hollywood.guide file (MorphOS version), it speak about this command:
- New [SDK]: Added HWEXT_SAVEANIM_BEGINANIMSTREAM; if this extension tag is defined, Hollywood will call
the BeginAnimStreamExt() function instead of the BeginAnimStream() function; this allows plugins to
get information about the desired file adapter, user tags and also the desired output format; the
original BeginAnimStream() is broken by design because it accepts neither a tag list nor a structure
argument so it can't be extended
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Record desktop screen

Post by jPV »

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.
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Record desktop screen

Post by papiosaur »

@jPV: Thanks for your explainations but i have a error message: "Attempt to modify the active brush!" if i add FreeBrush(desktop_brush) after the WriteAnimFrame(1, desktop_brush) line.

Like the brush is named "desktop_brush" so the brush is overwriten on the next loop no?
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Record desktop screen

Post by papiosaur »

A new small problem, i would like to add a brush in PNG format to show the mouse cursor instead of the CIRCLE present in the plouf code. The move of the cursor is OK but the alpha channel is black... An idea about that?

Thanks!
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Record desktop screen

Post by jPV »

papiosaur wrote: Mon Mar 25, 2024 1:34 pm @jPV: Thanks for your explainations but i have a error message: "Attempt to modify the active brush!" if i add FreeBrush(desktop_brush) after the WriteAnimFrame(1, desktop_brush) line.

Like the brush is named "desktop_brush" so the brush is overwriten on the next loop no?
Put EndSelect() between Circle and WriteAnimFrame to finish the drawing into the brush before freeing it.

The brush is not named as "desktop_brush", desktop_brush is a variable containing an identifier for a brush. It will contain id for another brush in the next loop, but the old brush is left in the memory if you don't free it. You just don't know the old brush's id anymore and you can't do anything with the "leaked" brush from that on.

papiosaur wrote: Mon Mar 25, 2024 1:53 pm A new small problem, i would like to add a brush in PNG format to show the mouse cursor instead of the CIRCLE present in the plouf code. The move of the cursor is OK but the alpha channel is black... An idea about that?
Use LoadAlpha=True in the table on LoadBrush()
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Record desktop screen

Post by papiosaur »

@jPV: ha OK, thanks a lot!

i understand better manipulation of brushes now :-)

Interesting part of Hollywood which i didn't know.

Thanks to plouf too of course ;-)
Post Reply