使用FFMPEG命令无法合并视频 [英] Unable to merge videos using FFMPEG Commands
问题描述
我试图用FFMPEG合并两个视频在Android和我一直在关注的Android战区博客这给伟大的思想和简单的方法来FFMPEG在我们的项目整合。不过,我在合并两个视频所面临的问题。
命令:
vk.run(新的String [] {
FFMPEG
-F,
CONCAT
-一世,
列表中,
-s
HD720
-C,
复制,
-b
br_from_db +K,
路径+/+merged_video_3.mp4
},work_path,getActivity());
和在上面的命令中的名单是我现在面临一个issue.It一个抛出我下面的错误,当我使用下面的方法:
code:
私人字符串generateList(字符串[]输入){
文件列表;
作家作家=无效;
尝试{
清单= File.createTempFile(ffmpeg的名单,名.txt);
作家=新的BufferedWriter(新OutputStreamWriter(新的FileOutputStream(列表)));
对于(字符串输入:输入){
writer.write(文件+输入+的'\\ n);
Log.d(TAG,写列表文件:文件'+输入+');
}
}赶上(IOException异常五){
e.printStackTrace();
返回/;
} {最后
尝试{
如果(作家!= NULL)
writer.close();
}赶上(IOException异常前){
ex.printStackTrace();
}
}
Log.d(TAG,写道:列表文件+ list.getAbsolutePath());
返回list.getAbsolutePath();
}
错误:
19 12-16:49:57.416 5437-5437 /? E / ffmpeg4android:命令验证失败。
12-16 19:49:57.416 5437-5437 /? E / ffmpeg4android:请检查输入文件是否存在: /data/data/com.family45.golive.family45v1/cache/ffmpeg-list-1803386407.txt/storage/emulated/0/DCIM/Camera/dec24.mp4 /storage/emulated/0/DCIM/Camera/vid2.mp4
12-16 19:49:57.416 5437-5437 /? W / System.err的:com.netcompss.ffmpeg4android.CommandValidationException
12-16 19:49:57.416 5437-5437 /? W / System.err的:在com.netcompss.loader.LoadJNI.run(LoadJNI.java:34)
12-16 19:49:57.416 5437-5437 /? W / System.err的:在com.netcompss.loader.LoadJNI.run(LoadJNI.java:49)
我从<一个获得命令href=\"http://stackoverflow.com/questions/20325615/android-concatenate-two-videos/20358243?noredirect=1#comment56374313_20358243\">this堆栈问题。它接受,但我面对上述问题。我非常肯定的影片都在各自的位置present,所有的路径是正确的,但我似乎无法使其工作。
在这个任何见解是非常AP preciated。提前致谢。
更新:
呼吁generateList:
的ArrayList&LT;串GT; paths_to_merge =新的ArrayList&LT;串GT;();
paths_to_merge.add(路径+/+dec24.mp4);
paths_to_merge.add(路径+/+vid2.mp4);
LoadJNI VK =新LoadJNI();
的String [] = V12新的String [paths_to_merge.size()];
V12 = paths_to_merge.toArray(V12);
字符串列表= generateList(V12);
我不知道哪里出了问题我的code,我还是没能来与右边的列表。然而,我发现这似乎是做工不错另一个命令。
命令:
vk.run(新的String [] {的ffmpeg, - Y, - 我,路径+/+num1.mp4, - 我路径+/+num2.mp4, - 我,路径+/+num3.mp4, - 我,路径+/+num4.mp4
-i,created_folder +/+created_video2.mp4, - 严,实验,
-filter_complex
\"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[2:v]scale=640x480,setsar=1:1[v2];[3:v]scale=640x480,setsar=1:1[v3];\" +
[4:V]比例= 640×480,setsar = 1:1 [V4]; [V0] [0:一个] [V1] [1:] [V2] [2:一个] [V3] [3:一] [V4] [4:]的concat = N = 5:v = 1:A = 1,
-ab,48000, - 交流,2, - 芳,22050, - S,640×480, - R,30, - V codeC,mpeg4的, - b,2097k,路径+/+numbers_video_m.mp4},路径getActivity());
你可以在命令中看到的,我已经为附加测试的目的5视频,但我相信,我们可以动态地添加更多的视频,这工作没有任何问题,我。
要注意的事情:
- 我,路径+/+num1.mp4
再present输入,你可以添加你想要的。
[0:V] =规模640×480,setsar = 1:1 [V0]
和根据相应的输入的数量添加此[0:V] ... [1:V] ..等。
[V0] [0:一]
和还根据输入的数量被加入该参数。
CONCAT = N = 5:V = 1:1 =
根据视频的数目给n的值。
因此,这些都是需要被照顾的主要的东西。
I am trying to merge two videos in Android using FFMPEG and I have been following the Android War Zone blog which gives great ideas and simple methods to integrate FFMPEG in our project. However, I am facing issues in merging two videos.
Command :
vk.run(new String[]{
"ffmpeg",
"-f",
"concat",
"-i",
list,
"-s",
"hd720",
"-c",
"copy",
"-b",
br_from_db + "k",
path + "/" + "merged_video_3.mp4"
}, work_path, getActivity());
And the "list" in the above command is the one where I am facing a issue.It throws me the following error when I use the following method :
Code :
private String generateList(String[] inputs) {
File list;
Writer writer = null;
try {
list = File.createTempFile("ffmpeg-list", ".txt");
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
for (String input : inputs) {
writer.write("file '" + input + "'\n");
Log.d(TAG, "Writing to list file: file '" + input + "'");
}
} catch (IOException e) {
e.printStackTrace();
return "/";
} finally {
try {
if (writer != null)
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
Log.d(TAG, "Wrote list file to " + list.getAbsolutePath());
return list.getAbsolutePath();
}
Error :
12-16 19:49:57.416 5437-5437/? E/ffmpeg4android﹕ Command validation failed.
12-16 19:49:57.416 5437-5437/? E/ffmpeg4android﹕ Check if input file exists: /data/data/com.family45.golive.family45v1/cache/ffmpeg-list-1803386407.txt/storage/emulated/0/DCIM/Camera/dec24.mp4 /storage/emulated/0/DCIM/Camera/vid2.mp4
12-16 19:49:57.416 5437-5437/? W/System.err﹕ com.netcompss.ffmpeg4android.CommandValidationException
12-16 19:49:57.416 5437-5437/? W/System.err﹕ at com.netcompss.loader.LoadJNI.run(LoadJNI.java:34)
12-16 19:49:57.416 5437-5437/? W/System.err﹕ at com.netcompss.loader.LoadJNI.run(LoadJNI.java:49)
I obtained the command from this stack question. Its accepted but I am facing the above issue. I am very sure that the videos are present in their respective locations and all the paths are right but I cant seem to make it work.
Any insights on this is highly appreciated. Thanks in advance.
Update :
Call to generateList:
ArrayList<String> paths_to_merge = new ArrayList<String>();
paths_to_merge.add(path + "/" + "dec24.mp4");
paths_to_merge.add(path + "/" + "vid2.mp4");
LoadJNI vk = new LoadJNI();
String[] v12 = new String[paths_to_merge.size()];
v12 = paths_to_merge.toArray(v12);
String list = generateList(v12);
I am not sure what went wrong in my code, I am still not able to come with the right list. However, I found another command which seems to be working good.
Command :
vk.run(new String[]{"ffmpeg","-y","-i",path + "/" + "num1.mp4","-i",path + "/" + "num2.mp4","-i",path + "/" + "num3.mp4","-i",path + "/" + "num4.mp4",
"-i",created_folder + "/" + "created_video2.mp4","-strict","experimental",
"-filter_complex",
"[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[2:v]scale=640x480,setsar=1:1[v2];[3:v]scale=640x480,setsar=1:1[v3];" +
"[4:v]scale=640x480,setsar=1:1[v4];[v0][0:a][v1][1:a][v2][2:a][v3][3:a][v4][4:a] concat=n=5:v=1:a=1",
"-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k",path + "/" + "numbers_video_m.mp4"},path,getActivity());
As you can see in the command, I have appended 5 videos for the purpose of testing but I believe that we can add more videos dynamically and this works without any issues for me.
Things to be noted :
"-i",path + "/" + "num1.mp4"
represent the input and you can append as many as you want.
[0:v]scale=640x480,setsar=1:1[v0];
and add this according to the number of inputs accordingly as [0:v]...[1:v].. and so on.
[v0][0:a]
and also this parameter to be added according the number of inputs.
concat=n=5:v=1:a=1
Give the value of n according to the number of videos.
So those are the main things that needs to be taken care of.
这篇关于使用FFMPEG命令无法合并视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!