Android Camera setRecordingHint(true)函数 在部分手机上的问题,例如拉伸,变形

setRecordingHint

 此函数是提高MediaRecorder录制摄像头视频性能的。

 技巧:如果你的应用是专为录像写的,那么在启动你的预览之前调用setRecordingHint(boolean)并传入true,这样可以帮你减少启动录制的时间.

问题:

    如果设置这个函数为true,在部分手机上面预览界面是变形的,而且android官方文档中是没有提及

 此变化的,原因目前不明,为了兼容性,只好注释掉此函数。

 

已知会出问题的手机:

MI 2 , LG 部分手机

华为荣耀畅玩4X,Che1-CL20 


然后在google搜索了此函数,发现一个stackoverflow上面的提问。

链接如下:

http://stackoverflow.com/questions/22054170/camera-parameters-setrecordinghint-and-aspect-ratio

-------------------

Camera.Parameters.setRecordingHint and aspect ratio

I've found some odd behavior around Camera.Parameters.setRecordingHint that I'd like to understand better.

If I set it to true, the size of the preview image can come back different from what I pass tosetPreviewSize. It depends on what size I set it to-- some aspect ratios work and some don't.

See the screenshots below-- setPreviewSize has been set to 640x480 for both, but one has setRecordingHint to true and the other to false. I have the code that produces this effect on GitHub.

Is this expected behavior? The docs for setRecordingHint don't indicate anything like this.

comparison of front-facing camera on S4 with setRecordingHint true/false

share edit
 
 
I can confirm this exact issue on LG G3 (Android 4.4.2). –  robert  Dec 8 '14 at 16:35

2 Answers

up vote 4 down vote accepted

You need to set video-size parameter to the correct value. I had the same problem - preview size was 640x480 and the preview appeared stretched while using setRecordingHint(true). I then used getParameters().flatten() to print out all parameters set for my Camera device. Myvideo-size parameter was actually set to 1920x1080 causing the incorrect aspect ratio. You can change this parameter using params.set("video-size", "WxH"). Only then is the aspect ratio correct.

share edit
 
 
is "video-size" documented anywhere? –  paleozogt  Dec 22 '14 at 18:02
 
I don't think so. –  Tadej Matek  Dec 22 '14 at 19:11
 
Thanks for the suggestion, I actually had to set all 3 sizes (preview, picture and video) to the same values to have it working properly on a Samsung S4 :/ This is really weird and not documented at all! –  dmarcato  Apr 2 '15 at 21:16 
 
Note that it may not work to set "video-size" if it is not an approved resolution in the "video-size-values" list. –  Daniel Smith  Nov 19 '15 at 23:52

i've seen a lot of random behavior around this and it unfortunately depends on the oem as well. i see a difference in framerate as well on some phones, like nexus 4 preview framerate drops in half. we depend on the preview frame callback to come at our desired framerate so we have to switch it on phone model unfortunately.

share edit
 
 
In fact on the MotoG running 4.4.2 this totally breaks video recording. You can record perhaps a single video but if you try to prepare the media recorder to record again using the the preview surface freezes and recording hangs. –  Sani Elfishawy  Jun 19 '14 at 1:17
 
I can confirm that on Nexus 4 (Android 5.0), the framerate breaks in half when disabling the recording hint. However, on many other devices it does not reduce the framerate at all (including the LG G3). –  robert  Dec 8 '14 at 16:37
 
our joke around the office is that the hint is to not setRecordingHint –  paleozogt  Dec 8 '14 at 17:31

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值