當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaMuxer類代碼示例

本文整理匯總了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!!");
        }
    }
}
 
開發者ID:tonyconstantinides,項目名稱:LiveMultimedia,代碼行數:21,代碼來源:AudioEncoder.java

示例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;
    }
}
 
開發者ID:tonyconstantinides,項目名稱:LiveMultimedia,代碼行數:25,代碼來源:GPUEncoder.java

示例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);
    }

}
 
開發者ID:cine-io,項目名稱:cineio-broadcast-android,代碼行數:18,代碼來源:AndroidMuxer.java

示例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;
}
 
開發者ID:hoolrory,項目名稱:AndroidVideoSamples,代碼行數:25,代碼來源:SurfaceEncoder.java

示例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;
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:27,代碼來源:StrengthenMp4MuxStore.java

示例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();
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:22,代碼來源:ScreenRecorder.java

示例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");
  }
}
 
開發者ID:pedroSG94,項目名稱:rtmp-rtsp-stream-client-java,代碼行數:22,代碼來源:Camera2Base.java

示例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");
  }
}
 
開發者ID:pedroSG94,項目名稱:rtmp-rtsp-stream-client-java,代碼行數:23,代碼來源:Camera1Base.java

示例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;
}
 
開發者ID:xiaxveliang,項目名稱:GLES2_AUDIO_VIDEO_RECODE,代碼行數:25,代碼來源:SohuMediaMuxerManager.java

示例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;
}
 
開發者ID:zpf527,項目名稱:EffectCamera,代碼行數:38,代碼來源:VideoEncoderCore.java

示例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;
        }
    }
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:34,代碼來源:CameraRecorder.java

示例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);
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:8,代碼來源:MediaMuxerWraper.java

示例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();
    }
}
 
開發者ID:zhangyaqiang,項目名稱:Fatigue-Detection,代碼行數:13,代碼來源:MMediaMuxer.java

示例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();
}
 
開發者ID:Nik-Gleb,項目名稱:mpeg-encoder,代碼行數:32,代碼來源:MpegEncoder.java

示例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;
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:38,代碼來源:SoftInputSurfaceActivity.java


注:本文中的android.media.MediaMuxer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。