Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3c3f60c

Browse files
committed
Add public interface for audio transcoding
1 parent cf15da5 commit 3c3f60c

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
4848
}
4949
};
5050
MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(),
51-
MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); // or createAndroid720pStrategy([your bit rate here])
51+
MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); // or createAndroid720pStrategy([your bitrate here])
5252
}
5353
```
5454

‎example/src/main/java/net/ypresto/androidtranscoder/example/TranscoderActivity.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void onTranscodeFailed(Exception exception) {
104104
};
105105
Log.d(TAG, "transcoding into " + file);
106106
mFuture = MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(),
107-
MediaFormatStrategyPresets.createAndroid720pStrategy(), listener);
107+
MediaFormatStrategyPresets.createAndroid720pStrategy(8000 * 1000, 128 * 1000, 1), listener);
108108
switchButtonEnabled(true);
109109
}
110110
break;

‎lib/src/main/java/net/ypresto/androidtranscoder/format/Android16By9FormatStrategy.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import android.util.Log;
2121

2222
class Android16By9FormatStrategy implements MediaFormatStrategy {
23+
public static final int AUDIO_BITRATE_AS_IS = -1;
24+
public static final int AUDIO_CHANNELS_AS_IS = -1;
2325
public static final int SCALE_720P = 5;
2426
private static final String TAG = "Android16By9FormatStrategy";
2527
private final int mScale;
@@ -28,7 +30,7 @@ class Android16By9FormatStrategy implements MediaFormatStrategy {
2830
private final int mAudioChannels;
2931

3032
public Android16By9FormatStrategy(int scale, int videoBitrate) {
31-
this(scale, videoBitrate, 0, 0);
33+
this(scale, videoBitrate, AUDIO_BITRATE_AS_IS, AUDIO_CHANNELS_AS_IS);
3234
}
3335

3436
public Android16By9FormatStrategy(int scale, int videoBitrate, int audioBitrate, int audioChannels) {
@@ -74,7 +76,7 @@ public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
7476

7577
@Override
7678
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
77-
if (mAudioBitrate == 0 || mAudioChannels == 0) return null;
79+
if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;
7880

7981
// Use original sample rate, as resampling is not supported yet.
8082
final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,

‎lib/src/main/java/net/ypresto/androidtranscoder/format/Android720pFormatStrategy.java‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,26 @@
2020
import android.util.Log;
2121

2222
class Android720pFormatStrategy implements MediaFormatStrategy {
23+
public static final int AUDIO_BITRATE_AS_IS = -1;
24+
public static final int AUDIO_CHANNELS_AS_IS = -1;
2325
private static final String TAG = "720pFormatStrategy";
2426
private static final int LONGER_LENGTH = 1280;
2527
private static final int SHORTER_LENGTH = 720;
26-
private static final int DEFAULT_BITRATE = 8000 * 1000; // From Nexus 4 Camera in 720p
27-
private final int mVideoBitRate;
28+
private static final int DEFAULT_VIDEO_BITRATE = 8000 * 1000; // From Nexus 4 Camera in 720p
29+
private final int mVideoBitrate;
2830
private final int mAudioBitrate;
2931
private final int mAudioChannels;
3032

3133
public Android720pFormatStrategy() {
32-
this(DEFAULT_BITRATE, 0, 0);
34+
this(DEFAULT_VIDEO_BITRATE);
3335
}
3436

3537
public Android720pFormatStrategy(int videoBitrate) {
36-
this(videoBitrate, 0, 0);
38+
this(videoBitrate, AUDIO_BITRATE_AS_IS, AUDIO_CHANNELS_AS_IS);
3739
}
3840

3941
public Android720pFormatStrategy(int videoBitrate, int audioBitrate, int audioChannels) {
40-
mVideoBitRate = videoBitrate;
42+
mVideoBitrate = videoBitrate;
4143
mAudioBitrate = audioBitrate;
4244
mAudioChannels = audioChannels;
4345
}
@@ -67,7 +69,7 @@ public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
6769
}
6870
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
6971
// From Nexus 4 Camera in 720p
70-
format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitRate);
72+
format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitrate);
7173
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
7274
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
7375
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
@@ -76,7 +78,7 @@ public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
7678

7779
@Override
7880
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
79-
if (mAudioBitrate == 0 || mAudioChannels == 0) return null;
81+
if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;
8082

8183
// Use original sample rate, as resampling is not supported yet.
8284
final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,

‎lib/src/main/java/net/ypresto/androidtranscoder/format/MediaFormatStrategyPresets.java‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ public static MediaFormatStrategy createAndroid720pStrategy() {
3434
/**
3535
* Preset based on Nexus 4 camera recording with 720p quality.
3636
* This preset is ensured to work on any Android >=4.3 devices by Android CTS (if codec is available).
37+
* Audio track will be copied as-is.
3738
*
38-
* @param bitRate Preferred bit rate for encoding.
39+
* @param bitrate Preferred bitrate for video encoding.
3940
*/
40-
public static MediaFormatStrategy createAndroid720pStrategy(int bitRate) {
41-
return new Android720pFormatStrategy(bitRate);
41+
public static MediaFormatStrategy createAndroid720pStrategy(int bitrate) {
42+
return new Android720pFormatStrategy(bitrate);
43+
}
44+
45+
/**
46+
* Preset based on Nexus 4 camera recording with 720p quality.
47+
* This preset is ensured to work on any Android >=4.3 devices by Android CTS (if codec is available).
48+
* <p/>
49+
* Note: audio transcoding is experimental feature.
50+
*
51+
* @param bitrate Preferred bitrate for video encoding.
52+
* @param audioBitrate Preferred bitrate for audio encoding.
53+
* @param audioChannels Output audio channels.
54+
*/
55+
public static MediaFormatStrategy createAndroid720pStrategy(int bitrate, int audioBitrate, int audioChannels) {
56+
return new Android720pFormatStrategy(bitrate, audioBitrate, audioChannels);
4257
}
4358

4459
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /