本文整理汇总了Java中android.media.MediaMuxer类的典型用法代码示例。如果您正苦于以下问题:Java MediaMuxer类的具体用法?Java MediaMuxer怎么用?Java MediaMuxer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaMuxer类属于android.media包,在下文中一共展示了MediaMuxer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAudioMuxer
import android.media.MediaMuxer; //导入依赖的package包/类
public synchronized void createAudioMuxer() throws IllegalStateException{
if (Thread.currentThread().isInterrupted()) {
release();
}
if ( isExternalStorageWritable()) {
File encodedFile = new File(OUTPUT_FILENAME_DIR, "/movies/EncodedAudio.mp4");
if (encodedFile.exists()) {
boolean result = encodedFile.delete();
if (!result)
throw new IllegalStateException("Unable to delete video file");
}
String outputPath = encodedFile.toString();
int format = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4;
try {
mAudioMuxer = new MediaMuxer(outputPath, format);
} catch (IOException e) {
Log.e(TAG, "Audio temp Muxer failed to create!!");
}
}
}
示例2: createMuxer
import android.media.MediaMuxer; //导入依赖的package包/类
/********************************************************************************
* Create a MediaMuxer. We can't add the video track and start() the muxer here,
* because our MediaFormat doesn't have the Magic Goodies. These can only be
* obtained from the encoder after it has started processing data.
**********************************************************************************/
@SuppressWarnings("all")
private synchronized void createMuxer() {
Log.d(TAG, "--->createMuxer()");
if ( isExternalStorageWritable()) {
File encodedFile = new File(OUTPUT_FILENAME_DIR, "/movies/EncodedAV" + "-" + mEncodingWidth + "x" + mEncodingHeight + ".mp4");
if (encodedFile.exists()) {
encodedFile.delete();
}
String outputPath = encodedFile.toString();
int format = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4;
try {
mMuxer = new MediaMuxer(outputPath, format);
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage());
}
mVideoTrackIndex = -1;
mMuxerStarted = false;
}
}
示例3: prepare
import android.media.MediaMuxer; //导入依赖的package包/类
@Override
public void prepare(EncodingConfig config) {
super.prepare(config);
try {
switch (config.getFormat()) {
case MPEG4:
mMuxer = new MediaMuxer(config.getOutputPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
break;
default:
throw new IllegalArgumentException("Unrecognized format!");
}
} catch (IOException e) {
throw new RuntimeException("MediaMuxer creation failed", e);
}
}
示例4: prepareEncoder
import android.media.MediaMuxer; //导入依赖的package包/类
private void prepareEncoder() {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat( MIME_TYPE, mSource.getWidth(), mSource.getHeight() );
format.setInteger( MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface );
format.setInteger( MediaFormat.KEY_BIT_RATE, mBitRate );
format.setInteger( MediaFormat.KEY_FRAME_RATE, FRAME_RATE );
format.setInteger( MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL );
mEncoder = MediaCodec.createEncoderByType( MIME_TYPE );
mEncoder.configure( format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE );
mSurface = mEncoder.createInputSurface();
mEncoder.start();
try {
mMuxer = new MediaMuxer( mUri.toString(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4 );
} catch ( IOException ioe ) {
throw new RuntimeException( "MediaMuxer creation failed", ioe );
}
mTrackIndex = -1;
mMuxerStarted = false;
}
示例5: addTrack
import android.media.MediaMuxer; //导入依赖的package包/类
@Override
public int addTrack(MediaFormat mediaFormat) {
int ret=-1;
synchronized (Lock){
if(!muxStarted){
if(audioTrack==-1&&videoTrack==-1){
try {
mMuxer=new MediaMuxer(path,MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException e) {
e.printStackTrace();
AvLog.e("create MediaMuxer failed:"+e.getMessage());
}
}
String mime=mediaFormat.getString(MediaFormat.KEY_MIME);
if(mime.startsWith("audio")){
audioTrack=mMuxer.addTrack(mediaFormat);
ret=audioTrack;
}else if(mime.startsWith("video")){
videoTrack=mMuxer.addTrack(mediaFormat);
ret=videoTrack;
}
startMux();
}
}
return ret;
}
示例6: run
import android.media.MediaMuxer; //导入依赖的package包/类
@SuppressLint("NewApi")
@Override
public void run() {
try {
try {
prepareEncoder();
mMuxer = new MediaMuxer(mDstPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException e) {
throw new RuntimeException(e);
}
mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG + "-display",
mWidth, mHeight, mDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
mSurface, null, null);
Log.d(TAG, "created virtual display: " + mVirtualDisplay);
recordVirtualDisplay();
} finally {
release();
}
}
示例7: startRecord
import android.media.MediaMuxer; //导入依赖的package包/类
/**
* Start record a MP4 video. Need be called while stream.
*
* @param path where file will be saved.
* @throws IOException If you init it before start stream.
*/
public void startRecord(String path) throws IOException {
if (streaming) {
mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
if (videoFormat != null) {
videoTrack = mediaMuxer.addTrack(videoFormat);
}
if (audioFormat != null) {
audioTrack = mediaMuxer.addTrack(audioFormat);
}
mediaMuxer.start();
recording = true;
} else {
throw new IOException("Need be called while stream");
}
}
示例8: startRecord
import android.media.MediaMuxer; //导入依赖的package包/类
/**
* Start record a MP4 video. Need be called while stream.
*
* @param path where file will be saved.
* @throws IOException If you init it before start stream.
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public void startRecord(String path) throws IOException {
if (streaming) {
mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
if (videoFormat != null) {
videoTrack = mediaMuxer.addTrack(videoFormat);
}
if (audioFormat != null) {
audioTrack = mediaMuxer.addTrack(audioFormat);
}
mediaMuxer.start();
recording = true;
} else {
throw new IOException("Need be called while stream");
}
}
示例9: SohuMediaMuxerManager
import android.media.MediaMuxer; //导入依赖的package包/类
/**
* Constructor
*
* @param ext extension of output file
* @throws IOException
*/
public SohuMediaMuxerManager(String ext) throws IOException {
if (TextUtils.isEmpty(ext)) {
ext = ".mp4";
}
try {
// 输出文件路径
mOutputPath = getCaptureFile(ext).toString();
//
} catch (final NullPointerException e) {
throw new RuntimeException("This app has no permission of writing external storage");
}
// 编码器
mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
//
mEncoderCount = mStatredCount = 0;
//
mIsStarted = false;
}
示例10: VideoEncoderCore
import android.media.MediaMuxer; //导入依赖的package包/类
/**
* Configures encoder and muxer state, and prepares the input Surface.
*/
public VideoEncoderCore(int width, int height, int bitRate, File outputFile)
throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE) Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mInputSurface = mEncoder.createInputSurface();
mEncoder.start();
// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
// obtained from the encoder after it has started processing data.
//
// We're not actually interested in multiplexing audio. We just want to convert
// the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
mMuxer = new MediaMuxer(outputFile.toString(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mTrackIndex = -1;
mMuxerStarted = false;
}
示例11: startRecord
import android.media.MediaMuxer; //导入依赖的package包/类
public void startRecord() throws IOException {
synchronized (REC_LOCK){
isRecordStarted=true;
MediaFormat audioFormat=mConfig.getAudioFormat();
mAudioEncoder=MediaCodec.createEncoderByType(audioFormat.getString(MediaFormat.KEY_MIME));
mAudioEncoder.configure(audioFormat,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
MediaFormat videoFormat=mConfig.getVideoFormat();
mVideoEncoder=MediaCodec.createEncoderByType(videoFormat.getString(MediaFormat.KEY_MIME));
//此处不能用mOutputSurface,会configure失败
mVideoEncoder.configure(videoFormat,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncodeSurface=mVideoEncoder.createInputSurface();
mAudioEncoder.start();
mVideoEncoder.start();
mMuxer=new MediaMuxer(mOutputPath,MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mRecordBufferSize = AudioRecord.getMinBufferSize(mRecordSampleRate,
mRecordChannelConfig, mRecordAudioFormat)*2;
// buffer=new byte[bufferSize];
mAudioRecord=new AudioRecord(MediaRecorder.AudioSource.MIC,mRecordSampleRate,mRecordChannelConfig,
mRecordAudioFormat,mRecordBufferSize);
mAudioThread=new Thread(new Runnable() {
@Override
public void run() {
mAudioRecord.startRecording();
while (!audioEncodeStep(isTryStopAudio)){};
mAudioRecord.stop();
}
});
mAudioThread.start();
isRecordAudioStarted=true;
}
}
示例12: MediaMuxerWraper
import android.media.MediaMuxer; //导入依赖的package包/类
public MediaMuxerWraper(String path, int format) throws IOException {
mMuxer=new MediaMuxer(path,format);
datas=new LinkedBlockingQueue<>(30);
recycler=new Recycler<>();
ThreadFactory factory= Executors.defaultThreadFactory();
mExec=new ThreadPoolExecutor(1,1,1,TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>(16),factory);
}
示例13: MMediaMuxer
import android.media.MediaMuxer; //导入依赖的package包/类
public MMediaMuxer(File outputFile) {
// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
// obtained from the encoder after it has started processing data.
try {
mMuxer = new MediaMuxer(outputFile.toString(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
startCount=0;
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: MpegEncoder
import android.media.MediaMuxer; //导入依赖的package包/类
/** Constructs a new {@link MpegEncoder} */
private MpegEncoder(@NonNull Builder builder, @NonNull MediaFormat format,
@NonNull String path) throws IOException {
checkState();
mFrameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
mEncoder = MediaCodec.createEncoderByType(format.getString(MediaFormat.KEY_MIME));
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mSurface = mEncoder.createInputSurface();
mInputSurface =
InputSurface.create (
mSurface,
builder.inputBuffer,
builder.width,
builder.height
)
.autoSwap()
.build();
mMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
if (builder.mLocation != null) {
mMuxer.setLocation(builder.mLocation.x, builder.mLocation.y);
}
if (builder.mOrientation != 0) {
mMuxer.setOrientationHint(builder.mOrientation);
}
mOutputBuffers = start();
}
示例15: prepareEncoder
import android.media.MediaMuxer; //导入依赖的package包/类
/**
* Prepares the video encoder, muxer, and an input surface.
*/
private void prepareEncoder(File outputFile) throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, WIDTH, HEIGHT);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMES_PER_SECOND);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE) Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mInputSurface = mEncoder.createInputSurface();
mEncoder.start();
// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
// obtained from the encoder after it has started processing data.
//
// We're not actually interested in multiplexing audio. We just want to convert
// the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
if (VERBOSE) Log.d(TAG, "output will go to " + outputFile);
mMuxer = new MediaMuxer(outputFile.toString(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mTrackIndex = -1;
mMuxerStarted = false;
}