Package: memcom
memcomInterprocess real time message/audio/video buffersTable of contentsInstallExamplesReferencesInstall$ pip3 install memcomExamplesExample that creates a test clipimportosimporttimeimportasyncioimportmemcomdefon_error(ctx,e):print(ctx.getName(),'---',e)asyncdefrun():print(memcom.__info__)# Video file nameifnotos.path.isdir('./out'):os.mkdir('./out')fname='./out/testvid.avi'# Clip length in secondst=30# Time divider / Clip will be t / div seconds in length# Using a higher divider gives more time to process# If your CPU can´t keep up, increase this valuediv=1#---------------------------------------------------------------# Video parametersw=800h=600vfps=15print('Create video share')vid=memcom.mcVideo()ifnotvid.create(bufs=2*vfps,width=w,height=h,fps=vfps,cleanup=True):raiseException(vid.getError())vsname=vid.getName()print(f'Video share created:{vsname}')#---------------------------------------------------------------# Audio Parametersch=2bps=16asr=48000afps=50print('Create audio share')aud=memcom.mcAudio()ifnotaud.create(bufs=2*afps,ch=ch,bps=bps,bitrate=asr,fps=afps,cleanup=True):raiseException(aud.getError())asname=aud.getName()print(f'Audio share created:{asname}')#---------------------------------------------------------------# Create initial rectangles# Initial rectsn=0# Target number of rects / adds one each secondm=4tv=[]rects=[{'x':0,'y':0,'w':w,'h':h}]foriinrange(0,n-1):memcom.addRect(rects)ri=0forrinrects:ri+=1v=memcom.mcTestVid(on_error=on_error,opts={'name':f'Rect{ri}','roi':r,'video':vsname,'vbias':-0.25,'vwin':0.25,'audio':asname,'abias':-0.25,'awin':0.25})ifnotv.create():raiseException(v.getError())tv.append(v)#---------------------------------------------------------------# Create file recorderprint('Create recorder')rec=memcom.mcRecord(on_error=on_error,opts={'name':'Recorder','video':vsname,'vbias':-0.5,'vwin':0.25,'audio':asname,'abias':-0.5,'awin':0.25})ifnotrec.create(fname):# if not rec.create(fname, opts={'roi':{'x':int(w/4), 'y':int(h/4), 'w':int(w/2), 'h':int(h/2)}}):raiseException(rec.getError())#---------------------------------------------------------------# Create frame eraser / clears frames before reuseprint('Create Eraser')erase=memcom.mcBlank(on_error=on_error,opts={'name':'Eraser','video':vsname,'vbias':-0.75,'vwin':0.25,'audio':asname,'abias':-0.75,'awin':0.25})ifnoterase.create():raiseException(rec.getError())#---------------------------------------------------------------# Create the clockprint('Create clock')clk=memcom.mcClock(on_error=on_error,opts={'name':'Clock','div':div,'video':vsname,'vfps':vfps,'vbias':0,'vwin':0.25,'audio':asname,'afps':afps,'abias':0,'awin':0.25})clk.create()#---------------------------------------------------------------# Run everything for t * div secondsd=0c=0t=t*divwhile0<t:time.sleep(1)t-=1d+=1ifd>=div:d=0c+=1ifc>=4:c=0iflen(rects)<m:print('Add rect')r=memcom.addRect(rects)ri=len(rects)+1v=memcom.mcTestVid(on_error=on_error,opts={'name':f'Rect{ri}','roi':r,'video':vsname,'vbias':-0.25,'vwin':0.25,'audio':asname,'abias':-0.25,'awin':0.25})ifnotv.create():raiseException(v.getError())tv.append(v)# Close everythingclk.close()erase.close()rec.close()forvintv:v.close()vid.close()if__name__=='__main__':loop=asyncio.new_event_loop()asyncio.set_event_loop(loop)loop.run_until_complete(run())ReferencesPythonhttps://www.python.org/piphttps://pip.pypa.io/en/stable/