Android无法使用前置摄像头录制视频,MediaRecorder启动失败:-19 [英] Android can't record video with Front Facing Camera, MediaRecorder start failed: -19

查看:252
本文介绍了Android无法使用前置摄像头录制视频,MediaRecorder启动失败:-19的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有相同问题的不同代码库.

I have two different code bases with the same problem.

第一个是直接从developer.android.com复制的代码: http://developer.android.com/guide/topics/media/camera.html#custom-camera

第二个是此代码:

http://android-er.blogspot.com.au/2011/10/simple-exercise-of-video-capture-using.html

两者在普通的后置摄像头上都能正常工作,但是一旦尝试使用前置摄像头,我就会收到错误消息.

Both work fine with the normal rear camera, but as soon as I try to use the front facing camera I get the error.

在以下设备上会发生这种情况:

This happens on the following devices:

  • Nexus S 4.1.2

Galaxy Nexus 4.1.2

Nexus 7 4.2.1(仅具有前置摄像头)

我也尝试过看起来像2.2时代的相机参数,尽管有些不同的文章引用了不同的字符串键,但有人声称某些Samsung和HTC设备需要使用此参数.

I have tried what looks like 2.2 era Camera Params as well, which some people claim is required with some Samsung and HTC devices, although multiple different articles reference different String Keys:

c = Camera.open(frontFacingCameraID); // attempt to get a Camera instance
Camera.Parameters params = c.getParameters();
params.set("cam-mode", 1);
params.set("cam_mode", 1);
params.set("camera-id", 1);
c.setParameters(params);

这些操作均无效,还请注意,我检测到的Nexus 7正确的前置摄像头ID当然是:0.但是在所有设备上的结果都是相同的.

None of these work, also please note that I am detecting the correct Front Facing Camera ID which on the Nexus 7 is of course: 0. But the results are the same on all the devices.

我尝试使用低质量的配置文件,尝试通过多种方式手动设置视频分辨率,编码器,输出格式,比特率,帧速率和视频大小,但没有一种方法有效.

I have tried using low quality profile, I have tried setting the video resolution, encoder, output format, bitrate, frame rate and video size manually in a multitude of ways but none which have worked.

让我觉得大多数代码都没错的是常规相机可以正常工作.因此,我的猜测与设置Media Recorder的prepareVideoRecorder()/prepareMediaRecorder()方法有关.

The thing which makes me think theres nothing wrong with most of the code is that the regular camera works fine. So my guess is its something to do with the prepareVideoRecorder() / prepareMediaRecorder() method which sets up the Media Recorder.

也许已知Media Recorder手动编码设置可用于前置摄像头?

Perhaps a Media Recorder manual encoding settings that are known to work on a front facing camera?

我不得不说,Android Camera和MediaRecorder API很烂.与iOS相比,这有点混乱,更不用说一些分散的设备领域中一些令人恐惧的参数不兼容问题和不同的分辨率了.

I have to say, the Android Camera and MediaRecorder API's suck. Compared with iOS its a bit of a mess, not to mention some of the scary looking param incompatibility issues and different resolutions across the fragmented device landscape.

假设我可以在我的JB设备上使用它,是否有人从经验中知道大多数问题是否可以通过API 15 ICS解决?

Assuming I can get it working on my JB devices, does anyone know from experience if most of these issues are resolved with API 15 ICS?

如果它太难支持了,我会考虑不支持API 10 Gingerbread.

I would consider not supporting API 10 Gingerbread if its going to be too hard to support.

推荐答案

好的,所以我终于可以使它正常工作了.

该问题似乎与Profile Settings尤其是与Frame Rate有关.

The issue seems to definitely relate to Profile Settings and in particular Frame Rate.

在Nexus S(我的主要测试设备)上,如果我探测到相机,则会收到以下参数:

On the Nexus S, my primary test device, if I probe the Camera I receive following Parameters:

对于后置摄像头:
15 FPS到30 FPS,足够公平.

For the Rear Camera:
15 FPS to 30 FPS, fair enough.

对于前置摄像头:
7.5 FPS到30 FPS,好吧.

For the Front Facing Camera:
7.5 FPS to 30 FPS, okay.

然后我检查我要使用的配置文件:

Then I check the Profiles I am trying to use:

CamcorderProfile.QUALITY_HIGH
CamcorderProfile.QUALITY_LOW

QUALITY_LOW:

audioBitRate:12200
audioChannels:1
audioCodec:AMR_NB audioSampleRate:8000
持续时间:30
fileFormat:THREE_GPP
质量:0
videoBitRate:256000
videoCodec:H264
videoFrameRate:30
videoFrameWidth:176
videoFrameHeight:144

audioBitRate: 12200
audioChannels: 1
audioCodec: AMR_NB audioSampleRate: 8000
duration: 30
fileFormat: THREE_GPP
quality: 0
videoBitRate: 256000
videoCodec: H264
videoFrameRate: 30
videoFrameWidth: 176
videoFrameHeight: 144

QUALITY_HIGH:

audioBitRate:24000
audioChannels:1
audioCodec:AAC
audioSampleRate:16000
持续时间:60
fileFormat:MPEG_4
质量:1
videoBitRate:3000000
videoCodec:H264
videoFrameRate:30
videoFrameWidth:720
videoFrameHeight:480

audioBitRate: 24000
audioChannels: 1
audioCodec: AAC
audioSampleRate: 16000
duration: 60
fileFormat: MPEG_4
quality: 1
videoBitRate: 3000000
videoCodec: H264
videoFrameRate: 30
videoFrameWidth: 720
videoFrameHeight: 480

很明显,高品质配置文件适用于后置摄像头,因为正面仅640x480.但它们都规定30 FPS.

Clearly, the High Quality Profile is meant for the Rear Camera, seeing as the front facing is only 640x480. But they both state 30 FPS.

现在....这很奇怪:

Now.... Here's the weirdness:

如果我为后置摄像头设置了任何帧频,则无论使用哪种配置文件,它都会因可怕的内容而崩溃:

If I set ANY frame rate for the rear facing camera, no matter what profile, it crashes with the dreaded:

-19错误

-19 error

mediaRecorder.setVideoFrameRate(fpsInt);

这没什么大不了的,因为我不在乎后置摄像头,但这很奇怪,考虑到配置文件默认为30,而Params说它们接受15-30.但是我尝试过的int值没有奏效.如果我省略setVideoFrameRate很好.

That's not a big deal coz I don't care about the rear camera but it is weird, considering the profiles are defaulting to 30 and the Params say they accept 15-30. But no int value I've tried has worked. If I omit the setVideoFrameRate it's fine.

无论如何,移至前置摄像头.

因此,如果我使用QUALITY_LOW配置文件并将帧频设置为15或更低,则可以正常工作.

So, if I use the QUALITY_LOW profile AND set the frame-rate to 15 or lower, it magically works.

mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
mediaRecorder.setVideoFrameRate(15);

实际上,任何值1到15都有效.看起来很奇怪.

In fact any value, 1 - 15 works. Which seems weird.

这是个难题,尽管我也对几乎所有前置摄像头的最小VGA 640x480分辨率都相当自信,但我可能可以为大多数相机寻找分辨率并选择合适的分辨率.

So here's the conundrum, I can probably probe for resolution and select an appropriate res for most cameras, although I'm also fairly confident almost all front-facing cameras at minimum VGA 640x480.

但是,帧速率呢? 就Nexus S而言,我不敢猜测就无法确定15或更低的值吗? 我是否应该始终使用相机返回的最低帧速率?

But, what about the frame rate? In the case of the Nexus S, I don't see any way I could determine the value of 15 or lower without just guessing? Should I aim to always use the LOWEST frame-rate that is returned by the Camera?

我看了一下Galaxy Nexus,它有3种帧频范围,第一个是15-15,第二个是15-30.尽管分辨率更高,但它的低质量配置还是相似的.如果我在Galaxy Nexus上使用低调配置,它似乎可以正常工作.

I took a look at the Galaxy Nexus and it has 3 frame rate ranges, the first one is 15 - 15 and the second is 15 - 30. Its low quality profile is similar albeit higher resolution. If I use low profile on Galaxy Nexus it seems to work fine.

使用Nexus 7,我无法探查CamcorderProfile,我一直在获取空指针,这很奇怪. 它说它支持4 FPS-60 FPS. 如果选择QUALITY_LOW,您认为它应该可以工作,则它会崩溃,并且我找不到可以使用的帧速率. 尽管错误与setProfile有关,所以我认为问题在于内置配置文件. 当然,Android API的要点是它是一致的,这是一艘旗舰设备,FF摄像头在那里可以进行视频会议了吗???

With the Nexus 7, I cant probe the CamcorderProfile's I keep getting null pointers, which is weird. It says it supports 4 FPS - 60 FPS. If I choose QUALITY_LOW which you'd think it should work, it crashes, and I can't find a frame rate it will work with. Although the error relates to setProfile, so I think the issue is with the built in profile. Surely the point of Android API is that it's consistent, this is a flag ship device and the FF camera is there for Video Conferencing isn't it?????

因此,尽管我使用手动自定义设置在两个设备上运行它,但是我看不到一种清晰的方法来通过代码在多个设备上运行.

So, while I have it working on two of the devices using manual custom settings for each, I can't see a clear way of making it work across multiple devices through code.

Nexus S似乎没有按照其Camera.getParameters().getSupportedPreviewFpsRange()

It seems that the Nexus S does not behave the way it promises to with regards to setting the FPS as per its Camera.getParameters().getSupportedPreviewFpsRange()

我很高兴它可以使用自动FPS设置,但是显然不能在FF相机上使用,所以我应该怎么办?我必须在Nexus S上明确设置FPS,在这种情况下,尽管相机告诉我它可以处理7.5-30 FPS,但FPS设置为1到15 FPS.

I'm all happy for it to use Auto FPS settings but apparently it won't with the FF camera so what am I supposed to do? I have to explicitly set the FPS on the Nexus S and in this case to anything from 1 to 15 FPS, despite the Camera telling me it handles 7.5 - 30 FPS.

看起来setProfile修复2.x中所有问题的承诺并不完全正确.

Seems like the promise of the setProfile fixing all the issues in 2.x wasn't entirely true.

我可以理解,如果您为特定的ROM编写Camera App,只是将其自定义为该特定的硬件,这也许可以解释为什么人们似乎总是在自定义ROM上有错误的Camera App.但是.....可下载的视频录制应用程序如何工作?它们是针对每台设备定制的吗?

I can understand if your writing the Camera App for a particular ROM you just customize it to that particular hardware, which might explain why people seem to always have buggy camera apps on custom ROMs. BUT..... How do downloadable video recording apps work? Are they custom to each device?

这是为什么Android上还没有Facebook Poke和Twitter Vine吗???? :P

Is this why there's no Facebook Poke and Twitter Vine on Android yet???? :P

Google,您的Camera API是什么?

Google, what is with your Camera API?

有人知道用于确定所有API 15+兼容设备的分辨率和帧速率的最佳实践"吗?

Does anyone know the "best practices" to determine resolution and frame-rate for all API 15+ compatible devices?

这是否有可能,还是我要在测试的每个设备上编写自定义代码,然后将骰子放在其余的骰子上?

Is that even possible, or am I going to be writing custom code on each device I test and then just roll the dice on the rest?

还是Nexus S和Nexus 7发生了意外事故?

Or is the Nexus S and the Nexus 7 just freak accidents?

这篇关于Android无法使用前置摄像头录制视频,MediaRecorder启动失败:-19的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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