zoukankan      html  css  js  c++  java
  • android开发,静音录制视频,在一般清晰度的前提下保证文件大小越小越好

    public void startRecord() {
            mediarecorder = new MediaRecorder();// 创建mediarecorder对象
            mCamera = getCameraInstance();
            Parameters parameters = mCamera.getParameters(); 
            mCamera.autoFocus(null);
            // 解锁camera
            mCamera.setDisplayOrientation(90);
            mCamera.unlock();
            mediarecorder.setCamera(mCamera);
    
            
            List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes(); 
            for(int i=0;i<supportedPreviewSizes.size();i++)
            {
                Log.v("startRecord", "width="+supportedPreviewSizes.get(i).width+";height="+supportedPreviewSizes.get(i).height);
            }
            // 设置录制视频源为Camera(相机)
    //        mediarecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mediarecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            // 设置录制文件质量,格式,分辨率之类,这个全部包括了
    //        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  模糊
    //        mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA));  //2.1M 
    //        mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_CIF));  //不支持
    //        mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));  //766KB  还行  比QUALITY_QCIF好
    //        mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_LOW));  //1M 质量类似LOW
    //        mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P));  //480p效果
    //        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实现录像静音
            mediarecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    //        mediarecorder.setVideoSize(640,480);
            mediarecorder.setVideoSize(1280,720);
            //设置编码比特率,不设置会使视频图像模糊
    //        mediarecorder.setVideoEncodingBitRate(5*1024*1024);  //清晰     512*1024(不清楚)
            mediarecorder.setVideoEncodingBitRate(900*1024); //较为清晰,且文件大小为3.26M(30秒)
            mediarecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);  //H263的貌似有点不清晰
    //        mediarecorder.setVideoFrameRate(10);  //设置无效
            //end
            
            mediarecorder.setPreviewDisplay(surfaceHolder.getSurface());
    
            // 设置视频文件输出的路径
            mediarecorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/data/data/"+System.currentTimeMillis()+".mp4");
            try {
                // 准备录制
                mediarecorder.prepare();
                // 开始录制
                mediarecorder.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    一般情况下,我们直接调用  mediarecorder 会产生很大的视频文件,30秒的为70M,因此,我们需要在录制视频时尽量控制视频文件的大小!

    mediarecorder.setVideoEncodingBitRate(900*1024);   //设置编码比特率,不设置会使视频图像模糊
  • 相关阅读:
    面向对象编程,其属性特性,用法等
    re正则模块细解,面向对象编程思路的优劣。
    机器人学——1.2-三维空间位姿描述
    机器人学——1.1-二维空间位姿描述
    机器人学——1.0-位置与姿态概述
    latex教程:1.2-latex现状
    latex教程: 1.1-历史
    windows安装opencv
    使用pip安装Opencv
    在Ubuntu上安装opencv-python
  • 原文地址:https://www.cnblogs.com/feijian/p/4794821.html
Copyright © 2011-2022 走看看