tcking / GiraffeCompressor

video compressor on android
70 stars 27 forks source link

android 11 not working #24

Open dineshchavhan opened 3 years ago

dineshchavhan commented 3 years ago

files/ffmpeg": error=13, Permission denied

dineshchavhan commented 3 years ago

Caused by: java.io.IOException: error=13, Permission denied at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.(UNIXProcess.java:133)

VivekThummar52 commented 3 years ago

in Android 10/11, according to new storage policy you can't save file in any public directory(as of i know for ffmpeg), so what i have tried is i saved output file to app specific private directory(in Android/data/app_folder/cache/output_file) and then i moved the file to wherever i want(programmatically using InputStream and OutputStream), here's that code for moving file:

// file - output file converted using ffmpeg
// outputUri - new destination

private void copyCacheToOriginal(File file, Uri outputUri) {
    try {
        InputStream in = new FileInputStream(file);
        try {
            OutputStream out = getContentResolver().openOutputStream(outputUri);
            try {
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                file.delete();
            } finally {
                out.close();
            }
        } finally {
            in.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(this, "Error Copying File", Toast.LENGTH_SHORT).show();
    }
}