我想从视频文件中检索帧。
我的代码遵循文章Use Android Hardware Decoder with OMXCodec in NDK,并且还引用了AwesomePlayer.cpp(AOSP)和libstagefright.cpp(ffmpeg)的代码。但是每当OMXCodec开始解码时它仍会挂起。我不知道问题是什么。
我很感激你的帮助。
代码:
int main(int argc, char *argv[])
{
OMXClient mClient;
status_t ret = mClient.connect();
LOGD("connect status is %d\n", ret);
sp<DataSource> mDs = DataSource::CreateFromURI("file:///sdcard/display/lwtwjod.mp4");
off64_t size = 0;
ret = mDs->getSize(&size);
LOGD("getSize[ret=%d]: %lld\n", ret, size);
sp<MediaExtractor> mMe = MediaExtractor::Create(mDs);
size_t tracksNum = mMe->countTracks();
LOGD("%u tracks\n", tracksNum);
sp<MediaSource> mMs;
bool hasVideo = false;
for(size_t i = 0; i != mMe->countTracks(); i++){
sp<MetaData> mMd_track = mMe->getTrackMetaData(i);
const char *_mime;
mMd_track->findCString(kKeyMIMEType, &_mime);
LOGD("the mime is %s\n", _mime);
String8 mime = String8(_mime);
if (!strncasecmp(mime.string(), "video/", 6)) {
LOGD("find video track!\n");
hasVideo = true;
mMs = mMe->getTrack(i);
int wid, hei;
mMd_track->findInt32(kKeyWidth, &wid);
mMd_track->findInt32(kKeyHeight, &hei);
LOGD("width: %d, height: %d\n", wid, hei);
break;
}
}
if(hasVideo){
sp<MediaSource> decoder =
OMXCodec::Create(mClient.interface(), mMs->getFormat(),
false, mMs,
NULL, OMXCodec::kClientNeedsFramebuffer);
LOGD("start decoding..\n");
ret = decoder->start(); // hangs here
LOGD("decoding return: %d\n", ret);
for(;;){
MediaBuffer *buffer;
buffer = NULL;
ret = decoder->read(&buffer);
LOGD("read decoded buffer result: %d\n", ret);
break;
}
}
}
logcat输出:
I/OMXClient( 5470): Using client-side OMX mux.
D/NativeCodec( 5470): connect status is 0
D/NativeCodec( 5470): getSize[ret=0]: 165748860
D/NativeCodec( 5470): 2 tracks
D/NativeCodec( 5470): the mime is video/avc
D/NativeCodec( 5470): find video track!
D/OMXCodec( 5470): Successfully allocated OMX node 'OMX.qcom.video.decoder.avc'
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] AVC profile = 100 (High), level = 31
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] video dimensions are 1280 x 720
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] Crop rect is 1280 x 720 @ (0, 0)
D/NativeCodec( 5470): start decoding..
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocating 2 buffers of size 2097152 on input port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8e39390 on input port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8e393e0 on input port
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): No color conversion required
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocating 15 buffers of size 1433600 on output port
E/OMX-VDEC-1080P( 197): GET_MV_BUFFER_SIZE returned: Size: 245760 and alignment: 8192
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9b08 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9b58 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ba8 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9bf8 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9c48 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9c98 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ce8 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9d38 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9d88 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9dd8 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9e28 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9e78 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9ec8 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9f18 on output port
I/OMXCodec( 5470): [OMX.qcom.video.decoder.avc] allocated buffer 0xb8eb9f68 on output port
E/OMXNodeInstance( 197): !!! Observer died. Quickly, do something, ... anything...
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9f68 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9f18 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9ec8 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9e78 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9e28 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9dd8 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9d88 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9d38 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9ce8 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9c98 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9c48 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9bf8 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9ba8 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9b58 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8eb9b08 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8e393e0 successful
I/OMXNodeInstance( 197): OMX_FreeBuffer for buffer header 0xb8e39390 successful
E/OMX-VDEC-1080P( 197):
E/OMX-VDEC-1080P( 197): Error in ioctl read next msg
E/ ( 197):
E/ ( 197): Destroy C2D instance
E/ ( 197):
E/ ( 197): Destroy C2D instance