Created
June 16, 2012 19:32
-
-
Save drbobrinkman/2942320 to your computer and use it in GitHub Desktop.
Rolling your own screen video capture in Android apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use this code in the onDraw function of your View class. This only works if you have a custom | |
* view that extends View or one of its descendants. (In my project I extend SurfaceView.) | |
*/ | |
try { | |
getDrawingCache(true).compress(Bitmap.CompressFormat.JPEG, 75, new FileOutputStream("/sdcard/screen-"+ String.format("%04d",frame) +".jpg")); | |
frame++; | |
} catch (Exception e) { | |
Log.e("Error--------->", e.toString()); | |
} | |
/** | |
* This goes out in your class file | |
*/ | |
public int frame=0; | |
/** | |
* To use this to make a video: | |
* 1) Run your app, to generate the frames of video | |
* 2) Use the pull command of adb to download all frames of video | |
* 3) Use ffmpeg to stitch these together into a video. Example command: | |
* ffmpeg -r 30 -i screen-%04d.jpg movie.mp4 | |
* | |
* IMPORTANT FAQ! | |
* Your files MUST be numbered consecutively, starting with screen-0000.jpg. You CANNOT | |
* skip a number, or leave out the padding zeroes at the front. You MUST start with 0000. | |
* Otherwise ffmpeg chokes, or stops encoding earlier than you expect. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment