Java Ffmpeg-在android中将视频分成30秒的部分
我正在做一个项目。我想把视频分成30秒相等的部分。如果视频的长度比理想情况下的30秒和15秒长45秒。我已经创建了一个方法,该方法取起点和终点,并运行Ffmpeg命令来剪切视频。这就是我到目前为止创造的Java Ffmpeg-在android中将视频分成30秒的部分,java,android,ffmpeg,video-processing,Java,Android,Ffmpeg,Video Processing,我正在做一个项目。我想把视频分成30秒相等的部分。如果视频的长度比理想情况下的30秒和15秒长45秒。我已经创建了一个方法,该方法取起点和终点,并运行Ffmpeg命令来剪切视频。这就是我到目前为止创造的 private void executeCutVideoCommand(int startMs, int endMs) { File moviesDir = Environment.getExternalStoragePublicDirectory(
private void executeCutVideoCommand(int startMs, int endMs) {
File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES
);
String filePrefix = "cut_video";
String fileExtn = ".mp4";
String yourRealPath = getPath(VideoCutterActivity.this, selectedVideoUri);
File dest = new File(moviesDir, filePrefix + fileExtn);
int fileNo = 0;
while (dest.exists()) {
fileNo++;
dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
}
filePath = dest.getAbsolutePath();
String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", yourRealPath, "-t", "" + (endMs - startMs) / 1000,"-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};
execFFmpegBinary(complexCommand);
MediaScannerConnection.scanFile(VideoCutterActivity.this,
new String[] { filePath },
null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}
/**
* Executing ffmpeg binary
*/
private void 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);
Intent intent = new Intent(VideoCutterActivity.this, PreviewActivity.class);
intent.putExtra(FILEPATH, filePath);
startActivity(intent);
}
@Override
public void onProgress(String s) {
progressDialog.setMessage("progress : " + s);
}
@Override
public void onStart() {
progressDialog.setMessage("Processing...");
progressDialog.show();
}
@Override
public void onFinish() {
progressDialog.dismiss();
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
}
我试图在方法调用中添加一个循环,但应用程序崩溃了
cutVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
choice = 2;
if (selectedVideoUri != null) {
int start,end;
for (int i=0;i<=duration;i=i+30){
start=i;
end=start+30;
executeCutVideoCommand(start,end);
}
// executeCutVideoCommand(rangeSeekBar.getSelectedMinValue().intValue() * 1000, rangeSeekBar.getSelectedMaxValue().intValue() * 1000);
} else
Snackbar.make(mainlayout, "Please upload a video", 4000).show();
}
});
}
cutVideo.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
选择=2;
if(selectedVideoUri!=null){
int开始,结束;
对于(int i=0;i是相关的,如何分割文件..首先让它在CLI环境(而不是android)中工作。然后将类似脚本的一系列CLI命令传输到android中,确保它们不会同时运行(在循环中)它们应该是序列化的。我不明白你的回答。你能详细说明ffmpeg吗?或者代码有问题吗?