作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个应用程序,它合并两个或两个以上的视频文件,这些文件是我从另一个 Activity 中获得的。选择文件后,我们将文件传递给发生合并的另一个 Activity 。我已经按照这个链接做同样的事情:AndroidWarZone FFMPEG
在这里,我找到了如何仅合并具有不同质量的两个文件的方法。命令如下:
String[] complexCommand = {"ffmpeg","-y","-i","/storage/emulated/0/videokit/sample.mp4",
"-i","/storage/emulated/0/videokit/in.mp4","-strict","experimental",
"-filter_complex",
"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k","/storage/emulated/0/vk2_out/out.mp4"}
private void mergeVideos() {
String savingPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4";
ArrayList<File> fileList = mList;
List<String> filenames = new ArrayList<String>();
for (int i = 0; i < fileList.size(); i++) {
filenames.add("-i");
filenames.add(fileList.get(i).toString());
}
Log.e("Log===",filenames.toString());
String joined = TextUtils.join(", ",filenames);
Log.e("Joined====",joined);
String complexCommand[] = {"-y", joined,
"-filter_complex",
"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k", savingPath};
Log.e("RESULT====",Arrays.toString(complexCommand));
execFFmpegBinary(complexCommand); }
E/RECEIVED DATA=====: [/mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4]
E/RESULT====: [-y, -i, /mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, -i, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4, -filter_complex, [0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1, -ab, 48000, -ac, 2, -ar, 22050, -s, 640x480, -r, 30, -vcodec, mpeg4, -b, 2097k, /storage/emulated/0/video.mp4]
private void execFFmpegBinary(final String[] combine) {
try{
fFmpeg.execute(combine, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.d("", "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d("", "SUCCESS with output : " + s);
Toast.makeText(getApplicationContext(),"Success!",Toast.LENGTH_SHORT)
.show();
}
@Override
public void onProgress(String s) {
Log.d("", "progress : " + s);
}
@Override
public void onStart() {
progressDialog.setMessage("Processing...");
progressDialog.show();
}
@Override
public void onFinish() {
progressDialog.dismiss();
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
}
E/FFMPEG====: ffmpef : coorect loaded
complexCommand = new String[]{"-y", "-i", file1.toString(), "-i", file2.toString(), "-strict", "experimental", "-filter_complex",
"[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1","-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", rootPath + "/output.mp4"};
最佳答案
请先使用演示,确保它在您的设备上运行。
如果是这样,请从博客中获取合并命令,并在演示中使用它。
现在,在您的应用程序中尝试一个简单的命令,如果它有效,请尝试合并命令。
如果其中任何步骤失败,请直接与我联系。
关于Android使用FFMPEG合并两个具有不同(大小,编解码器,帧,宽高比)的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46051764/
我是一名优秀的程序员,十分优秀!