1

Is it possible and if so "how" would one create a "fake" Camera in an Android application. By "fake" I mean an all software creation that simply looks like a regular Camera to the OS but in actuality takes a Bitmap or byte array as its input data. I want to use such a device with a MediaRecorder to create h.264 videos.

Things this could be used for:

  • Image slideshow video creation
  • Screen capture to video file

Caveats: No rooting and no ROM modification

Alex I
  • 19,689
  • 9
  • 86
  • 158
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131

3 Answers3

3

I think what you are looking for is a way to encode videos to H.264 in a way similar to what MediaRecorder does but not from the camera. You do not particularly care whether this is done with a "fake camera" or in some other way, correct? In that case...

You can use the MediaCodec API available in Android 4.1 and later. You can just give it a series of images and it will create video encoded with (where available) the hardware encoder. Some sample code: Create video from screen grabs in android and Encoding H.264 from camera with Android MediaCodec

Community
  • 1
  • 1
Alex I
  • 19,689
  • 9
  • 86
  • 158
1

If you are expecting to affect other apps with your "fake Camera", that is only possible by modifying the Android source code and rolling your own ROM mod.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Yes,you can! No rooting and no ROM modification,the best way to do this is to build a virtual app that runs the other app as a plugin,so that you can modify anything in the target app. But there is so much work to do, the best news is that there are several open source projects to do this. And so, the next thing is not so difficult,you only have to hook several libs so in /system/lib that affect the camera recording. In fact, I have done this on my device, but I modified the system lib directly, it has to be rooted of course. But it works well on almost all apps except some apps that use the service to capture video. We have to modify the service lib, but it is a little more difficult.

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
pan yang
  • 11
  • 1