net.ypresto.androidtranscoder.format.MediaFormatStrategy Java Examples

The following examples show how to use net.ypresto.androidtranscoder.format.MediaFormatStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaTranscoderEngine.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void setupTrackTranscoders(MediaFormatStrategy formatStrategy) {
    MediaExtractorUtils.TrackResult trackResult = MediaExtractorUtils.getFirstVideoAndAudioTrack(mExtractor);
    MediaFormat videoOutputFormat = formatStrategy.createVideoOutputFormat(trackResult.mVideoTrackFormat);
    MediaFormat audioOutputFormat = formatStrategy.createAudioOutputFormat(trackResult.mAudioTrackFormat);
    if (videoOutputFormat == null && audioOutputFormat == null) {
        throw new InvalidOutputFormatException("MediaFormatStrategy returned pass-through for both video and audio. No transcoding is necessary.");
    }
    QueuedMuxer queuedMuxer = new QueuedMuxer(mMuxer, new QueuedMuxer.Listener() {
        @Override
        public void onDetermineOutputFormat() {
            MediaFormatValidator.validateVideoOutputFormat(mVideoTrackTranscoder.getDeterminedFormat());
            MediaFormatValidator.validateAudioOutputFormat(mAudioTrackTranscoder.getDeterminedFormat());
        }
    });

    if (videoOutputFormat == null) {
        mVideoTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, queuedMuxer, QueuedMuxer.SampleType.VIDEO);
    } else {
        mVideoTrackTranscoder = new VideoTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, videoOutputFormat, queuedMuxer);
    }
    mVideoTrackTranscoder.setup();
    if (audioOutputFormat == null) {
        mAudioTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, queuedMuxer, QueuedMuxer.SampleType.AUDIO);
    } else {
        mAudioTrackTranscoder = new AudioTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, audioOutputFormat, queuedMuxer);
    }
    mAudioTrackTranscoder.setup();
    mExtractor.selectTrack(trackResult.mVideoTrackIndex);
    mExtractor.selectTrack(trackResult.mAudioTrackIndex);
}
 
Example #2
Source File: MediaTranscoderEngine.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
private void setupTrackTranscoders(MediaFormatStrategy formatStrategy) {
    MediaExtractorUtils.TrackResult trackResult = MediaExtractorUtils.getFirstVideoAndAudioTrack(mExtractor);
    MediaFormat videoOutputFormat = formatStrategy.createVideoOutputFormat(trackResult.mVideoTrackFormat);
    MediaFormat audioOutputFormat = formatStrategy.createAudioOutputFormat(trackResult.mAudioTrackFormat);
    if (videoOutputFormat == null && audioOutputFormat == null) {
        throw new InvalidOutputFormatException("MediaFormatStrategy returned pass-through for both video and audio. No transcoding is necessary.");
    }
    QueuedMuxer queuedMuxer = new QueuedMuxer(mMuxer, new QueuedMuxer.Listener() {
        @Override
        public void onDetermineOutputFormat() {
            MediaFormatValidator.validateVideoOutputFormat(mVideoTrackTranscoder.getDeterminedFormat());
            MediaFormatValidator.validateAudioOutputFormat(mAudioTrackTranscoder.getDeterminedFormat());
        }
    });

    if (videoOutputFormat == null) {
        mVideoTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, queuedMuxer, QueuedMuxer.SampleType.VIDEO);
    } else {
        mVideoTrackTranscoder = new VideoTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, videoOutputFormat, queuedMuxer);
    }
    mVideoTrackTranscoder.setup();
    if (audioOutputFormat == null) {
        mAudioTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, queuedMuxer, QueuedMuxer.SampleType.AUDIO);
    } else {
        mAudioTrackTranscoder = new AudioTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, audioOutputFormat, queuedMuxer);
    }
    mAudioTrackTranscoder.setup();
    mExtractor.selectTrack(trackResult.mVideoTrackIndex);
    mExtractor.selectTrack(trackResult.mAudioTrackIndex);
}