• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps recording yuv data which is converted from a bitmap and images are changed constantly on this bitmap

Rudba556

Lurker
Oct 27, 2015
3
0
I am trying to record images which are changed at a set time interval. These are displayed on an imageview. (works something like a movie maker)

For this I am:

1. Drawing these images on a bitmap, this method is repeated over a 50ms interval

Code:
        private void BitmapUpdate() {
               timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                try {
                    new Task1().execute();
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }, 0, 50);
        }

        class Task1 extends AsyncTask<Void, Void, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            clearBitmap();

        }

        @Override
        protected String doInBackground(Void... arg0) {
           
            onImageDisplayed();
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);

        }
        }

        public void clearBitmap(){
        if (imageview != null){
        //All the 3 methods below give same error - can't call getpixels() on recycled bitmap
        imageview.setDrawingCacheEnabled(false);
        //OR
        imageview.destroyDrawingCache();
        //OR
        bitmap.recycle();

        }
           }



         public void onImageDisplayed(){

        if (imageview != null) {
            imageview.setDrawingCacheEnabled(true);
            imageview.buildDrawingCache();
            bitmap = imageview.getDrawingCache();
            System.out.println(bitmap.getByteCount() + " is bitmap size ");
            }
           }

2. Using the bitmap data to convert it to yuv data
By using getNV21 method :

http://stackoverflow.com/questions/5960247/convert-bitmap-array-to-yuv-ycbcr-nv21

3. Finally this yuv data is passed FFmpeg recorder, through a method similar to onPreviewFrame, except that the data is from getNV21 method. This method is started by a button click.

What I have achieved:

1. If i dont use clearBitmap(); i get only the first image recorded in the video, even on changing to next image only first image is present throughout the video.


2. So After research on stack overflow many developers suggested clearing the previous imageCache for the next Image. But in my case if i use any of these methods, anywhere,
Code:
        imageview.setDrawingCacheEnabled(false);
        //OR
        imageview.destroyDrawingCache();
        //OR
        bitmap.recycle();

I get the error; mostly because the getNV21 method is running non stop, and always is expecting pixels flow from the Bitmap.

3. If i try running the methods one after another, by stopping getpixels for a moment by a boolean, i only get a black screen.

Kindly help...!

THANKS.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones