MediaRecorder setVideoSize在不同的设备中显示不同的行为 [英] MediaRecorder setVideoSize shows different behaviour in different devices

查看:127
本文介绍了MediaRecorder setVideoSize在不同的设备中显示不同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用媒体记录器在android应用中录制视频.

I am using media recorder to record video in an android app.

mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);

//mMediaRecorder.setVideoSize(mPreviewSize.width, mPreviewSize.height);

mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);  
String file_name = Environment.getExternalStorageDirectory().getPath() +"/myVideo.mp4";   
mMediaRecorder.setOutputFile(file_name);    
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();

问题出在那

 mMediaRecorder.setVideoSize(mPreviewSize.width, mPreviewSize.height);

在HTC和Xperia中,setVideoSize可以正常工作(仅当我不对此行发表评论时才有效).但是在Nexus和Note中,setVideoSize不起作用(仅当我注释此行时才起作用).

In HTC and Xperia, setVideoSize works fine (Will work only if I don't comment this line). But in Nexus and Note, setVideoSize won't work( Will work only if I comment this line).

我应该怎么做才能使该应用程序在所有这些设备中正确运行?

What should I do in order for the app to run in all these devices correctly??

推荐答案

您需要了解预览和实际捕获的视频是两个不同的东西,同样,预览大小和视频大小是两个不同的参数.在取景器中看到的实际上是预览,但实际上并不是录制的内容.

You need to understand that the preview and the actual captured video are two different things, likewise Preview sizes and Video sizes are two different parameters. What you see in the viewfinder is essentially the preview, but it is not what actually gets recorded.

  1. 启动相机时,您可以为相机设置预览尺寸.但是您必须查询支持的预览尺寸,并在其中设置一个.

  1. When starting a camera, you set the preview size to the camera. But you must query for the supported preview sizes and should set one among them.

Camera camera = camera.open();列出psizes = camera.getParameters().getSupportedPreviewSizes();

Camera camera = camera.open(); List psizes = camera.getParameters() .getSupportedPreviewSizes();

一旦设置了预览,就可以使用MediaRecorder开始记录,并且可以将视频大小设置为媒体记录器,这就是将要捕获的视频的实际大小.同样,您应该设置受支持的视频尺寸之一.

Once you have set up the preview, you can start recording by using a MediaRecorder, and the video size can be set to the media recorder, and it is the actual size of the video that will be captured. Again, you should set one of supported video size.

列表大小= camera.getParameters().getSupportedVideoSizes();

List sizes = camera.getParameters() .getSupportedVideoSizes();

然后,您可以将其中之一设置为媒体记录器

and then, you can set one of these to the media recorder

mediaRecorder.setVideoSize(videoWidth, videoHeight);

因此,请记住始终检查支持的大小,否则肯定会导致应用程序崩溃.

So, remember to check for the supported sizes always, else you are bound to get an app crash.

这篇关于MediaRecorder setVideoSize在不同的设备中显示不同的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆