Android Hardware decoding Learning

Source: Internet
Author: User

FileInputStream Inch = New FileInputStream("/sdcard/sample.ts");StringMimeType= "VIDEO/AVC";MediacodecDecoder= Mediacodec.Createdecoderbytype(MimeType);MediaformatFormat= Mediaformat.Createvideoformat(MimeType, 1920, 1080);Byte[]Header_sps= { 0, 0, 0, 1, 103, 100, 0, 40, -84, 52, -59, 1, -32, 17, 31, 120, 11, 80, 16, 16, 31, 0, 0, 3, 3, -23, 0, 0, -22, 96, -108 };Byte[]Header_pps= { 0, 0, 0, 1, 104, -18, 60, -128 };Format.Setbytebuffer("Csd-0", Bytebuffer. Wrap (Header_sps)); Format.setbytebuffer ("Csd-1", Bytebuffer.wrap (Header_pps)); Format.setinteger (Mediaformat.key _max_input_size, 1920x1080); Format.setinteger ("Durationus", 63446722);d ecoder.configure (format, surface, NULL, 0); Decoder.start (); bytebuffer[] inputbuffers = Decoder.getinputbuffers (); bytebuffer[] outputbuffers = Decoder.getoutputbuffers (); Bufferinfo info = new Bufferinfo (), Boolean iseos = False;long Startms = System.currenttimemillis (); while (! Thread.interrupted ()) {if (!iseos) {int inindex = Decoder.dequeueinputbuffer (+); if (inindex >= 0) {byte buffer2[ ] = new BYTE[18800 * 8 * 8 * 8]; Bytebuffer buffer = Inputbuffers[inindex]; int samplesize; SampleSize = In.read (buffer2, 0, 18800 * 4); Buffer.clear (); Buffer.put (buffer2, 0, samplesize); Buffer.clear (); if (SampleSize < 0) {Decoder.queueinputbuffer (inindex, 0, 0, 0, mediacodec.buffer_flag_end_of_stream); IsEOS = true;} else {decoder.queueinputbuffer (inindex, 0, samplesize, 0, 0);}} } int outindex = decodeR.dequeueoutputbuffer (info, 10000); Switch (outindex) {case MEDIACODEC.INFO_OUTPUT_BUFFERS_CHANGED:LOG.D ("decodeactivity", "Info_output_buffers_ CHANGED "); Outputbuffers = Decoder.getoutputbuffers (); Break Case MEDIACODEC.INFO_OUTPUT_FORMAT_CHANGED:LOG.D ("decodeactivity", "New FORMAT" + Decoder.getoutputformat ()); Break Case MEDIACODEC.INFO_TRY_AGAIN_LATER:LOG.D ("decodeactivity", "Dequeueoutputbuffer timed out!" + INFO); Break Default:bytebuffer buffer = Outputbuffers[outindex]; LOG.V ("Decodeactivity", "We can ' t use this buffer but render it due to the API limit," + buffer); while (info.presentationtimeus/1000 > System.currenttimemillis ()-Startms) {try {sleep];} catch (Interruptedex Ception e) {e.printstacktrace (); break;}} Decoder.releaseoutputbuffer (Outindex, true); Break } if ((Info.flags & mediacodec.buffer_flag_end_of_stream)! = 0) {log.d ("decodeactivity", "OutputBuffer BUFFER_FLAG_ End_of_stream "); Break }}decoder.stop ();d ecoder.release ();

Android Hardware decoding learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.