Skip to content

Commit

Permalink
add enum VideoFormatMimeType
Browse files Browse the repository at this point in the history
  • Loading branch information
MasayukiSuda committed Jan 13, 2020
1 parent 0bb5aa0 commit 672f4ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.daasuu.mp4compose;

import android.media.MediaFormat;

public enum VideoFormatMimeType {
HEVC(MediaFormat.MIMETYPE_VIDEO_HEVC),
AVC(MediaFormat.MIMETYPE_VIDEO_AVC),
MPEG4(MediaFormat.MIMETYPE_VIDEO_MPEG4),
H263(MediaFormat.MIMETYPE_VIDEO_H263),
AUTO("");

private final String videoFormatMimeType;

VideoFormatMimeType(String videoFormatMimeType) {
this.videoFormatMimeType = videoFormatMimeType;
}

public String getFormat() {
return videoFormatMimeType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.daasuu.mp4compose.FillMode;
import com.daasuu.mp4compose.FillModeCustomItem;
import com.daasuu.mp4compose.Rotation;
import com.daasuu.mp4compose.VideoFormatMimeType;
import com.daasuu.mp4compose.filter.GlFilter;
import com.daasuu.mp4compose.logger.AndroidLogger;
import com.daasuu.mp4compose.logger.Logger;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class Mp4Composer {
private boolean flipHorizontal = false;
private long trimStartMs = 0;
private long trimEndMs = -1;
private String videoFormatMimeType;
private VideoFormatMimeType videoFormatMimeType = VideoFormatMimeType.AUTO;
private EGLContext shareContext;

private ExecutorService executorService;
Expand Down Expand Up @@ -156,7 +157,7 @@ public Mp4Composer timeScale(final int timeScale) {
return this;
}

public Mp4Composer videoFormatMimeType(String videoFormatMimeType) {
public Mp4Composer videoFormatMimeType(@NonNull VideoFormatMimeType videoFormatMimeType) {
this.videoFormatMimeType = videoFormatMimeType;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import android.media.*;
import android.opengl.EGLContext;
import android.os.Build;
import android.text.TextUtils;
import android.util.Size;
import androidx.annotation.NonNull;
import com.daasuu.mp4compose.FillMode;
import com.daasuu.mp4compose.FillModeCustomItem;
import com.daasuu.mp4compose.Rotation;
import com.daasuu.mp4compose.VideoFormatMimeType;
import com.daasuu.mp4compose.filter.GlFilter;
import com.daasuu.mp4compose.logger.Logger;
import com.daasuu.mp4compose.source.DataSource;
Expand Down Expand Up @@ -63,7 +63,7 @@ void compose(
final boolean flipHorizontal,
final long trimStartMs,
final long trimEndMs,
final String videoFormatMimeType,
final VideoFormatMimeType videoFormatMimeType,
final EGLContext shareContext
) throws IOException {

Expand Down Expand Up @@ -172,34 +172,34 @@ void compose(
}

@NonNull
private static MediaFormat createVideoOutputFormatWithAvailableEncoders(final String mimeType,
private static MediaFormat createVideoOutputFormatWithAvailableEncoders(@NonNull final VideoFormatMimeType mimeType,
final int bitrate,
@NonNull final Size outputResolution) {
final MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);

if (!TextUtils.isEmpty(mimeType)) {
final MediaFormat mediaFormat = createVideoFormat(mimeType, bitrate, outputResolution);
if (mimeType != VideoFormatMimeType.AUTO) {
final MediaFormat mediaFormat = createVideoFormat(mimeType.getFormat(), bitrate, outputResolution);
if (mediaCodecList.findEncoderForFormat(mediaFormat) != null) {
return mediaFormat;
}
}

final MediaFormat hevcMediaFormat = createVideoFormat(MediaFormat.MIMETYPE_VIDEO_HEVC, bitrate, outputResolution);
final MediaFormat hevcMediaFormat = createVideoFormat(VideoFormatMimeType.HEVC.getFormat(), bitrate, outputResolution);
if (mediaCodecList.findEncoderForFormat(hevcMediaFormat) != null) {
return hevcMediaFormat;
}

final MediaFormat avcMediaFormat = createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, bitrate, outputResolution);
final MediaFormat avcMediaFormat = createVideoFormat(VideoFormatMimeType.AVC.getFormat(), bitrate, outputResolution);
if (mediaCodecList.findEncoderForFormat(avcMediaFormat) != null) {
return avcMediaFormat;
}

final MediaFormat mp4vesMediaFormat = createVideoFormat(MediaFormat.MIMETYPE_VIDEO_MPEG4, bitrate, outputResolution);
final MediaFormat mp4vesMediaFormat = createVideoFormat(VideoFormatMimeType.MPEG4.getFormat(), bitrate, outputResolution);
if (mediaCodecList.findEncoderForFormat(mp4vesMediaFormat) != null) {
return mp4vesMediaFormat;
}

return createVideoFormat(MediaFormat.MIMETYPE_VIDEO_H263, bitrate, outputResolution);
return createVideoFormat(VideoFormatMimeType.H263.getFormat(), bitrate, outputResolution);
}

@NonNull
Expand Down

0 comments on commit 672f4ae

Please sign in to comment.