/////////////////////////////
//	
//
//	AVI File Save
//
//
/////////////////////////////
//global new_ppavi aviframeID
//avimap=[];

function avisave(avifilesavepath,scale,rate,from,to)
global new_ppavi ppavi aviframe avimap aviprocess aviframe_sub_bsub aviframe_sub_tdiff

aviprocess=TK_GetVar('imScilab(aviprocess)');
totalframe=to-from+1
new_ppavi = CreateAviFile(avifilesavepath, totalframe, ppavi(3), ppavi(4), scale, rate);
if new_ppavi==[]
	disp("create false");
	return
else
	for i=from:to
      		aviframe=AviReadFrame(ppavi, i);
      		if aviframe==[]
			disp ("read error");
			break;
       		end
       		execstr(aviprocess)
		AviWriteFrame(new_ppavi, aviframe);
		TK_SetVar('imScilab(aviframeCurr)',string(i-from+1));
		TK_SetVar('imScilab(aviframesaveSum)',string(totalframe));
		TK_EvalStr('.avisub.fra24.pro28 configure -percent [expr 100*$imScilab(aviframeCurr)/$imScilab(aviframesaveSum)]');
		TK_EvalStr('.avisub.fra24.pro28 configure -textvalue [string range [expr $imScilab(aviframeCurr)*100/$imScilab(aviframesaveSum).0] 0 3]\%');
		new_ppavi(6)=new_ppavi(6)+1;
		aviframe=[];
	end
	AviWriteEnd(new_ppavi);  //releases the Streams
	aviframe=AviReadFrame(ppavi,760);
	TK_EvalStr('destroy .avisub');
	TK_SetVar('imScilab(avi,exposeclose)', string(0));
	impreview(avilabid,aviframe_temp,320,240);
end
endfunction