如何控制捕获视频的帧高度和宽度:setVideoSize() 不起作用

发布于 2024-09-13 16:24:22 字数 939 浏览 5 评论 0原文

例如,在 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 技术交流群。

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

发布评论

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

评论(3

泪眸﹌ 2024-09-20 16:24:22

顺序很重要。尝试在 setVideoEncoder 之前调用 setVideoSize:

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();

The order is important. Try calling setVideoSize before setVideoEncoder:

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();
っ左 2024-09-20 16:24:22

recorder.setVideoSize 似乎是一个损坏的 API,并且似乎不起作用。
但您可以使用“高质量”预设,该预设将为您设置视频输出格式、编码器、大小和帧速率。
我假设这是因为这些设置是硬件加速的?

在我的 Nexus 上,这有效:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();

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:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
倾听心声的旋律 2024-09-20 16:24:22

此功能 - recorder.setProfile - 自 Android v. 2.2 起有效

This feature - recorder.setProfile - is valid since Android v. 2.2

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