使用此依赖项: 编译'com.writingminds:FFmpegAndroid:0.3.2'
我使用了吹码来进行视频压缩 public static final String VIDEOCODEC =“ - vcodec”; public static final String AUDIOCODEC =“ - acodec”;
public static final String VIDEOBITSTREAMFILTER = "-vbsf";
public static final String AUDIOBITSTREAMFILTER = "-absf";
public static final String VERBOSITY = "-v";
public static final String FILE_INPUT = "-i";
public static final String SIZE = "-s";
public static final String FRAMERATE = "-r";
public static final String FORMAT = "-f";
public static final String BITRATE_VIDEO = "-b:v";
public static final String BITRATE_AUDIO = "-b:a";
public static final String CHANNELS_AUDIO = "-ac";
public static final String FREQ_AUDIO = "-ar";
String [] complexCommand = {“ - y”,FILE_INPUT,yourRealPath,SIZE,“480x360”,FRAMERATE,“25”,VIDEOCODEC,“mpeg4”,BITRATE_VIDEO,“150k”,BITRATE_AUDIO,“48000”,CHANNELS_AUDIO, “2”,FREQ_AUDIO,“22050”,filePath};
/**
* Executing ffmpeg binary
*/
private static String execFFmpegBinary(final String[] command) {
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.d(TAG, "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d(TAG, "SUCCESS with output : " + s);
}
@Override
public void onProgress(String s) {
Log.d(TAG, "Started command : ffmpeg " + command);
Log.d(TAG, "progress : " + s);
}
@Override
public void onStart() {
Log.d(TAG, "Started command : ffmpeg " + command);
}
@Override
public void onFinish() {
Log.d(TAG, "Finished command : ffmpeg " + command);
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
return filePath;
}