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 :
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 :
represent the input and you can append as many as you want.
and add this according to the number of inputs accordingly as [0:v]...[1:v].. and so on.
and also this parameter to be added according the number of inputs.
Give the value of n according to the number of videos.
So those are the main things that needs to be taken care of.