Android development, mute recording video, in the premise of general definition to ensure that the smaller the file size, the better

Source: Internet
Author: User

 Public voidStartrecord () {Mediarecorder=NewMediarecorder ();//Create a Mediarecorder objectMcamera =getcamerainstance (); Parameters Parameters=mcamera.getparameters (); Mcamera.autofocus (NULL); //Unlock CameraMcamera.setdisplayorientation (90);        Mcamera.unlock ();                Mediarecorder.setcamera (Mcamera); List<Size> supportedpreviewsizes =parameters.getsupportedpreviewsizes ();  for(intI=0;i<supportedpreviewsizes.size (); i++) {LOG.V ("Startrecord", "width=" +supportedpreviewsizes.get (i). width+ "; height=" +Supportedpreviewsizes.get (i). height); }        //set the recording video source to camera//Mediarecorder.setaudiosource (MediaRecorder.AudioSource.CAMCORDER);Mediarecorder.setvideosource (MediaRecorder.VideoSource.CAMERA); //set the recording file quality, format, resolution and so on, this all includes//Mediarecorder.setprofile (Camcorderprofile.get (camcorderprofile.quality_480p)); //7.43M 10frame//Mediarecorder.setprofile (Camcorderprofile.get (camcorderprofile.quality_1080p)); //70.94M 10frame//Mediarecorder.setprofile (Camcorderprofile.get (CAMCORDERPROFILE.QUALITY_CIF)); //2.6M 5frame/10frame//Mediarecorder.setprofile (Camcorderprofile.get (CAMCORDERPROFILE.QUALITY_QCIF)); //0.76M 30frame Blur//Mediarecorder.setprofile (Camcorderprofile.get (CAMCORDERPROFILE.QUALITY_QVGA)); //2.1M//Mediarecorder.setprofile (Camcorderprofile.get (CAMCORDERPROFILE.QUALITY_TIME_LAPSE_CIF)); //not supported//Mediarecorder.setprofile (Camcorderprofile.get (Camcorderprofile.quality_low)); //766KB is better than Quality_qcif .//Mediarecorder.setprofile (Camcorderprofile.get (Camcorderprofile.quality_time_lapse_low)); //1M Quality similar to low//Mediarecorder.setprofile (Camcorderprofile.get (camcorderprofile.quality_time_lapse_480p)); //480p Effect//Mediarecorder.setaudioencoder (Mediarecorder.audioencoder.);//Mediarecorder.setvideoencoder (MediaRecorder.VideoEncoder.H264); //Boolean issupquality_time_lapse_cif = Camcorderprofile.hasprofile (CAMCORDERPROFILE.QUALITY_TIME_LAPSE_CIF); 
    //Boolean issupquality_low = Camcorderprofile.hasprofile (camcorderprofile.quality_low);//log.v ("Startrecord", "issupquality_time_lapse_cif=" +issupquality_time_lapse_cif+ "; issupquality_low=" + Issupquality_low);//        //Mediarecorder.setvideoframerate (30); //start to mute videoMediarecorder.setoutputformat (MediaRecorder.OutputFormat.MPEG_4);//mediarecorder.setvideosize (640,480);Mediarecorder.setvideosize (1280,720); //set the encoded bitrate, not set will blur the video image//mediarecorder.setvideoencodingbitrate (5*1024*1024); //Clear 512*1024 (unclear)Mediarecorder.setvideoencodingbitrate (900*1024);  Clear, and the file size is 3.26M (30 seconds) Mediarecorder.setvideoencoder (MediaRecorder.VideoEncoder.H264); H263 seems a little unclear.//Mediarecorder.setvideoframerate (10); //Invalid setting//EndMediarecorder.setpreviewdisplay (Surfaceholder.getsurface ()); //set the path of the video file outputMediarecorder.setoutputfile (Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/data/data/" + System.currenttimemillis () + ". mp4"); Try {            //Prepare to recordMediarecorder.prepare (); //Start RecordingMediarecorder.start (); } Catch(Exception e) {e.printstacktrace (); }    }

In general, we directly call Mediarecorder will produce very large video files, 30 seconds for 70M, so we need to record the video as far as possible to control the size of the video file!

Mediarecorder.setvideoencodingbitrate (900*1024);   set the encoded bitrate, not set will blur the video image

Android development, mute recording video, in the premise of general definition to ensure that the smaller the file size, the better

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.