I have managed to get Video capture to work for a custom camera experience (i.e. using MediaRecorder, Camera, SurfaceView, etc.). But if I am recording a video and change the orientation of the device, video capture stops. Is there way to continue the capture after the orientation change? If fact I want the capture to continue no matter how many times the orientation changes. I imagine it might all have to do with savedInstanceState and saving the file that I pass to mRecorder.setOutputFile(my file). If that's correct, what else am I missing? Or is there a more standard way to handle orientation change during video recording? Thanks for any guidance.
Related
I need to make a video capturer which records something and then saves the file to the disk.
I succeeded in making it work with either back camera and front camera separately but i can't figure out how to make them work together and switch between them the same way the native app does while recording.
I've read that back and front camera are separate devices but I was wondering if there is a possibility to make them work together or the only thing I can do is that when I switch between the cameras to save the current file, start a new media recorder session and record another file and to merge them after I finish.
Thanks
On many modern Android phones the two cameras can work in parallel. You cannot use MediaRecorder to work with such stream, because it can either work with input from one camera (and you have no control over the recording until you stop it), or record a Surface.
Well, in principle you could draw the frames from the two cameras on the same Surface and connect this Surface to a MediaRecorder, but it would not work smoothly.
What you can do, is receive the frames from the two cameras, merge them together to receive a composite frame, and pass these frames to MediaCodec, and then – to MediaMuxer, similar to the camera recording example.
I am having a hard time to figure out how to save footage from both front and back camera at the same time in the same file.
At the moment I have both cameras preview on screen working perfectly but I would like to whenever I press record button to capture those frames until I press it again to stop. Then, it should be saved together locally on device.
Any idea how to achieve this?
Recording preview frames coming from both cameras is not different from any other case of recording video that is through MediaCodec. You cannot use MediaRecorder.
Will it be possible to prevent other camera app from using the camera while my app is using it, at least until the duration of my video recording is completed?
If yes, how can I achieve it?
If no, is there any event I can listen to to know if other camera app has accessed the camera?
What's happening is that the camera instance is being taken from my app and no video is being fed to the recorded file, only audio.
I'm building a custom camera to record video. The camera displays the preview correctly and records the video correctly as well. The problem is with the saved video. The recording is in the wrong orientation(sideways), and I know it's being recorded this way because I'm using a third-party app to playback the video. I've solved it temporarily with this line:
mRecorder.setOrientationHint(270);
However, I'm not sure that this will work on all devices. My question is, what's a more reliable solution to my problem?
Edit
This problem only happens when I record in portrait, when I record in landscape, the orientation is already correct and I don't have to use setOrientationHint
Edit 2
That question is about fixing the preview orientation, I've already solved that problem. My question is how to fix the recording orientation i.e. the orientation of the saved video. –
Is there any way to implement Slow Motion and Time Lapse recording using Camera API?
I tried using MediaRecorder setting VideoFrameRate, VideoBitRate VideoCaptureRate but nothing work for me.
I have successfully implemented using JNI but i found it is taking too much time and not optimized as well.
If you find any other solution available please help me.
I solved it myself and i am sharing my working code piece , just using Camera API slow motion and timelapse are implemented
Before start you must know definition of setCaptureRate(double fps)
Set video frame capture rate.
This can be used to set a different video frame capture rate than the
recorded video's playback rate. This method also sets the recording
mode to time lapse. In time lapse video recording, only video is
recorded. Audio related parameters are ignored when a time lapse
recording session starts, if an application sets them.
TimeLapse
For time lapse you need to use following camera profile , According to you video frame width and height. Choose any one from below profile or you may choose other according to your need.
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_1080P);
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P);
And now you need configure your video setCaptureRate and setVideoEncodingBitRate
video_recorder.setCaptureRate(profile.videoFrameRate/6.0f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);
and at last you need to set your configured Profile to your MediaRecorder.
video_recorder.setProfile(profile);
Slow Motion
For slow motion you also need to configure CamcorderProfile i am using following config for profile.
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_HIGH);
video_recorder.setCaptureRate(profile.videoFrameRate / 0.25f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);
video_recorder.setProfile(profile);
For slowmotion you have to use CameraAPI2 otherwise it will not work.