Dxpacknet 4. Save audio and video as a local AVI file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.