Wednesday, 15 May 2013

Android MediaMuxer readSampleData IllegalStateException -



Android MediaMuxer readSampleData IllegalStateException -

i using next code generate video. however, 1 in every 5 attempts readsampledata raises either illegalargumentexception or illegalstateexception. can stop exceptions. can check state of extractor before calling readsampledata. if so, how?

mediaextractor videoextractor = new mediaextractor(); videoextractor.setdatasource(source); log.d(tag, "video extractor track count " + videoextractor.gettrackcount() ); mediamuxer muxer = new mediamuxer(outputfile, mediamuxer.outputformat.muxer_output_mpeg_4); videoextractor.selecttrack(0); mediaformat videoformat = videoextractor.gettrackformat(0); int videotrack = muxer.addtrack(videoformat); log.d(tag, "video format " + videoformat.tostring() ); boolean videoended = false; long videotimestamp = 0; int framecount = 0; int offset = 100; bytebuffer videobuf = bytebuffer.allocate(max_sample_size); bufferinfo videobufferinfo = new bufferinfo(); muxer.start(); while (!videoended) { videobufferinfo.offset = offset; videobufferinfo.size = videoextractor.readsampledata(videobuf, offset); if (videobufferinfo.size < 0) { log.d(tag, "video ended " + videobufferinfo.size); videoended = true; videobufferinfo.size = 0; } else { videotimestamp = videobufferinfo.presentationtimeus = videoextractor.getsampletime(); videobufferinfo.flags = videoextractor.getsampleflags(); muxer.writesampledata(videotrack, videobuf, videobufferinfo); videoextractor.advance(); framecount++; log.d(tag, "frame (" + framecount + ") video presentationtimeus:" + (videobufferinfo.presentationtimeus/1000000.0f) +" flags:" + videobufferinfo.flags +" size " + videobufferinfo.size); } } muxer.stop(); muxer.release();

the actual code adds sound video after video extractor loop.

android illegalstateexception illegalargumentexception mediacodec mediamuxer

No comments:

Post a Comment