如何设置MediaRecorder才能获得最佳的视频质量效果?

发布于 2024-11-08 13:57:29 字数 203 浏览 2 评论 0原文

请问各位,在不考虑手机物理限制的情况下,如何设置MediaRecorder中的参数才能通过编码获得最佳的视频录制效果?或者我的 MediaRecorder 编码导致视图小失真是否有任何影响?

如果你们中的一些人可能猜测不清楚的参数,我实际上是使用首选项设置一些参数。我错过了哪些可能有助于改进视频编码过程的参数,例如:帧速率

Guys can someone tell me how should I set the parameters in the MediaRecorder in order to get the best video recording effect possible through coding without considering the physical limitation of the phone? Or is there any effect of the view small distortion caused by my coding of the MediaRecorder?

If some of you might be guessing of the unclear parameters I'm actually setting some of the parameters using preferences. What are the parameters I miss which might help to improve the video encoding process Ex: framerate

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2024-11-15 13:57:29

根据 API 级别,您可能想要使用或不使用现有的配置文件。

没有配置文件:

recorder.setVideoSize(640, 480);
recorder.setVideoFrameRate(16); //might be auto-determined due to lighting
recorder.setVideoEncodingBitRate(3000000);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

或者如果您想使用现有的配置文件

CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);

请注意,您不能同时使用这两个选项,因为您会收到错误或您的准备将无法工作,

因为并非所有 Android API 和/或设备都支持相同的值,您必须查询每个设备的最大值或找到适用于任何地方的东西。

Depending on the API level you may want to use existing profiles or not.

Without profiles:

recorder.setVideoSize(640, 480);
recorder.setVideoFrameRate(16); //might be auto-determined due to lighting
recorder.setVideoEncodingBitRate(3000000);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Or if you want to use existing profiles

CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);

Please note that you cannot have both options together as you will get errors or your prepare will not work

As not all the Android API and/or devices support the same values you will either have to query the maximum values per device or find something that works everywhere.

谈场末日恋爱 2024-11-15 13:57:29

虽然这个问题很老了,但我想指出我用来录制高清质量视频的组合。

使用下面的代码组合来实现高清质量的视频。

CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);                    
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);                        
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);                        
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);                    
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);                    
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);                    
mMediaRecorder.setVideoEncodingBitRate(cpHigh.videoBitRate);                    
mMediaRecorder.setVideoFrameRate(cpHigh.videoFrameRate);
int rotation = mWindowManager.getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mMediaRecorder.setOrientationHint(orientation);

使用下面的代码获取 DISPLAY_HEIGHT,DISPLAY_WIDTH

DisplayMetrics metrics = new DisplayMetrics();      
mWindowManager.getDefaultDisplay().getMetrics(metrics);          
DISPLAY_WIDTH = metrics.widthPixels;
DISPLAY_HEIGHT = metrics.heightPixels;

定义 ORIENTATIONS 如下所示

public static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
    ORIENTATIONS.append(Surface.ROTATION_0, 90);
    ORIENTATIONS.append(Surface.ROTATION_90, 0);
    ORIENTATIONS.append(Surface.ROTATION_180, 270);
    ORIENTATIONS.append(Surface.ROTATION_270, 180);
}

希望它有帮助。

Although the question is quite old, i would like to to point out the combination i used to record the video of HD quality.

Use below combination of the code to achieve HD quality video.

CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);                    
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);                        
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);                        
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);                    
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);                    
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);                    
mMediaRecorder.setVideoEncodingBitRate(cpHigh.videoBitRate);                    
mMediaRecorder.setVideoFrameRate(cpHigh.videoFrameRate);
int rotation = mWindowManager.getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mMediaRecorder.setOrientationHint(orientation);

Use below code to get the DISPLAY_HEIGHT,DISPLAY_WIDTH

DisplayMetrics metrics = new DisplayMetrics();      
mWindowManager.getDefaultDisplay().getMetrics(metrics);          
DISPLAY_WIDTH = metrics.widthPixels;
DISPLAY_HEIGHT = metrics.heightPixels;

Define ORIENTATIONS as shown below

public static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
    ORIENTATIONS.append(Surface.ROTATION_0, 90);
    ORIENTATIONS.append(Surface.ROTATION_90, 0);
    ORIENTATIONS.append(Surface.ROTATION_180, 270);
    ORIENTATIONS.append(Surface.ROTATION_270, 180);
}

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文