2

I'm using https://github.com/hiteshsondhi88/ffmpeg-android-java in an app that needs to combine multiple mp4 files into one.

Here is a command

ffmpeg -i concat:"/data/data/com.testapp.app/cache:temp/lds82df9skov65i15k3ct16cik.mp4|/data/data/com.testapp.app/cache:temp/qm5s0utmb8c1gbhch6us2tnilo.mp4" -codec copy /data/data/com.testapp.app/cache:temp/4egqalludvs03tnfleu5dgb6iv.mp4

java method to append files, movie files is an array holding files i want to combine

public void appendFiles() {

    showProgressDialog();

    movieFile = getRandomFile();

    StringBuilder b = new StringBuilder();

    try {

        for (int i = 0; i < movieFiles.size(); i++) {

            File f = movieFiles.get(i);

            if (!f.exists()) {
                continue;
            }

            if(i != 0){
                b.append("|");
            }

            b.append(f.getPath());


        }

        final String command = "-i concat:\""+b.toString() + "\" -codec copy " + movieFile.getPath();



        try {
            ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
                @Override
                public void onFailure(String s) {
                    app.log("FAILED with output : " + s);
                }

                @Override
                public void onSuccess(String s) {
                    app.log("SUCCESS with output : " + s);

                    createThumbnail();

                    stopProgressDialog();

                    startReview();
                }

                @Override
                public void onProgress(String s) {
                    app.log("Started command : ffmpeg " + command);

                }

                @Override
                public void onStart() {

                    app.log("Started command : ffmpeg " + command);

                }

                @Override
                public void onFinish() {
                    app.log("Finished command : ffmpeg " + command);

                }
            });
        }
        catch (FFmpegCommandAlreadyRunningException e) {
            e.printStackTrace();
        }


    }

    catch (Exception e) {
        e.printStackTrace();
    }

}

and getRandomFile()

    public File getRandomFile() {
        if (captureDir != null) {
            if (captureDir.exists()) {

                SecureRandom random = new SecureRandom();
                File file = new File(captureDir, new BigInteger(130, random).toString(32) + ".mp4");
                return file;
            }
        }
        return null;
    }

but I keep seeing the error no such file or directory

concat:"/data/data/com.testapp.app/cache:temp/lds82df9skov65i15k3ct16cik.mp4|/data/data/com.testapp.app/cache:temp/qm5s0utmb8c1gbhch6us2tnilo.mp4": No such file or directory

any ideas?

Brian
  • 4,328
  • 13
  • 58
  • 103

3 Answers3

1

You can use following command. ffmpeg -f concat -i list.txt -c:v copy -c:a copy result.mp4

But if you will store files' full path in list.txt file like

file '/sdcard/blabla/v0.mp4'
file '/sdcard/blabla/v1.mp4'
file '/sdcard/blabla/v2.mp4'

then you need to add -safe 0 flag.

ffmpeg -f concat -safe 0 -i list.txt -c:v copy -c:a copy result.mp4

And usage in the library you use is like:

String[] cmd = new String[]{"-f", "concat", "-safe", "0", "-i", "list.txt", "-c", "copy", "-preset", "ultrafast", outFile};

ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler()
{

    @Override
    public void onFailure(String message)
    {
    }
    @Override
    public void onSuccess(String message)
    {
    }
    @Override
    public void onProgress(String message)
    {
    }

    @Override
    public void onStart()
    {
    }

    @Override
    public void onFinish()
    {
    }
}
Gokhan Celikkaya
  • 716
  • 1
  • 7
  • 17
0

I just got through this. Command

ffmpeg -i "concat:file1.mp4|file2.mp4" 

won't work. You have to save list of your files into text file, and then fire:

ffmpeg -f concat -i list.txt -c:v copy -c:a copy result.mp4

Try it - I was using the same library.

0

Quite late: but this concept may be helpful to the person seeking for the solution to such problem.
The possible reason might be the two videos are having different sample rate and frame rate. So you need to first convert or transcode it into the same rate.after which you can concatenate the respective videos.

Dila Gurung
  • 1,726
  • 21
  • 26