1

I am trying to add functionality to extract, decode, edit, encode and mux a video on Android. Therefore, I found some very useful implementation, which is part of the Android CTS ExtractDecodeEditEncodeMuxTest. Unfortunately, the code only works if it is executed as part of the testcase. I tried to execute it from a normal activity and get:

E/ExtractDecodeEditEncodeMuxTest (18781): java.lang.IllegalStateException: Failed to stop the muxer

W/System.err(18781): java.lang.RuntimeException: Surface frame wait timed out W/System.err(18781): at ...OutputSurface.awaitNewImage(OutputSurface.java:216)

Any ideas, why the output surface does not receive the frames?

UPDATE: Here are the log files for the working test case and the non-working implementation. The code for both is exactly the same. The only difference is that the working one is an AndroidTestCase and the other one is running in the application within an IntentService.

It seems that the whole thing stops extracting and decoding after about 6 frames. Any ideas?

Working Testcase Logoutput

Non-Working Log Output

Florian
  • 2,048
  • 3
  • 28
  • 36

2 Answers2

1

morelikely you need to run it in separate thread

    public static void runTest(ExtractDecodeEditEncodeMuxTest test) throws Throwable {
        test.setOutputFile();
        TestWrapper wrapper = new TestWrapper(test);
        Thread th = new Thread(wrapper, "codec test");
        th.start();
        th.join();
        if (wrapper.mThrowable != null) {
            throw wrapper.mThrowable;
        }
    }
Marlon
  • 1,473
  • 11
  • 13
  • yes I do. I call the code you declared in onResume(). However, I would prefer to do the whole stuff in an intent service – Florian Jul 14 '14 at 10:25
  • can you try to comment out th.join()? it can block OnFrameAvailable() – Marlon Jul 14 '14 at 10:33
  • I think the issue is coming somewhere else, could you please have a quick look at the log files I added? – Florian Jul 14 '14 at 12:18
  • sorry, i do not see anything special in the logs. so commenting out th.join() does not help in receiving surface? – Marlon Jul 14 '14 at 12:38
  • No, unfortunately not. It seems that the error occurs before. – Florian Jul 14 '14 at 12:44
  • 2
    Make sure the thread on which the test is running does not have a Looper. If it does, `SurfaceTexture.OnFrameAvailableListener` will deliver the "frame available" message to the waiting thread, rather than sending the Message to the Handler on the main thread, and you'll get stuck. The other tests (linked from http://bigflake.com/mediacodec/) have a quick note to this effect. – fadden Jul 14 '14 at 15:44
  • @fadden I know this is an old thread, but I wonder if you could provide more specifics. I am not strong with threading and cannot figure out how to accomplish your solution. – Garrett Daniel DeMeyer Jan 06 '16 at 14:09
  • 1
    @GarrettDanielDeMeyer: depending on your actual needs, the code in Grafika (https://github.com/google/grafika) may be more directly applicable. For threading, see http://jcip.net/. – fadden Jan 07 '16 at 05:58
1

Thank's to fadden, I was able to resolve this issue. I am using an intent service now and start a thread without looper there, which works fine.

For running the code in an Android service, this means that the wrapping thread has to be started from a custom thread. Starting a thread within a thread is probably not the very best solution, but it actually solves the problem.

Florian
  • 2,048
  • 3
  • 28
  • 36