/
CustomAndroidFormatStrategy.java
69 lines (57 loc) · 2.36 KB
/
CustomAndroidFormatStrategy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.apache.cordova.videoeditor;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.util.Log;
import net.ypresto.androidtranscoder.format.MediaFormatStrategy;
import net.ypresto.androidtranscoder.format.OutputFormatUnavailableException;
/**
* Created by ehmm on 02.05.2016.
*
*
*/
public class CustomAndroidFormatStrategy implements MediaFormatStrategy {
private static final String TAG = "CustomFormatStrategy";
private static final int DEFAULT_BITRATE = 8000000;
private static final int DEFAULT_FRAMERATE = 30;
private static final int DEFAULT_SHORT_LENGTH = 720;
private final int mBitRate;
private final int mFrameRate;
private final int mShorterLength;
public CustomAndroidFormatStrategy() {
this.mBitRate = DEFAULT_BITRATE;
this.mFrameRate = DEFAULT_FRAMERATE;
this.mShorterLength = DEFAULT_SHORT_LENGTH;
}
public CustomAndroidFormatStrategy(final int bitRate, final int frameRate, final int shorterLength) {
this.mBitRate = bitRate;
this.mFrameRate = frameRate;
this.mShorterLength = shorterLength;
}
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger("width");
int height = inputFormat.getInteger("height");
int outWidth;
int outHeight;
if(width > mShorterLength || height > mShorterLength) {
if(width >= height) {
outWidth = Double.valueOf((width * mShorterLength)/(double) height).intValue();
outHeight = mShorterLength;
} else {
outWidth = mShorterLength;
outHeight = Double.valueOf((height * mShorterLength)/(double) width).intValue();
}
} else {
outHeight = height;
outWidth = width;
}
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, mFrameRate);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
return format;
}
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
return null;
}
}