我正在尝试使用MediaExtract提取avi文件的Track 0(视频轨道),并使用MediaCodec编码为h264格式。以下是我配置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;
}
我面临的问题是这部分。
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;
}
这是日志。
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
我该如何解决这个问题? 什么是libwvm.so?它为什么不能打开?
以下是我如何调用这些函数:
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();
}
“test.avi”的MediaInfo
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)
此处的完整代码:http://pastebin.com/WiCp4SPq encoder_pack.java
http://pastebin.com/JjyR9pdH Main_Activity.java
答案 0 :(得分:2)
我自己问过这个问题(我有太多的信息可以在这里添加评论)MediaExtractor.setDataSource throws IOException "failed to instantiate extractor"我想我现在已经回答了我自己的问题。
看来,如果我不是要求它从文件中提取,而是自己打开文件,获取输入流,从输入流中获取FileDescriptor,然后让它从文件描述符中提取,它每次都有效。
答案 1 :(得分:0)
设备可以使用内置播放器(即预安装)播放此文件吗? 我从来没有看到设备用本机相机写“* .avi”文件,所以我怀疑设备上的MediaCodec实现不支持这种文件格式。