user21728: 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?

user21728: 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

user1871: 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.

21728: <p>I'm trying to execute a two-pass encoding with compiled ffmpeg library in android.</p>

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

<blockquote>
  <p>Cannot write log file 'ffmpeg2pass-0.log' for pass-1 encoding:
  Read-only file system</p>
</blockquote>

<pre><code>List&lt;String&gt; testEncodeList = new LinkedList&lt;&gt;();
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&lt;String&gt; cmd = new LinkedList&lt;&gt;();
        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);
    }
});
</code></pre>

<p>Can I force log file <code>'ffmpeg2pass-0.log'</code> be written in a custom path where a non-rooted device could access?</p>
 21728: <p>Based on <a href="https://ffmpeg.org/ffmpeg-all.html#toc-Video-Options" rel="nofollow noreferrer">official doc</a>, the default value of <code>-passlogfile</code> is <strong><code>ffmpeg2pass-0.log</code></strong> 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.</p>

<p>The solution is to override <code>-passlogfile</code>:</p>

<p><code>-passlogfile /mnt/sdcard/myCustomPath  //without extension</code> </p>

<h3>full example of a <strong>Two-pass</strong> encoding</h3>

<pre><code>public static void run2PassEncoding(Context context) {

    List&lt;String&gt; pass1Commands = new LinkedList&lt;&gt;();

    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&lt;String&gt; pass2Commands = new LinkedList&lt;&gt;();
            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);
        }
    });

}
</code></pre>

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

<p>like this one:</p>

<p><a href="https://github.com/bravobit/FFmpeg-Android" rel="nofollow noreferrer">https://github.com/bravobit/FFmpeg-Android</a></p>

<p>or this one:</p>

<p><a href="http://writingminds.github.io/ffmpeg-android-java/" rel="nofollow noreferrer">http://writingminds.github.io/ffmpeg-android-java</a></p>
 1871: <p>You have to set the <code>-passlogfile</code> option e.g. <code>-passlogfile my/folder/path/fileprefix</code>. ffmpeg will then write logs to files starting with <code>fileprefix-</code> in <code>my/folder/path/</code>. Set the option and same value in latter passes. The folder path must already exist.</p>
