android.media.MediaMuxer类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中android.media.MediaMuxer类的一些代码示例,展示了MediaMuxer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaMuxer类的具体详情如下:
包路径:android.media.MediaMuxer
类名称:MediaMuxer

MediaMuxer介绍

暂无

代码示例

代码示例来源:origin: guardianproject/haven

mTrackIndex = mMuxer.addTrack(newFormat);
  mMuxer.start();
  mMuxerStarted = true;
} else if (encoderStatus < 0)
      mMuxer.writeSampleData(mTrackIndex, encodedData,
          mBufferInfo);
    } catch (Exception e)

代码示例来源:origin: TeamNewPipe/NewPipe

};
muxer = new MediaMuxer(tmpFile.getAbsolutePath(), OutputFormat.MUXER_OUTPUT_MPEG_4);
    muxer.addTrack(tracks[0].getTrackFormat(0)),
    muxer.addTrack(tracks[1].getTrackFormat(0))
};
long nextReport = NOTIFY_BYTES_INTERVAL;
muxer.start();
      muxer.writeSampleData(tracksIndex[i], buffer, info);
      written += info.size;
      done++;
try {
  if (muxer != null) {
    muxer.stop();
    muxer.release();

代码示例来源:origin: guardianproject/haven

try
  mMuxer = new MediaMuxer(outputPath,
      MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException ioe)
  mMuxer.stop();
  mMuxer.release();

代码示例来源:origin: ChillingVan/AndroidInstantVideo

@Override
  public void close() {
    isStart = false;
    if (mMuxer != null) {
      mMuxer.stop();
      mMuxer.release();
      mMuxer = null;
    }
  }
});

代码示例来源:origin: guoxiaoxing/phoenix

public void writeSampleData(SampleType sampleType, ByteBuffer byteBuf, MediaCodec.BufferInfo bufferInfo) {
  if (mStarted) {
    mMuxer.writeSampleData(getTrackIndexForSampleType(sampleType), byteBuf, bufferInfo);
    return;
  }
  byteBuf.limit(bufferInfo.offset + bufferInfo.size);
  byteBuf.position(bufferInfo.offset);
  if (mByteBuffer == null) {
    mByteBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE).order(ByteOrder.nativeOrder());
  }
  mByteBuffer.put(byteBuf);
  mSampleInfoList.add(new SampleInfo(sampleType, bufferInfo.size, bufferInfo));
}

代码示例来源:origin: dingjikerbo/Android-RTSP

public int addTrack(MediaFormat trackFormat) {
  if (mStarted) {
    throw new IllegalStateException();
  }
  synchronized (mMuxer) {
    int track = mMuxer.addTrack(trackFormat);
    if (++mNumTracks == mExpectedNumTracks) {
      mMuxer.start();
      mStarted = true;
    }
    return track;
  }
}

代码示例来源:origin: aserbao/AndroidCamera

/**
 * Creates a muxer to write the encoded frames.
 *
 * <p>The muxer is not started as it needs to be started only after all streams have been added.
 */
private MediaMuxer createMuxer() throws IOException {
  return new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
}

代码示例来源:origin: ChillingVan/AndroidInstantVideo

@Override
public void onStart() {
  isStart = true;
  mMuxer.start();
}

代码示例来源:origin: WangShuo1143368701/WSLiveDemo

/**
 * assign encoder to muxer
 * @param format
 * @return minus value indicate error
 */
/*package*/ synchronized int addTrack(final MediaFormat format) {
  if (mIsStarted)
    throw new IllegalStateException("muxer already started");
  final int trackIx = mMediaMuxer.addTrack(format);
  if (DEBUG) Log.i(TAG, "addTrack:trackNum=" + mEncoderCount + ",trackIx=" + trackIx + ",format=" + format);
  return trackIx;
}

代码示例来源:origin: saki4510t/libcommon

@Override
public void stop() {
  if (mIsStarted) {
    mIsStarted = false;
    mMuxer.stop();
  }
}

代码示例来源:origin: saki4510t/libcommon

@Override
public void release() {
  mIsStarted = false;
  if (!mReleased) {
    mReleased = true;
    try {
      mMuxer.release();
    } catch (final Exception e) {
      Log.w(TAG, e);
    }
  }
}

代码示例来源:origin: WangShuo1143368701/WSLiveDemo

/**
 * request stop recording from encoder when encoder received EOS
*/
/*package*/ synchronized void stop() {
  if (DEBUG) Log.v(TAG,  "stop:mStatredCount=" + mStatredCount);
  mStatredCount--;
  if ((mEncoderCount > 0) && (mStatredCount <= 0)) {
    mMediaMuxer.stop();
    mMediaMuxer.release();
    mIsStarted = false;
    if (DEBUG) Log.v(TAG,  "MediaMuxer stopped:");
  }
}

代码示例来源:origin: WangShuo1143368701/WSLiveDemo

/**
 * write encoded data to muxer
 * @param trackIndex
 * @param byteBuf
 * @param bufferInfo
 */
/*package*/ synchronized void writeSampleData(final int trackIndex, final ByteBuffer byteBuf, final MediaCodec.BufferInfo bufferInfo) {
  if (mStatredCount > 0)
    mMediaMuxer.writeSampleData(trackIndex, byteBuf, bufferInfo);
}

代码示例来源:origin: windrunnerlihuan/DogCamera

public int addTrack(MediaFormat trackFormat) {
  if (mStarted) {
    throw new IllegalStateException();
  }
  synchronized (mMuxer) {
    int track = mMuxer.addTrack(trackFormat);
    if (++mNumTracks == mExpectedNumTracks) {
      mMuxer.start();
      mStarted = true;
    }
    return track;
  }
}

代码示例来源:origin: MasayukiSuda/GPUVideo-android

/**
 * Constructor
 */
public MediaMuxerCaptureWrapper(final String filePath) throws IOException {
  mediaMuxer = new MediaMuxer(filePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
  encoderCount = startedCount = 0;
  isStarted = false;
}

代码示例来源:origin: guoxiaoxing/phoenix

mMuxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
  setupMetadata();
  setupTrackTranscoders(formatStrategy);
  runPipelines();
  mMuxer.stop();
} finally {
  try {
      mMuxer.release();
      mMuxer = null;

代码示例来源:origin: saki4510t/libcommon

@Override
public void start() {
  mMuxer.start();
  mIsStarted = true;
}

代码示例来源:origin: saki4510t/AudioVideoRecordingSample

/**
 * assign encoder to muxer
 * @param format
 * @return minus value indicate error
 */
/*package*/ synchronized int addTrack(final MediaFormat format) {
  if (mIsStarted)
    throw new IllegalStateException("muxer already started");
  final int trackIx = mMediaMuxer.addTrack(format);
  if (DEBUG) Log.i(TAG, "addTrack:trackNum=" + mEncoderCount + ",trackIx=" + trackIx + ",format=" + format);
  return trackIx;
}

代码示例来源:origin: guoxiaoxing/phoenix

private void onSetOutputFormat() {
  if (mVideoFormat == null || mAudioFormat == null) return;
  mListener.onDetermineOutputFormat();
  mVideoTrackIndex = mMuxer.addTrack(mVideoFormat);
  Log.v(TAG, "Added track #" + mVideoTrackIndex + " with " + mVideoFormat.getString(MediaFormat.KEY_MIME) + " to muxer");
  mAudioTrackIndex = mMuxer.addTrack(mAudioFormat);
  Log.v(TAG, "Added track #" + mAudioTrackIndex + " with " + mAudioFormat.getString(MediaFormat.KEY_MIME) + " to muxer");
  mMuxer.start();
  mStarted = true;
  if (mByteBuffer == null) {
    mByteBuffer = ByteBuffer.allocate(0);
  }
  mByteBuffer.flip();
  Log.v(TAG, "Output format determined, writing " + mSampleInfoList.size() +
      " samples / " + mByteBuffer.limit() + " bytes to muxer.");
  MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
  int offset = 0;
  for (SampleInfo sampleInfo : mSampleInfoList) {
    sampleInfo.writeToBufferInfo(bufferInfo, offset);
    mMuxer.writeSampleData(getTrackIndexForSampleType(sampleInfo.mSampleType), mByteBuffer, bufferInfo);
    offset += sampleInfo.mSize;
  }
  mSampleInfoList.clear();
  mByteBuffer = null;
}

代码示例来源:origin: dingjikerbo/Android-RTSP

public boolean release() {
    synchronized (mMuxer) {
      if (++mNumReleases == mNumTracks) {
        mMuxer.stop();
        mMuxer.release();
        return true;
      }
    }
    return false;
  }
}

相关文章