c# - How can i create an avi video file in real time while my application is processing? -


edit:

this did: in form1:

screencapture sc; avifile af; 

in form1 constructor:

sc = new screencapture(); af = new avifile(); 

in form1 timer1 tick event:

private void timer1_tick(object sender, eventargs e)         {             if (playimages == true)             {                 timer1.enabled = false;                 play();                 timer1.enabled = true;             }             else             {                 af.createavi(this.sc);             }         } 

the avifile class after changed it:

using system; using system.collections.generic; using system.componentmodel; using system.drawing; using system.data; using system.text; using system.windows.forms; using avifile; using screenshotdemo;  namespace screenvideorecorder {     class avifile     {         avimanager avimanager;          bitmap bmp;          public avifile()         {             avimanager = new avimanager(@"d:\testdata\new.avi", false);         }          public void createavi(screencapture sc)         {             bmp = new bitmap(sc.capturescreen());             videostream avistream = avimanager.addvideostream(false, 25, bmp);//dlg.rate, bmp);             avistream.addframe(bmp);             bmp.dispose();         }          public avimanager avim         {                         {                 return avimanager;             }             set             {                 avimanager = value;             }         }     } } 

in form1 button click event stop:

private void button3_click(object sender, eventargs e)         {             timer1.enabled = false;             if (af != null)             {                 af.avim.close();             }         } 

but before stop after running after few seconds of taking screenshots: button1 wich start timer , take screenshots:

private void button1_click(object sender, eventargs e)         {             playimages = false;             timer1.enabled = true;         } 

after few seconds im getting exception:

exception in avifilecreatestream: -2147205019   system.exception unhandled   hresult=-2146233088   message=exception in avifilecreatestream: -2147205019   source=avifile   stacktrace:        @ avifile.videostream.createstreamwithoutformat()        @ avifile.videostream.createstream()        @ avifile.videostream..ctor(int32 avifile, boolean writecompressed, double framerate, bitmap firstframe)        @ avifile.avimanager.addvideostream(boolean iscompressed, double framerate, bitmap firstframe)        @ screenvideorecorder.avifile.createavi(screencapture sc) in d:\c-sharp\screenvideorecorder\screenvideorecorder\screenvideorecorder\avifile.cs:line 27        @ screenvideorecorder.form1.timer1_tick(object sender, eventargs e) in d:\c-sharp\screenvideorecorder\screenvideorecorder\screenvideorecorder\form1.cs:line 61        @ system.windows.forms.timer.ontick(eventargs e)        @ system.windows.forms.timer.timernativewindow.wndproc(message& m)        @ system.windows.forms.nativewindow.debuggablecallback(intptr hwnd, int32 msg, intptr wparam, intptr lparam)        @ system.windows.forms.unsafenativemethods.dispatchmessagew(msg& msg)        @ system.windows.forms.application.componentmanager.system.windows.forms.unsafenativemethods.imsocomponentmanager.fpushmessageloop(intptr dwcomponentid, int32 reason, int32 pvloopdata)        @ system.windows.forms.application.threadcontext.runmessageloopinner(int32 reason, applicationcontext context)        @ system.windows.forms.application.threadcontext.runmessageloop(int32 reason, applicationcontext context)        @ system.windows.forms.application.run(form mainform)        @ screenvideorecorder.program.main() in d:\c-sharp\screenvideorecorder\screenvideorecorder\screenvideorecorder\program.cs:line 19        @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args)        @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args)        @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()        @ system.threading.threadhelper.threadstart_context(object state)        @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)        @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state)        @ system.threading.threadhelper.threadstart()   innerexception:  

the exception in class : videostream wich not class it's site downloaded source files: http://www.codeproject.com/articles/7388/a-simple-c-wrapper-for-the-avifile-library

how can fix ?

it's not entirely clear question you're asking.

but appears case want put screenshots avifile directly instead of saving them disk , loading them in.

the key piece of code this:

bitmap = (bitmap)bitmap.fromfile(form1.imagesfiles[n]); avistream.addframe(bitmap); bitmap.dispose(); 

instead of loading them memory file can do:

bitmap = new bitmap(sc.capturescreen()); avistream.addframe(bitmap); bitmap.dispose(); 

that way you're not saving disk, you're inserting directly avi stream.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -