-
Notifications
You must be signed in to change notification settings - Fork 53
multiple_files
chriszeng87 edited this page Sep 6, 2017
·
7 revisions
由于多个文件中音视频的config信息可能不一致,需要将文件转码成同一格式的文件并合并成单一的文件。短视频SDK中提供KSYMergeKit来处理多个视频文件的导入
目前支持的文件类型与单个文件导入相同:mp4/mov/3gp
/**
* start transcode and merge
*
* @param srcFiles source file url
* @param outputFile dest file url
* @param transCodeTmpDir temporary file directory for transcode
* @param autoDeleteTmpDir flag of auto delete transcoded temporary files
*/
public void start(final List<Uri> srcFiles, String outputFile, String transCodeTmpDir,boolean autoDeleteTmpDir)
/**
* stop transcode and merge
*/
public void stop()
/**
* get current transcoding files progress
*/
public float getTranscodeProgress()
/**
* get current transcoding files id
*/
public int getCurrentTransFileId()
- 设置视频码率:[setVideoBitrate(int bps)]
- 设置音频频码率:[setAudioBitrate(int bps)]
- 自定义分辨率设置:[setTargetSize (int width, int height)]
可通过 [setEncodeMethod(int)]接口设置。可取值有:
- StreamerConstants.ENCODE_METHOD_SOFTWARE 使用H.264软编码
- StreamerConstants.METHOD_HARDWARE 使用H.264硬编码
- 可通过 [setVideoFps(float fps)]设置。
- 可通过 [setAudioChannels(int channels)]设置。
- 可通过 [setAudioSampleRate(int sampleRate)]设置
KSYMergeKit类中提供以下两种回调接口
- OnInfoListener 包含编辑和合成过程中状态变更事件回调,状态码为正数
- OnErrorListener 包含编辑和合成过程中错误事件回调,状态码为负数
名称 | 数值 | 含义 | msgs |
---|---|---|---|
INFO_TRANSCODE_UNSUPPORT | 1 | 不支持文件格式 | |
INFO_TRANSCODE_STOPBYUSERS | 2 | 用户终止转码 | |
ERROR_TRANSCODE_FAILED | -1 | 转码失败 | 失败原因错误码 |
INFO_MERGE_FINISH | 100 | 合成结束 | 合成后文件路径,一般为start时传入的文件路径 |
ERROR_MERGE_FAILED | -100 | 合成失败 | 失败原因错误码 |
ERROR_MERGE_EMPTY | -101 | 合成文件为空 | 导入文件均不支持转码时触发此回调 |
private KSYMergeKit.OnInfoListener mOnInfoListener = new KSYMergeKit.OnInfoListener() {
@Override
public void onInfo(int type, String msg) {
switch (type) {
case KSYMergeKit.INFO_MERGE_FINISH:
//转码结束
if (mTranscodeDialog != null) {
mTranscodeDialog.dismiss();
mTranscodeDialog = null;
}
EditActivity.startActivity(ConfigActivity.this, msg);
break;
case KSYMergeKit.INFO_TRANSCODE_UNSUPPORT:
//不支持当前转码文件的文件格式
Log.d(TAG, "onInfo: " + msg);
break;
case KSYMergeKit.INFO_TRANSCODE_STOPBYUSERS:
//转码过程中被手动停止
if (mTranscodeDialog != null) {
mTranscodeDialog.dismiss();
mTranscodeDialog = null;
}
Log.d(TAG, "onInfo: stopped by user");
default:
break;
}
}
};
private KSYMergeKit.OnErrorListener mOnErrorListener = new KSYMergeKit.OnErrorListener() {
@Override
public void onError(int type, int reason, long msg) {
Toast.makeText(ConfigActivity.this, "Transcode " +
"failed: " + type + ", reason:" + reason, Toast.LENGTH_SHORT).show();
switch (type) {
case KSYMergeKit.ERROR_MERGE_EMPTY:
case KSYMergeKit.ERROR_MERGE_FAILED:
if (mTranscodeDialog != null) {
mTranscodeDialog.dismiss();
mTranscodeDialog = null;
}
break;
default:
break;
}
}
};