12

That's my question :). If I start recording using the Front Camera with the MediaRecorder and then switch to the back camera, is it possible to keep recording using the same video file? Also, is it possible to record both cameras at the same time?

StackOverflowed
  • 5,854
  • 9
  • 55
  • 119
  • Perhaps more suited for the [android](http://android.stackexchange.com/) site – Omar Meky Mar 19 '14 at 14:05
  • @Omar-Meky No, the android site is mainly focusing on using Android, not Android programming. – StackOverflowed Mar 19 '14 at 14:06
  • ok, I thought you meant from a usage perspective! – Omar Meky Mar 19 '14 at 14:09
  • 2
    Yes, it's definitely possible to continuously write to the same file even after switching, but not using the default MediaRecorder classes. Also, since the cameras take a little bit to start up and actually record, there will never be a smooth transition between them unless you can somehow start it up and start recording before transitioning, but then you're just going to run into tons of other problems. – Cruceo Mar 19 '14 at 15:03
  • @Guardanis so what would you suggest as an alternative to MediaRecorder in this case? – StackOverflowed Mar 19 '14 at 16:23
  • I don't know of an alternate, but you may be able to extend it and override how it handles the writing. It's definitely not going to be a small task, though – Cruceo Mar 19 '14 at 17:36
  • @StackOverflowed Did you got any solution to record video front and back camera at the same time? – Murali Ganesan Aug 27 '14 at 05:00
  • 1
    The solution is to individually put frames in a media recorder or mediacodec in onPreviewFrame. Then all you need to do to switch cameras is close/open and clear buffers. However, there may or may not be problems with different camera hardwares since you configure the recording color formats/resolutions on one piece of hardware then swap to a different one. It's pretty complex and I still don't have it all figured out, but it's definitely possible even using the default classes. – sbaar Mar 30 '15 at 02:45

1 Answers1

3

You can do it on Nexus9 with camera2 api. (Nexus5 can't open 2 cameras at the same time)

  • Create 2 Gl contexts(Shared) and 2 texture buffers.
  • Create a TextureView for previewing.
  • Create a MediaRecoder for recording.
  • Open front and back camera.
  • Make repeating request that output target is texture buffer.
  • Render scene with 2 textures to TextureView's surface for each frame.
  • Render scene with 2 textures to MediaRecoder's surface for each frame.

You can switch to each camera by changing render object. You can also render both images in same video using alpha-blend, transform, scaling, etc. by 30fps

Joe Mizuno
  • 437
  • 2
  • 15