android - Recording darkens preview and ratios -
this coded in nativescript, i'll try best adapt scenario java. have created in-app video view support record video.
this done follows:
first create surfaceview
hold preview of camera:
this.msurfaceview = new android.view.surfaceview(this._context); this.mholder = this.msurfaceview.getholder(); this.mholder.settype(android.view.surfaceholder.surface_type_push_buffers);
then create instance of camera
, , sets video surface:
var mcamera = android.hardware.camera; var camera = mcamera.open(1); this.camera = camera; this.camera.setdisplayorientation(90); var parameters = camera.getparameters(); parameters.setrecordinghint(true); if( parameters.isvideostabilizationsupported() ){ parameters.setvideostabilization(true); } camera.setparameters(parameters); this.camera.setpreviewdisplay(_this.mholder); this.camera.startpreview(); this.camera.startfacedetection();
now, good. have camera preview in view want be. color , think image aspect ratio too.
however, when initiate recording, following code:
this.mediarecorder = new android.media.mediarecorder(); // step 1: unlock , set camera mediarecorder this.camera.unlock(); this.mediarecorder.setcamera(this.camera); // step 2: set sources this.mediarecorder.setaudiosource(android.media.mediarecorder.audiosource.camcorder); this.mediarecorder.setvideosource(android.media.mediarecorder.videosource.camera); //this.mediarecorder.setoutputformat(android.media.mediarecorder.outputformat.mpeg_4); // step 3: set camcorderprofile (requires api level 8 or higher) this.mediarecorder.setprofile(android.media.camcorderprofile.get(android.media.camcorderprofile.quality_high)); // platform.screen.mainscreen.widthdips // platform.screen.mainscreen.heightdips // step 4: set output file var filename = "videocapture_" + new date() + ".mp4"; var path = android.os.environment.getexternalstoragepublicdirectory(android.os.environment.directory_dcim).getabsolutepath() + "/camera/" + filename; this.file = new java.io.file(path); this.mediarecorder.setoutputfile(this.file.tostring()); this.mediarecorder.setorientationhint(270); try { this.mediarecorder.prepare(); this.mediarecorder.start(); } catch( ex ) { console.log(ex); }
then, image becomes darker, , face (its what's in focus when i'm trying out) gets wider. aspect ratio changes, , lighting somehow.
i have tried setting setpicturesize on camera parameters, , setvideosize on mediarecorder no luck. , lighting change, have no clue whats going on. i've been googling myself half way heaven, , still found nothing, hope here has got tip on pursue next?
video recording tries run @ steady frame rate, such 30fps. camera preview slows down 10-15fps maintain brightness, if you're in darker location, video recording darker (since can't expose longer 1/30s instead of 1/10s camera preview can).
did call setvideosize before or after calling setprofile? setprofile call changes many parameters, including preview size; video recording sizes 16:9, , default camera preview resolution 4:3 size. when start recording, aspect ratio switches.
most video recording apps use 16:9 preview sizes before starting recording they're consistent. can record 4:3 video, that's not people want see.
Comments
Post a Comment