小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

關(guān)于安卓視頻拍攝的小問題

 火柴個(gè)人資料館 2017-01-11
由于在項(xiàng)目中要加入視頻拍攝 第一次使用了系統(tǒng) intent 方法
 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
// String currentVideoName = System.currentTimeMillis() + ".mp4";
// File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/xxx/");
// File out = new File(dir, currentVideoName);
// PreferencesUtils.getInstance(this).put("REQUEST_VIDEO", out.getAbsolutePath());
// Uri uri = Uri.fromFile(out);
// intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
// //限制時(shí)長
// intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 6);
// //0和1是所有相機(jī)都有的設(shè)置,0是最小,1是最大,不存在中間0.5
// intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
// //限制大小
// intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024*1024L);
該方法使用簡單 但是畫面質(zhì)量 只有0 和 1 2種 如果是1 1秒大概在2m 6秒的視頻12m左右 上傳和播放都會(huì)延遲  如果用第三方進(jìn)行壓縮 也比較耗時(shí) 
換了一種方式
MediaRecorder

mMediaRecorder = new MediaRecorder();
mMediaRecorder.reset();
if (mCamera != null)
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setOnErrorListener(this);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.setVideoSource(VideoSource.CAMERA);// 視頻源
mMediaRecorder.setAudioSource(AudioSource.MIC);// 音頻源
mMediaRecorder.setOutputFormat(OutputFormat.MPEG_4);// 視頻輸出格式
mMediaRecorder.setAudioEncoder(AudioEncoder.AMR_NB);// 音頻格式
mMediaRecorder.setVideoSize(mWidth, mHeight);// 設(shè)置分辨率:
//setVideoSize需要權(quán)衡的因素較多,主要包括三方面:MediaRecorder支持的錄制尺寸、
// 視頻文件的大小以及兼容不同Android機(jī)型。這里采用640 * 480(微信小視頻的尺寸是320*240),
// 文件大小在500-1000kb之間,并且市面上99%以上機(jī)型支持此錄制尺寸。
mMediaRecorder.setVideoSize(640, 480);
// 設(shè)置錄制的視頻幀率。必須放在設(shè)置編碼和格式的后面,否則報(bào)錯(cuò)  
// mMediaRecorder.setVideoFrameRate(16);// 這個(gè)我把它去掉了,感覺沒什么用
mMediaRecorder.setVideoEncodingBitRate(1 * 1024 * 1024);// 設(shè)置幀頻率,然后就清晰了 肯定文件越大越清晰
mMediaRecorder.setOrientationHint(90);// 輸出旋轉(zhuǎn)90度,保持豎屏錄制
mMediaRecorder.setVideoEncoder(VideoEncoder.MPEG_4_SP);// 視頻錄制格式
// mediaRecorder.setMaxDuration(Constant.MAXVEDIOTIME * 1000);
mMediaRecorder.setOutputFile(mRecordFile.getAbsolutePath());
mMediaRecorder.prepare();
try {
mMediaRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
使用這個(gè)的好處是可以再拍攝之前設(shè)置參數(shù) 畫面的幀數(shù) 尺寸 可以有效限制文件大小 10秒的視頻在1m左右 只需要注意權(quán)限文件就可以了
 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多