I had a conflict that how to use Camera.lock.
But at last I got how to use Camera.lock() API.
Camera.lock() API is....
For example, first set camera parameter, second record camera image.
Reference document here. it is android developer site.
My source code here.
2011年11月27日日曜日
2011年11月23日水曜日
add more MediaRecorder API 2
I try setOutputFormat and setVideoEncoder.
try setVideoEncodingBitRate()
try setVideoFrameRate()
setVideoSize
source code here
_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
_recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);but RAW_AMR is audio only.
_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
try setVideoEncodingBitRate()
_recorder.setVideoEncodingBitRate(10000000);
try setVideoFrameRate()
_recorder.setVideoFrameRate(5);
setVideoSize
_recorder.setVideoSize(100, 100);If set odd size, app comes exception.
source code here
Add more MediaRecorder API
I used MediaRecorder API follow:
callback function for max duration and max file size.
set orientation. it change orientation at playback only.
setMaxDuration() setMaxFileSize() setOnErrorListener() setOnInfoListener() setOrientationHint()
callback function for max duration and max file size.
MediaRecorder.OnInfoListener mInfoListener = new MediaRecorder.OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { // TODO Auto-generated method stub switch (what) { case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED : _recorder.stop(); _recorder.reset(); _isRecording = false; Log.d("camera", "stop"); Log.d("camera", "onInfo=" + MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED); break; case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED : _recorder.stop(); _recorder.reset(); _isRecording = false; Log.d("camera", "stop"); Log.d("camera", "onInfo=" + MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED); break; case MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN : Log.d("camera", "onInfo=" + MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN); break; } } };set max duration if duration is 30 second, call onInfo().
_recorder.setMaxDuration(30000); //max 30 secondsset max file size if file size is 40 M bytes, call onInfo().
_recorder.setMaxFileSize(40000000); //max 40M bytes
set orientation. it change orientation at playback only.
_recorder.setOrientationHint(0);source code here.
setDisplayOrientation
I used setDisplayOrientation().
It is exception to do setDisplayOrientation, while camera do preview.
Do it between stopPreview and startPreview
source code here
It is exception to do setDisplayOrientation, while camera do preview.
Do it between stopPreview and startPreview
camera.stopPreview(); camera.setDisplayOrientation(result); camera.startPreview();There are the Reference code at Android Developer Page follow:
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } Log.d("camera", "result= " + result); camera.stopPreview(); camera.setDisplayOrientation(result); camera.startPreview();
source code here
NexusOne AudioSource
My android is NexusOne. When I called setAudioSource(...), it became exception. oh my god.
2011年11月20日日曜日
setOneShotPreviewCallback
Once register callback, one time be done callback.
It is callback function.
private Camera.PreviewCallback mPreviewListener = new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { Log.d("camera", "onPreviewFrame size=" + data.length); } };
register callback.
_camera.setOneShotPreviewCallback(mPreviewListener);
Every time you touch, you can register a function callback, we confirmed that the function is called callback.
source code here.
2011年11月19日土曜日
setPreviewCallback
I check setPreviewCallback.
It is API to receive every camera frame.
But I found callback timing no strict interval.
calback function.
register callback.
unregister callback.
It is API to receive every camera frame.
But I found callback timing no strict interval.
10-10 13:50:13.580: DEBUG/camera(684): onPreviewFrame size=230400 10-10 13:50:13.670: DEBUG/camera(684): onPreviewFrame size=230400 10-10 13:50:13.710: DEBUG/camera(684): onPreviewFrame size=230400 10-10 13:50:13.770: DEBUG/camera(684): onPreviewFrame size=230400
calback function.
private Camera.PreviewCallback mPreviewListener = new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { Log.d("camera", "onPreviewFrame size=" + data.length); } };
register callback.
_camera.setPreviewCallback(mPreviewListener);
unregister callback.
_camera.setPreviewCallback(null);source code here.
2011年11月18日金曜日
get thumbnail from video
I used ThumbnailUtils. It create thumbnail from video file.
get thumbnail
And I add thumbnail to table view.
get thumbnail
Bitmap bmp = ThumbnailUtils.createVideoThumbnail("/sdcard/sample.3gp",MediaStore.Video.Thumbnails.MINI_KIND );
And I add thumbnail to table view.
ImageView image = new ImageView(this); image.setImageBitmap(bmp); tablelayout.addView(image, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));source code here.
MediaScannerConnection
I would like to register taken video in gallery.
I used MediaScannerConnection.
Register video.
It is simple. it is all.
Let see your gallery.
source code here
I used MediaScannerConnection.
Register video.
MediaScannerConnection.scanFile(this, "/sdcard/sample.3gp", "video/3gpp", null);
It is simple. it is all.
Let see your gallery.
source code here
2011年11月17日木曜日
MediaRecorder
I use MediaRecorder class.
I set up SurfaceView.
And set up SurfaceHolder.Callback
source code here
Actually, I would like to try Camera class and Camera.lock() method. but it has exception. in my NexusOne.
I set up SurfaceView.
SurfaceView mySurfaceView = (SurfaceView) findViewById(R.id.surfaceView1); SurfaceHolder holder = mySurfaceView.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
And set up SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder holder) { } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { _holder = holder; } public void surfaceDestroyed(SurfaceHolder holder) { }Create MediaRecorder
_recorder = new MediaRecorder();Initialize MediaRecorder and start it.
_recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); _recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); _recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); _recorder.setOutputFile("/sdcard/sample.3gp"); _recorder.setPreviewDisplay(_holder.getSurface()); try { _recorder.prepare(); } catch (Exception e) { Log.e("test", "recorder error"); } _recorder.start();stop it.
_recorder.stop(); _recorder.reset();
source code here
Actually, I would like to try Camera class and Camera.lock() method. but it has exception. in my NexusOne.
2011年11月16日水曜日
getThumbnails
I used getThumbnails() to video in gallery.
Get ContentResolver
After I put Bitmap at Table view.
source code here.
Get ContentResolver
ContentResolver contentresolver = getContentResolver();Get video content list from sdcard.
Cursor cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, null);move first a pointer of video list.
cursor.moveToFirst();Get thumbnail.
Bitmap bmp = MediaStore.Video.Thumbnails.getThumbnail(contentresolver, id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
After I put Bitmap at Table view.
source code here.
2011年11月10日木曜日
FaceDetector
I use FaceDetector class.
FaceDetector class need Bitmap class.
First get Bitmap.
MidPoint is center coordinate of face .
FaceDetector class need Bitmap class.
First get Bitmap.
Bitmap bitmapimage = BitmapFactory.decodeFile("/sdcard/face.jpg");Get FaceDetector class
FaceDetector facedetector = new FaceDetector(bitmapimage.getWidth(), bitmapimage.getHeight(), 10);Get face analysis result.
int num = facedetector.findFaces(bitmapimage, faces);view result
MidPoint is center coordinate of face .
Log.d("test", "confidence = " + faces[i].confidence()); Log.d("test", "eyesDistance = " + faces[i].eyesDistance()); PointF point = new PointF(); faces[i].getMidPoint(point); Log.d("test", "MidPoint x = " + point.x + " y=" + point.y); Log.d("test", "euler x = " + faces[i].pose(Face.EULER_X)); Log.d("test", "euler y = " + faces[i].pose(Face.EULER_Y)); Log.d("test", "euler x = " + faces[i].pose(Face.EULER_Z));sourcecode here
2011年11月3日木曜日
ExifInterface
ExifInterface access in jpeg exif header.
Create class
for string
Create class
ExifInterface exif = null; exif = new ExifInterface("/sdcard/test.jpg");exsample getting attribute
for string
Log.d("test", "FNumber=" + exif.getAttribute("FNumber"));for int
Log.d("test", "Flash=" + exif.getAttributeInt("Flash", 0));for double
Log.d("test", "FocalLenght=" + exif.getAttributeDouble("FocalLenght", 0));It is possible to get thumbnail
if (exif.hasThumbnail()) { outputFile(exif.getThumbnail()); }source code here
2011年11月1日火曜日
CameraProfile
CameraProfile class give me quality parameter for jpeg encoder.
get quality for High
my android result
setJpegQuality() sample source code
get quality for High
int quality = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_HIGH); Log.d("test", "QUALITY_HIGH=" + quality);for medium
quality = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_MEDIUM); Log.d("test", "QUALITY_MEDIUM=" + quality);for low
quality = CameraProfile.getJpegEncodingQualityParameter(CameraProfile.QUALITY_LOW); Log.d("test", "QUALITY_LOW=" + quality);source code here
my android result
QUALITY_HIGH=90 QUALITY_MEDIUM=80 QUALITY_LOW=70This quality paramter is used for setJpegQuality().
setJpegQuality() sample source code
CamcorderProfile
I used CamcorderProfile.
Get profile.
Get profile.
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);View parameter,
Log.d("test","quality= " + profile.quality); Log.d("test","autoBitRate= " + profile.audioBitRate); Log.d("test","audioChannels= " + profile.audioChannels); Log.d("test","audioCodec= " + profile.audioCodec); Log.d("test","audioSampleRate= " + profile.audioSampleRate); Log.d("test","duration= " + profile.duration); Log.d("test","fileformat= " + profile.fileFormat); Log.d("test","videoBitRate= " + profile.videoBitRate); Log.d("test","videocodec= " + profile.videoCodec); Log.d("test","videoFrameHeight= " + profile.videoFrameHeight); Log.d("test","videoFrameRate= " + profile.videoFrameRate); Log.d("test","videoFrameWidth= " + profile.videoFrameWidth);The Version is Android 2.3.1. CamcorderProfile has QUALITY_HIGH and QUALITY_LOW. I don't know how to get other profile. My android result follow QUALITY_HIGH
quality= 1 autoBitRate= 96000 audioChannels= 1 audioCodec= 3 audioSampleRate= 16000 duration= 60 fileformat= 2 videoBitRate= 3000000 videocodec= 2 videoFrameHeight= 480 videoFrameRate= 27 videoFrameWidth= 720QUALITY_LOW
quality= 0 autoBitRate= 12200 audioChannels= 1 audioCodec= 1 audioSampleRate= 8000 duration= 30 fileformat= 1 videoBitRate= 256000 videocodec= 3 videoFrameHeight= 144 videoFrameRate= 27 videoFrameWidth= 176
source code here
登録:
投稿 (Atom)