Android MediaCodec and MediaMuxer
ringa_lee
ringa_lee 2017-04-18 09:05:59
0
2
448

Android MediaMuxer API 中有这样一段sample code
https://developer.android.com...

 MediaMuxer muxer = new MediaMuxer("temp.mp4", OutputFormat.MUXER_OUTPUT_MPEG_4);
 // More often, the MediaFormat will be retrieved from MediaCodec.getOutputFormat()
 // or MediaExtractor.getTrackFormat().
 MediaFormat audioFormat = new MediaFormat(...);
 MediaFormat videoFormat = new MediaFormat(...);
 int audioTrackIndex = muxer.addTrack(audioFormat);
 int videoTrackIndex = muxer.addTrack(videoFormat);
 ByteBuffer inputBuffer = ByteBuffer.allocate(bufferSize);
 boolean finished = false;
 BufferInfo bufferInfo = new BufferInfo();

 muxer.start();
 while(!finished) {
   // getInputBuffer() will fill the inputBuffer with one frame of encoded
   // sample from either MediaCodec or MediaExtractor, set isAudioSample to
   // true when the sample is audio data, set up all the fields of bufferInfo,
   // and return true if there are no more samples.
   finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo);
   if (!finished) {
     int currentTrackIndex = isAudioSample ? audioTrackIndex : videoTrackIndex;
     muxer.writeSampleData(currentTrackIndex, inputBuffer, bufferInfo);
   }
 };
 muxer.stop();
 muxer.release();
 

这段代码 finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo); 似乎不是API提供的函数,xref里没有搜到,是自定义的函数吗?还是新版本去掉了这个API?

Thanks

ringa_lee
ringa_lee

ringa_lee

membalas semua(2)
小葫芦

Fungsi dalam MediaCodec, semak sama ada ia wujud dalam kelas ini

小葫芦

Memandangkan ia adalah kod sampel, ini jelas merupakan fungsi tersuai dan bukan kaedah API.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan