1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by Rudba556, Feb 4, 2016.

  1. Rudba556

    Rudba556 Lurker
    Thread Starter

    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 (Text):
    1.  
    2.         private void BitmapUpdate() {
    3.                timer = new Timer();
    4.         timer.scheduleAtFixedRate(new TimerTask() {
    5.             public void run() {
    6.                 try {
    7.                     new Task1().execute();
    8.                 } catch (Exception e) {
    9.                     // TODO: handle exception
    10.                 }
    11.             }
    12.         }, 0, 50);
    13.         }
    14.  
    15.         class Task1 extends AsyncTask<Void, Void, String> {
    16.  
    17.         @Override
    18.         protected void onPreExecute() {
    19.             super.onPreExecute();
    20.             clearBitmap();
    21.  
    22.         }
    23.  
    24.         @Override
    25.         protected String doInBackground(Void... arg0) {
    26.            
    27.             onImageDisplayed();
    28.             return null;
    29.         }
    30.  
    31.         @Override
    32.         protected void onPostExecute(String result) {
    33.             super.onPostExecute(result);
    34.  
    35.         }
    36.         }
    37.  
    38.         public void clearBitmap(){
    39.         if (imageview != null){
    40.         //All the 3 methods below give same error - can't call getpixels() on recycled bitmap
    41.         imageview.setDrawingCacheEnabled(false);
    42.         //OR
    43.         imageview.destroyDrawingCache();
    44.         //OR
    45.         bitmap.recycle();
    46.  
    47.         }
    48.            }
    49.  
    50.  
    51.  
    52.          public void onImageDisplayed(){
    53.  
    54.         if (imageview != null) {
    55.             imageview.setDrawingCacheEnabled(true);
    56.             imageview.buildDrawingCache();
    57.             bitmap = imageview.getDrawingCache();
    58.             System.out.println(bitmap.getByteCount() + " is bitmap size ");
    59.             }
    60.            }
    61.  
    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 (Text):
    1.  
    2.         imageview.setDrawingCacheEnabled(false);
    3.         //OR
    4.         imageview.destroyDrawingCache();
    5.         //OR
    6.         bitmap.recycle();
    7.  
    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.
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...