Nirmal Sheet
Nirmal Sheet

Reputation: 103

Failed to instantiate mediaextractor when using setDataSource()

I am trying to extract Track 0 (video track) of an avi file using MediaExtract and encode to h264 format using MediaCodec. Here is how i configured mediaCodec

public MediaCodec configure_codec(){
         Log.d("OUT","configure starts");
         MediaCodec codec = MediaCodec.createEncoderByType("video/avc");

         MediaFormat format = MediaFormat.createVideoFormat("video/avc", 320, 240);

         format.setInteger(MediaFormat.KEY_BIT_RATE, 700000);
         format.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
         format.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
         format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5); 
         //Configure codec for encoding 
         codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
         Log.d("OUT","codec configured");
         return codec;

    }

The problem i am facing is in this part.

public MediaExtractor extract_video()
    {
        MediaExtractor extractor = new MediaExtractor();

        //problem in this line

        try{
            extractor.setDataSource(file_in);
        }catch(Throwable th){
            Log.d("OUT", th.getMessage());
        }

        MediaFormat format = extractor.getTrackFormat(0);
        String mime = format.getString(MediaFormat.KEY_MIME);
        Log.d("OUT", String.format("MIME TYPE: %s", mime));

        extractor.selectTrack(0);

        return extractor;
    }

Here is the log.

07-01 10:53:53.284: D/OUT(1779): Main starts
07-01 10:53:54.024: I/Choreographer(1779): Skipped 82 frames!  The application may be doing too much work on its main thread.
07-01 10:53:54.373: I/Choreographer(1779): Skipped 247 frames!  The application may be doing too much work on its main thread.
07-01 10:53:54.433: D/gralloc_goldfish(1779): Emulator without GPU emulation detected.
07-01 10:54:00.194: I/Choreographer(1779): Skipped 36 frames!  The application may be doing too much work on its main thread.
07-01 10:54:00.336: D/OUT(1779): Button Start
07-01 10:54:00.336: D/OUT(1779): start starts
07-01 10:54:00.344: D/OUT(1779): /mnt/sdcard/test.avi
07-01 10:54:00.344: D/OUT(1779): /mnt/sdcard/result.h264
07-01 10:54:00.344: D/OUT(1779): configure starts
07-01 10:54:00.394: I/OMXClient(1779): Using client-side OMX mux.
07-01 10:54:00.504: I/SoftAVCEncoder(1779): Construct SoftAVCEncoder
07-01 10:54:00.534: I/ACodec(1779): setupVideoEncoder succeeded
07-01 10:54:00.534: E/OMXNodeInstance(1779): OMX_GetExtensionIndex failed
07-01 10:54:00.544: D/OUT(1779): codec configured
07-01 10:54:00.734: E/WVMExtractor(1779): Failed to open libwvm.so
07-01 10:54:00.734: D/OUT(1779): Failed to instantiate extractor.
07-01 10:54:00.744: D/AndroidRuntime(1779): Shutting down VM
07-01 10:54:00.755: W/dalvikvm(1779): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-01 10:54:00.924: E/AndroidRuntime(1779): FATAL EXCEPTION: main
07-01 10:54:00.924: E/AndroidRuntime(1779): java.lang.IllegalArgumentException
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.media.MediaExtractor.getTrackFormatNative(Native Method)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.media.MediaExtractor.getTrackFormat(MediaExtractor.java:195)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at com.app.convert_final.encoder_pack.extract_video(encoder_pack.java:46)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at com.app.convert_final.encoder_pack.start(encoder_pack.java:81)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at com.app.convert_final.MainActivity$1.onClick(MainActivity.java:27)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.view.View.performClick(View.java:4084)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.view.View$PerformClick.run(View.java:16966)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.os.Handler.handleCallback(Handler.java:615)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.os.Looper.loop(Looper.java:137)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at java.lang.reflect.Method.invokeNative(Native Method)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at java.lang.reflect.Method.invoke(Method.java:511)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-01 10:54:00.924: E/AndroidRuntime(1779):     at dalvik.system.NativeStart.main(Native Method)
07-01 10:54:03.394: I/Process(1779): Sending signal. PID: 1779 SIG: 9

How should i solve this issue? What is libwvm.so? Why does it fail to open?

Here is how i called the functions:

public void start()
    {
        this.running = true;
        Log.d("OUT","start starts");
        Log.d("OUT", file_in);
        Log.d("OUT", file_out);
        codec = configure_codec();
        extractor = extract_video();
        now_start();
    }

MediaInfo of "test.avi"

General
Complete name                            : D:\test.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 967 KiB
Duration                                 : 2s 500ms
Overall bit rate                         : 3 169 Kbps

Video
ID                                       : 0
Format                                   : JPEG
Codec ID                                 : MJPG
Duration                                 : 2s 500ms
Bit rate                                 : 2 782 Kbps
Width                                    : 320 pixels
Height                                   : 240 pixels
Original height                          : 480 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 30.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:2
Bit depth                                : 8 bits
Scan type                                : Interlaced
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 1.207
Stream size                              : 849 KiB (88%)

Audio
ID                                       : 1
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : 1
Duration                                 : 2s 500ms
Bit rate mode                            : Constant
Bit rate                                 : 352.8 Kbps
Channel(s)                               : 1 channel
Sampling rate                            : 22.05 KHz
Bit depth                                : 16 bits
Stream size                              : 108 KiB (11%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 33 ms (1.00 video frame)

Full code here: http://pastebin.com/WiCp4SPq encoder_pack.java
http://pastebin.com/JjyR9pdH Main_Activity.java

Upvotes: 6

Views: 8176

Answers (2)

Andy Newman
Andy Newman

Reputation: 1208

I asked this myself (I had too much information to add it as a comment here) MediaExtractor.setDataSource throws IOException "failed to instantiate extractor" and I think I've answered my own question now.

It would appear that if, instead of asking it to extract from a file, I open the file myself, get an input stream, get the FileDescriptor from the input stream, and then ask it to extract from the file descriptor, it works every time.

Upvotes: 2

user2399321
user2399321

Reputation: 637

Can device play this file with some built-in player(ie pre-installed)? I never saw devices writing "*.avi" file with native camera, so I suspect that MediaCodec implementation on the device just does not support this file format.

Upvotes: 0

Related Questions