After capturing the audio and video to save to a local file, this is a very common application scenario, dxpacknet saving video files is also relatively simple
Write to stream with Iavistreamwriter AVI file
1. Initialize the relevant device, set the data capture callback function
dxdevicecollection cameras; Idxcameracapture camcapture; Idxmicrophcapture microphone; Iavistreamwriter Aviwriter; Private voidForm1_Load (Objectsender, EventArgs e) {Cameras= dxfactory.createdxcompent<dxdevicecollection>(Dxdevicecollection.environment_cameras); Camcapture= Dxfactory.createdxcompent<idxcameracapture> ( This, Panel1); CAMCAPTURE.FRAMECB=CAMERASFRAMECB; Camcapture.init (cameras[0]); Microphone= Dxfactory.createdxcompent<idxmicrophcapture> ( -); Microphone. AUDIOCB=AUCAPTUREBUFFERCB; }
2. Create an AVI write stream to open the device
Private voidButton1_Click (Objectsender, EventArgs e) {button1. Enabled=false; //Create an AVI file write stream the first parameter is-write the file path The second parameter is-whether audio write is supported, true for sound/video, False for write-only videoAviwriter = dxfactory.createdxcompent<iavistreamwriter> ("C:\\avicaptest.avi",true); Aviwriter.width=640;//Set Video widthAviwriter.height =480;//set the video heightAviwriter.compresstype = Avivideocompresstype.microsoftvideo1;//set the video compression formatAviwriter.open (); //Open write stream microphone. Open (); Microphone. Start (); Camcapture.run (); }
3. Write audio/video data in callback
Private voidAUCAPTUREBUFFERCB (byte[] Buffer,intlength) { //Write audio dataaviwriter.writewavbuffer (buffer, length); } Private voidCAMERASFRAMECB (byte[] Buffer,intsize) { //Write video dataAviwriter.writebmpbuffer (buffer, Math.max (size,640*480*3)); }
privatevoid button2_click (object sender, EventArgs e) { False; Microphone. Stop (); Camcapture.stop (); Aviwriter.dispose (); // remember to close the stream when you're done NULL ; }
Dxpacknet 4. Save audio and video as a local AVI file