bytedeco/javacv

FFMPEGFrameGrabber start does nothing after run continuously

Open

#1,552 opened on Dec 16, 2020

View on GitHub
 (13 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
help wantedquestion

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hi, I've been using ffmpeg frame grabber to extract each frame from a video (loaded from external storage). Each frame will be preprocessed and sent into machine learning model, and yes this is a CPU intensive work. Currently I am trying to predict all the datatest, by running prediction continuously. I dont have any problem with phone other than Samsung (I've tried OPPO F1, MI note 8, redmi 9) which successfully ran 400-500 videos, but when I tried using Samsung phone, it would stuck on x-th attempt data (intermittent, lets say it's stuck at the 7th/8th video), at the grabber.start() line. The result from of each video processing will be emitted to the screen (this is an Observable function created using RxJava)

Here's the code snippet that will be run as mush as the amount of datatest video:

        try { 
        val grabber = FFmpegFrameGrabber(inputStream)
        hsv = Mat()
        skinMask = Mat()
        grabber.start() // <--- stuck here

        var idx = 1

        while (true) {
            /* 15 FPS, grabImage twice */
            val nthFrame = grabber.grabImage() ?: break
            grabber.grabImage() ?: break

            var mat = converterToMat.convertToOrgOpenCvCoreMat(nthFrame)

            mat = preprocessImageGetSkin(mat, cropSize, idx++)

            bmp = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
            Utils.matToBitmap(mat, bmp)

            outputData.add(mobileNetV2Classifier.recognize(bmp)[0])

            /* Clean Components */
            bmp.recycle()
            bmp = null
            mat.release()

        }


        grabber.stop()
        grabber.release()
    } catch (e: Exception) {
        // do nothing
    }`

What I've known so far:

  • It seems that the problem is not from the video, since the error is intermittent (sometimes stuck at 4th video, sometimes 8th, etc).
  • There're no error log produced, it just do nothing

Is it something that caused by samsung's custom rom?

details:

  • Smartphone: Samsung Galaxy S9+, Android 10

Contributor guide