本文整理了Java中android.media.MediaRecorder.setVideoEncoder()
方法的一些代码示例,展示了MediaRecorder.setVideoEncoder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaRecorder.setVideoEncoder()
方法的具体详情如下:
包路径:android.media.MediaRecorder
类名称:MediaRecorder
方法名:setVideoEncoder
暂无
代码示例来源:origin: guardianproject/haven
private boolean prepare(Camera camera) {
mCamera = camera;
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
// mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
// mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mMediaRecorder.setMaxDuration(mSeconds);
mMediaRecorder.setOutputFile(mOutputFile);
try {
mMediaRecorder.prepare();
} catch(IllegalStateException e) {
Log.d("ERROR", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d("ERROR", "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testVideoEncoder() throws Exception {
assertThat(shadowMediaRecorder.getState()).isNotEqualTo(ShadowMediaRecorder.STATE_DATA_SOURCE_CONFIGURED);
assertThat(shadowMediaRecorder.getVideoEncoder()).isNotEqualTo(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
assertThat(shadowMediaRecorder.getVideoEncoder()).isEqualTo(MediaRecorder.VideoEncoder.H264);
assertThat(shadowMediaRecorder.getState()).isEqualTo(ShadowMediaRecorder.STATE_DATA_SOURCE_CONFIGURED);
}
代码示例来源:origin: commonsguy/cw-omnibus
void start() {
recorder=new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(config.frameRate);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoSize(config.width, config.height);
recorder.setVideoEncodingBitRate(config.bitRate);
recorder.setOutputFile(output.getAbsolutePath());
try {
recorder.prepare();
vdisplay=projection.createVirtualDisplay("andcorder",
config.width, config.height, config.density,
VIRT_DISPLAY_FLAGS, recorder.getSurface(), null, null);
beeper.startTone(ToneGenerator.TONE_PROP_ACK);
recorder.start();
}
catch (IOException e) {
throw new RuntimeException("Exception preparing recorder", e);
}
}
代码示例来源:origin: florent37/CameraFragment
videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
videoRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
videoRecorder.setVideoEncoder(camcorderProfile.videoCodec);
代码示例来源:origin: florent37/CameraFragment
videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
videoRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
videoRecorder.setVideoEncoder(camcorderProfile.videoCodec);
代码示例来源:origin: willowtreeapps/Hyperion-Android
static void prepare(@NonNull Context context) throws RecordingException {
mediaRecorder = new MediaRecorder();
projectionManager = (MediaProjectionManager) context
.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
createDirectoryIfNeeded(context);
String videoId = UUID.randomUUID().toString();
outputPath = context.getFilesDir().getPath() + "/hyperion_recorder/" + videoId + ".mp4";
try {
//mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile(outputPath);
mediaRecorder.setVideoSize(displayMetrics.widthPixels, displayMetrics.heightPixels);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
//mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setVideoEncodingBitRate(512 * 2000);
mediaRecorder.setVideoFrameRate(30);
int rotation = windowManager.getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mediaRecorder.setOrientationHint(orientation);
mediaRecorder.prepare();
} catch (IOException e) {
throw new RecordingException("Failed to initialize the media recorder.", e);
}
}
代码示例来源:origin: googlesamples/android-Camera2Video
private void setUpMediaRecorder() throws IOException {
final Activity activity = getActivity();
if (null == activity) {
return;
}
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
mNextVideoAbsolutePath = getVideoFilePath(getActivity());
}
mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
switch (mSensorOrientation) {
case SENSOR_ORIENTATION_DEFAULT_DEGREES:
mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
break;
case SENSOR_ORIENTATION_INVERSE_DEGREES:
mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
break;
}
mMediaRecorder.prepare();
}
代码示例来源:origin: stackoverflow.com
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
代码示例来源:origin: guoxiaoxing/phoenix
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncodingBitRate(mCamcorderProfile.videoBitRate);
mMediaRecorder.setVideoEncoder(mCamcorderProfile.videoCodec);
代码示例来源:origin: guoxiaoxing/phoenix
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncodingBitRate(mCamcorderProfile.videoBitRate);
mMediaRecorder.setVideoEncoder(mCamcorderProfile.videoCodec);
代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void prepareMediaRecorder() {
// Configure the input sources.
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
// Set the output format and encoder.
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
// Specify the output file
File mediaDir = getExternalMediaDirs()[0];
File outputFile = new File(mediaDir, "myvideorecording.mp4");
mediaRecorder.setOutputFile(outputFile.getPath());
// Prepare to record
try {
mediaRecorder.prepare();
} catch (IOException e) {
Log.d(TAG, "Media Recorder Failure.", e);
}
}
代码示例来源:origin: dalong982242260/SmallVideoRecording
/**
* 自定义的设置mediaeecorder 这里设置视频质量最低 录制出来的视频体积很小 对质量不是要求不高的可以使用
*/
public void customMediaRecorder(){
if (mediaRecorder != null) {
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
//设置分辨率,应设置在格式和编码器设置之后
mediaRecorder.setVideoSize(previewWidth, previewHeight);
mediaRecorder.setVideoEncodingBitRate(800 * 1024);
}
}
代码示例来源:origin: google-ar/sceneform-android-sdk
private void setUpMediaRecorder() throws IOException {
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile(videoPath.getAbsolutePath());
mediaRecorder.setVideoEncodingBitRate(bitRate);
mediaRecorder.setVideoFrameRate(frameRate);
mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
mediaRecorder.setVideoEncoder(videoCodec);
mediaRecorder.prepare();
try {
mediaRecorder.start();
} catch (IllegalStateException e) {
Log.e(TAG, "Exception starting capture: " + e.getMessage(), e);
}
}
代码示例来源:origin: GitEliteNovice/CustomCamera
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setUpMediaRecorder() throws IOException {
final Activity activity = getActivity();
if (null == activity) {
return;
}
Log.d("things called","setUpMediaRecording");
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
mNextVideoAbsolutePath = getVideoFilePath(getActivity());
}
mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
Log.d("orentataions", String.valueOf(global_orm));
mMediaRecorder.setOrientationHint(getOrientation(rotation));
mMediaRecorder.prepare();
}
代码示例来源:origin: stackoverflow.com
Socket socket = new Socket(serverAddr, serverPort);
socket.setTcpNoDelay(true);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
Camera camera = Camera.open();
camera.unlock();
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
recorder.setVideoFrameRate(15);
recorder.setVideoSize(480, 320);
recorder.prepare();
recorder.start();
代码示例来源:origin: stackoverflow.com
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setVideoSize(720,480);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
代码示例来源:origin: stackoverflow.com
public class VideoHolderCallback implements SurfaceHolder.Callback{
MediaRecorder recorder;
...
public void configureRecorder(){
if(camera == null) {
camera = Camera.open();
camera.unlock();
}
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(filePath);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
}
代码示例来源:origin: chinmoyp/screenrecorder
private void initRecorder() {
if (mMediaRecorder == null) {
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
mMediaRecorder.setOutputFile(getFilePath());
}
}
}
代码示例来源:origin: mobapptuts/android_camera2_api_video_app
private void setupMediaRecorder() throws IOException {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setOutputFile(mVideoFileName);
mMediaRecorder.setVideoEncodingBitRate(1000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setOrientationHint(mTotalRotation);
mMediaRecorder.prepare();
}
代码示例来源:origin: duanhong169/Camera
private void setUpMediaRecorder(MediaRecorderConfigurator configurator) throws IOException {
if (configurator == null || configurator.useDefaultConfigs()) {
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile(nextVideoAbsolutePath);
mediaRecorder.setVideoEncodingBitRate(10000000);
mediaRecorder.setVideoFrameRate(30);
mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
}
if (configurator != null) {
configurator.configure(mediaRecorder);
}
mediaRecorder.setOrientationHint(Utils.getOrientation(sensorOrientation, currentDeviceRotation));
mediaRecorder.prepare();
}
内容来源于网络,如有侵权,请联系作者删除!