Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping preview callback while recording video?

I'm currently using onPreviewCallback so I can capture frames from camera when in preview and stream them via http.

That works but then I issue a command to start recording and, it seems, I do not have a preview callback anymore.

So, how do I keep the preview callback so I can both send the frames from the surface to my server AND record the video on the device?

like image 834
Alexander Kulyakhtin Avatar asked Apr 23 '13 08:04

Alexander Kulyakhtin


2 Answers

I didn't work for quite long time with Android Camera. However, as I remember

1) onPreviewCallback isn't called while you are recording

It's mentioned in couple of questions:

Camera onPreviewFrame not called How to show real time filtered camera preview while recording videos?

2) I saw that it was handled in SipDroid and couple of other Android SIP clients following way (this was a 1-2 years ago, so this method could be outdates):

  • A pipe was created
  • Receiving socket of the pipe was wrapped in FileDescriptor and passed to MediaRecorder setOutputFile
  • Sending socket of the pipe was constantly read in a thread.
  • This way you can receive a content which is written to a file
  • Now, the issue how to deal with the content (since, it's H.263 or H.264 encoded and could be mixed with the sound, if you record video with the sound).
  • There were some heuristical algorithms which parsed the content (however, it's pain in the ass)

3) You can use onPreviewFrame + start AudioRecorder and encode it yourself (using ffmpeg or something like that) to mp4 file. This way you don't need to start MediaRecorder recording.

like image 55
Victor Ronin Avatar answered Oct 07 '22 18:10

Victor Ronin


You can call these methods after your media recorder.start() being called as following :

camera.reconnect();
camera.setPreviewCallback();
surfaceview.getHolder().addCallback();

The reasons:

  1. After camera.unlock() is called, another process(here is the media recorder process) may use the camera; when the process is done, you must reconnect to the camera, which will re-acquire the lock and allow you to continue using the camera.
  2. And then re-register the surfaceview frame data callback after camera reconnected, because its some state may be changed after reconnected.

I have ever been the same issue as yours in my application, and i fixed it by this. Hope it can resolve your problems!

like image 1
Hanyee Avatar answered Oct 07 '22 18:10

Hanyee