Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop MediaCodec and lamemp3 Multi-segment Audio capture and splicing by Android

Shulou Source: shulou.com Published: 2022-05-31 19:06:44 09月21日 Update

< audioExtractor.getTrackCount(); i++) { MediaFormat format = audioExtractor.getTrackFormat(i); String mime = format.getString(MediaFormat.KEY_MIME); if(mime.startsWith(AUDIO)){ d = format.getLong(MediaFormat.KEY_DURATION); audioExtractor.selectTrack(i); audioDecoder = MediaCodec.createDecoderByType(mime); audioDecoder.configure(format, null, null, 0); audioDecoder.start(); break; } } } catch (IOException e) { e.printStackTrace(); } MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); while (true) { extractorInputBuffer(audioExtractor, audioDecoder); int outIndex = audioDecoder.dequeueOutputBuffer(info, 50000); if (outIndex >

= 0) {ByteBuffer data = audioDecoder.getOutputBuffer (outIndex); if ((info.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG)! = 0) {info.size = 0;} if (info.size! = 0) {byte [] bytes = new byte [data.remaining ()] Data.get (bytes,0,bytes.length); data.clear (); try {pcmos.write (bytes);} catch (IOException e) {e.printStackTrace () } if (encoderListener! = null) {int progress = (int) (info.presentationTimeUs + startTime) * 50) / duration); encoderListener.onEncoder (progress);}} audioDecoder.releaseOutputBuffer (outIndex, false) } if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM)! = 0) {break;}} audioDecoder.stop (); audioDecoder.release (); audioExtractor.release (); return d;} private void extractorInputBuffer (MediaExtractor mediaExtractor, MediaCodec mediaCodec) {int inputIndex = mediaCodec.dequeueInputBuffer (50000) If (inputIndex > = 0) {ByteBuffer inputBuffer = mediaCodec.getInputBuffer (inputIndex); long sampleTime = mediaExtractor.getSampleTime (); int sampleSize = mediaExtractor.readSampleData (inputBuffer, 0); if (mediaExtractor.advance ()) {mediaCodec.queueInputBuffer (inputIndex, 0, sampleSize, sampleTime, 0) } else {if (sampleSize > 0) {mediaCodec.queueInputBuffer (inputIndex, 0, sampleSize, sampleTime, MediaCodec.BUFFER_FLAG_END_OF_STREAM);} else {mediaCodec.queueInputBuffer (inputIndex, 0,0,0, MediaCodec.BUFFER_FLAG_END_OF_STREAM) }} private int format (int fjingint [] fs) {if (f > = fs [0]) {return fs [0];} else if (f = fs [I]) {return fs [I];} return-1 The progress bar function of jni callback, 50 * / public void setProgress (long size,long total) {if (encoderListener! = null) {int progress = 50 + (int) ((total*50) / size); if (decoderHolder = = null) {encoderListener.onEncoder (progress) } else {encoderListener.onDecoder (decoderHolder,progress);}} public interface OnAudioEncoderListener {void onDecoder (AudioHolder decoderHolder,int progress); void onEncoder (int progress); void onOver (String path);}} use private AudioMerge audioMerge = new AudioMerge (); private List list = new ArrayList () AudioMerge.start (Environment.getExternalStorageDirectory (). GetAbsolutePath () + "/ HMSDK/test_merge.mp3", list); this is the end of the article on "how to develop MediaCodec and lamemp3 multi-segment audio capture and splicing by Android". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how Android develops MediaCodec and lamemp3 multi-segment audio interception and splicing". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: File audio channel data development problem sound quality size time knowledge progress content function only attribute time format article coding part Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia OPPO Reno Redmi Microsoft