Save preview while recording video?

I am currently using onPreviewCallback, so I can capture frames from the camera when in the preview and transmit them via http.

This works, but then I issue a command to start recording, and it looks like I no longer have the preview callback.

So, how do I save the preview callback so that I can send frames from the surface to my server And record video to the device?

+6
source share
3 answers

I have not worked with an Android camera for a long time. However, as far as I remember

1) onPreviewCallback is not called during recording

He mentioned in several questions:

The onPreviewFrame camera is not called. How to display the cameraโ€™s real-time preview during video recording?

2) I saw that it was processed in SipDroid and a couple of other Android SIP clients as follows (this was 1-2 years ago, so this method may be deprecated):

  • A pipe was created
  • The receiving pipe socket was wrapped in a FileDescriptor and passed to MediaRecorder setOutputFile
  • The pipe sending connector is constantly read in the stream.
  • This way you can get the content that is written to the file
  • Now the question is how to work with content (since it is encoded with H.263 or H.264 and can mix with sound if you record video with sound).
  • There were some heuristic algorithms that analyzed the content (however, this is a pain in the ass)

3) You can use onPreviewFrame + to run AudioRecorder and encode it yourself (using ffmpeg or something like that) into the mp4 file. Thus, you do not need to start MediaRecorder recording.

+5
source

You can call these methods after calling the .start () media recorder as follows:

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

Causes:

  • After calling the camera.unlock () function, another process (here is the process of recording media files) can use the camera; when the process is complete, you must reconnect to the camera, which will re-lock the lock and allow you to continue using the camera.
  • And then re-register the surface image frame data callback after the camera is reconnected, because its some state may be changed after reconnecting.

I had the same problem as you have in my application and I fixed it. Hope he can solve your problems!

+2
source

Once I got the camera and MediaRecorder to start and stop recording without crashing (it wasnโ€™t easy), I still had a problem, as you described, where the preview callback will stop receiving the call.

The fix I finally found is to add a setPreviewCallback call after mediaRecorder.start () and another after mediaRecorder.stop (). Not sure if this is correct, but it worked for the Razr M, which I am testing on.

+1
source

All Articles