1

I'm trying to play a video stored in sd card using javacv. Following is my code

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        playthevideo();
    }

    protected void playthevideo() {

       String imageInSD = "/storage/080A-0063/dama/" + "test3.mp4";

       FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(imageInSD);

       AndroidFrameConverter converterToBitmap = new AndroidFrameConverter();

       OpenCVFrameConverter.ToIplImage converterToipi = new OpenCVFrameConverter.ToIplImage();

           try {
               Log.d("Tag", "try");
               grabber.start();
               Log.d("Tag", "started");

               int i = 0;
               IplImage grabbedImage = null;

               ImageView mimg = (ImageView) findViewById(R.id.a);

               grabber.setFrameRate(grabber.getFrameRate());
               ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
               while (((grabbedImage = converterToipi.convert(grabber.grabImage())) != null)) {

                   Log.d("Tag", String.valueOf(i));

                   int width = grabbedImage.width();

                   int height = grabbedImage.height();

                   if (grabbedImage == null) {
                       Log.d("Tag", "error");
                   }

                   IplImage container = IplImage.create(width, height, IPL_DEPTH_8U, 4);

                   cvCvtColor(grabbedImage, container, CV_BGR2RGBA);

                   Bitmap bitmapnew = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

                   bitmapnew.copyPixelsFromBuffer(container.getByteBuffer());

                   if (bitmapnew == null) {
                       Log.d("Tag", "bit error");
                   }

                   mimg.setImageBitmap(bitmapnew);

                   mimg.requestFocus();

                   i++;
               }

               Log.d("Tag", "go");

           }
           catch(Exception e) {

          }
     }
}

just ignore the tags because those are only for my testing purposes.. When I run this code the main activity layout is still loading while android monitor shows the value of "i" (which is current frame number) and suddenly after frame number 3671 code exits the while loop and the imageview shows a frame which is not the end frame of that video(it somewhere around staring of the video). I was unable to find a way to show the grabbed frames from ffmpegframegrabber so i decided to show the image in imageview in this way. Can anybody tell me why I'm getting this error or another error non path to play and show the video in android activity? BTW javacv 1.3.1 is imported correctly into my android dev environment. Thanks.

Marat
  • 6,142
  • 6
  • 39
  • 67
d91
  • 83
  • 1
  • 8

0 Answers0