0

I'm trying to execute a two-pass encoding with compiled ffmpeg library in android.

I'm running my app on a device that is not rooted. So after executing below commands I get :

Cannot write log file 'ffmpeg2pass-0.log' for pass-1 encoding: Read-only file system

List<String> testEncodeList = new LinkedList<>();
testEncodeList.add("-i");
testEncodeList.add(inputPath);
testEncodeList.add("-pass");
testEncodeList.add("1");
testEncodeList.add("-f");
testEncodeList.add("null");
testEncodeList.add("-");
// cmd.add("/dev/null");
runSingleFFmpegTask(this, testEncodeList, new ExecuteBinaryResponseHandler() {
    @Override
    public void onSuccess(String message) {
        super.onSuccess(message);
        SRLog.i("FFMPEG_PASS1:" + "onSuccess" + "\n" + message);


        List<String> cmd = new LinkedList<>();
        cmd.add("-i");
        cmd.add(inputPath);
        cmd.add("-pass");
        cmd.add("2");
        cmd.add(generateOutput(MP4_FORMAT));
        runSingleFFmpegTask(AudioComp.this, cmd, new ExecuteBinaryResponseHandler() {
            @Override
            public void onSuccess(String message) {
                super.onSuccess(message);
                SRLog.i("FFMPEG_PASS2:" + "onSuccess" + "\n" + message);
            }

            @Override
            public void onFailure(String message) {
                super.onFailure(message);
                SRLog.i("FFMPEG_PASS2:" + "onFailure" + "\n" + message);
            }
        });


    }

    @Override
    public void onFailure(String message) {
        super.onFailure(message);
        SRLog.i("FFMPEG_PASS1:" + "onFailure" + "\n" + message);
    }
});

Can I force log file 'ffmpeg2pass-0.log' be written in a custom path where a non-rooted device could access?

2

You have to set the -passlogfile option e.g. -passlogfile my/folder/path/fileprefix. ffmpeg will then write logs to files starting with fileprefix- in my/folder/path/. Set the option and same value in latter passes. The folder path must already exist.

2
  • is this option has any extra setting to clean itself after encoding is finished? I mean any logs that is generated by this option to be deleted after process is done. I can't keep track .log files name. – S.R Aug 11 '19 at 4:16
  • I don't see one. You may open a ticket at trac.ffmpeg.org, if you like. – Gyan Aug 11 '19 at 5:36
1

Based on official doc, the default value of -passlogfile is ffmpeg2pass-0.log which if you do not override when using two pass encoding, ffmpeg will try to write this file in the system path where a non rooted device doesn't like, so encoding process will fail.

The solution is to override -passlogfile:

-passlogfile /mnt/sdcard/myCustomPath //without extension

full example of a Two-pass encoding

public static void run2PassEncoding(Context context) {

    List<String> pass1Commands = new LinkedList<>();

    String tempLogPath = "/storage/emulated/0/2passLog";
    String inputPath = "/storage/emulated/0/myVideo.mp4";
    String output = "/storage/emulated/0/output.mp4";

    pass1Commands.add("-y");
    pass1Commands.add("-i");
    pass1Commands.add(inputPath);
    pass1Commands.add("-codec:v");
    pass1Commands.add("libx264");
    pass1Commands.add("-passlogfile");
    pass1Commands.add(tempLogPath);
    pass1Commands.add("-preset");
    pass1Commands.add("veryfast");
    pass1Commands.add("-b:v");
    pass1Commands.add("500k");
    pass1Commands.add("-maxrate");
    pass1Commands.add("500k");
    pass1Commands.add("-bufsize");
    pass1Commands.add("1000k");
    pass1Commands.add("-vf");
    pass1Commands.add("scale=420:-2");
    pass1Commands.add("-pass");
    pass1Commands.add("1");
    pass1Commands.add("-an");

    pass1Commands.add("-f");
    pass1Commands.add("null");
    pass1Commands.add("-");



    runSingleFFmpegTask(context, pass1Commands, new ExecuteBinaryResponseHandler() {
        @Override
        public void onSuccess(String message) {
            super.onSuccess(message);
            Log.i("FFMPEG_PASS1: " + "onSuccess" , message);

            List<String> pass2Commands = new LinkedList<>();
            pass2Commands.add("-y");
            pass2Commands.add("-i");
            pass2Commands.add(inputPath);
            pass2Commands.add("-codec:v");
            pass2Commands.add("libx264");
            pass2Commands.add("-passlogfile");
            pass2Commands.add(tempLogPath);
            pass2Commands.add("-preset");
            pass2Commands.add("fast");
            pass2Commands.add("-b:v");
            pass2Commands.add("500k");
            pass2Commands.add("-maxrate");
            pass2Commands.add("500k");
            pass2Commands.add("-bufsize");
            pass2Commands.add("1000k");
            pass2Commands.add("-vf");
            pass2Commands.add("scale=420:-2");
            pass2Commands.add("-pass");
            pass2Commands.add("2");
            pass2Commands.add("-codec:a");
            pass2Commands.add("libfdk_aac");
            pass2Commands.add("-b:a");
            pass2Commands.add("128k");
            pass2Commands.add(output);

            runSingleFFmpegTask(context, pass2Commands, new ExecuteBinaryResponseHandler() {
                @Override
                public void onSuccess(String message) {
                    super.onSuccess(message);
                    Log.i("FFMPEG_PASS2: " + "onSuccess" , message);
                }
            });
        }





        @Override
        public void onFailure(String message) {
            super.onFailure(message);
            Log.i("FFMPEG_PASS1:" + "onFailure" + "\n" , message);
        }
    });

}

note: if you don't know how to use ffmpeg in android, start by using pre compiled ffmpeg.

like this one:

https://github.com/bravobit/FFmpeg-Android

or this one:

http://writingminds.github.io/ffmpeg-android-java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.