如何控制捕获视频的帧高度和宽度:setVideoSize() 不起作用
例如,在 Nexus One 上,相机应用程序能够捕获 720x480(“高”质量设置)的 H.264 视频。然而,当使用 MediaRecorder API 时,它似乎总是以 320x240 的固定帧大小进行捕获。
我希望 setVideoSize() 方法能够控制帧大小(如下面的准备片段所示),但它似乎没有效果(使用 Froyo 2.2 Android SDK)。
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setVideoSize(720,480);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
有关 Android 开发者列表的讨论似乎表明了这一点是一个长期存在的问题。任何人都可以建议如何控制帧大小,或者使用当前的 API 是否可以实现?
On a Nexus One (for example), the camera application is able to capture H.264 video at 720x480 (the "High" quality setting). However, when using the MediaRecorder API, it always seems to capture at a fixed frame size of 320x240.
I would expect the setVideoSize() method to control the frame size (as in the prepare fragment below), but it appears to have no effect (using Froyo 2.2 Android SDK).
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setVideoSize(720,480);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
Discussions on the android developers list seem to indicate this is a long standing issue. Can anyone advise how the frame size can be controlled, or if it is possible at all with the current API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
顺序很重要。尝试在 setVideoEncoder 之前调用 setVideoSize:
The order is important. Try calling setVideoSize before setVideoEncoder:
recorder.setVideoSize 似乎是一个损坏的 API,并且似乎不起作用。
但您可以使用“高质量”预设,该预设将为您设置视频输出格式、编码器、大小和帧速率。
我假设这是因为这些设置是硬件加速的?
在我的 Nexus 上,这有效:
recorder.setVideoSize seems to be a broken API and doesn't seem to work.
But you can use the "high quality" preset that will set the video output format, encoders, size and frame rate for you.
I'm assuming this is because these settings are hardware accelerated?
On my Nexus one this worked:
此功能 - recorder.setProfile - 自 Android v. 2.2 起有效
This feature - recorder.setProfile - is valid since Android v. 2.2