0

I'm trying to use this open source code to extract frames from mp4 in android:

https://github.com/PhilLab/Android-MediaCodec-Examples/blob/master/ExtractMpegFramesTest.java

The original code is written as a unit test file, that extends AndroidTestCase. So I changed the constructor to:

  ExtractMpegFramesTest(Uri filename, android.content.Context context) throws Throwable {
        INPUT_FILE = filename;
        local_context = context;
        //ExtractMpegFramesWrapper.runTest(this);
    }

The commented out code is the original. I call the code as

           try {
                ExtractMpegFramesTest extractMpegFramesTest = new ExtractMpegFramesTest( currFileURI, this);
                extractMpegFramesTest.testExtractMpegFrames();

            } catch (Exception e) {
                e.printStackTrace();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }

Using the debugger, I see that it opens the file via MediaExtractor. It goes through a few iterations and throws an exception: java.lang.RuntimeException: frame wait timed out. It runs 5 frames and on the 6th it times out on this call; outputSurface.awaitNewImage(); (line 297)

original code:

      public void awaitNewImage() {
            final int TIMEOUT_MS = 100000;

            synchronized (mFrameSyncObject) {
                while (!mFrameAvailable) {
                    try {
                        // Wait for onFrameAvailable() to signal us.  Use a timeout to avoid
                        // stalling the test if it doesn't arrive.
                        mFrameSyncObject.wait(TIMEOUT_MS);
                        if (!mFrameAvailable) {
                            // TODO: if "spurious wakeup", continue while loop
                            throw new RuntimeException("frame wait timed out");
                        }
                    } catch (InterruptedException ie) {
                        // shouldn't happen
                        throw new RuntimeException(ie);
                    }
                }
                mFrameAvailable = false;
            }

So it looks like it does'nt get a new frame from the file and then times out.

From google searches, the error happens because I'm looping rather than using a thread. But that sample code uses a thread. I also tried increasing timeout, but same result. Any recommendations how I can go about debugging this?

EDIT: It looks like that code is seriously outdated. The class metadataretriever in the android api is much better. Here is a link to the discussion:

MediaMetadataRetriever.getFrameAtTime() returns only first frame

Arun
  • 1,507
  • 5
  • 19
  • 29

0 Answers0