Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

ffmpeg - Why storage access functions not working on android 10 API-29 ? error=13, Permission denied?

This example code is to create video from images and music. Code running on till API level 28 but when I just upgrade to Build version 29 then it starts crashing. I tried the most solution but could not find the proper reason and solution.
Please let me know...

2

021-01-08 19:48:16.045 18413-19578/com.example.photovideomaker E/audio: io
    java.io.IOException: Cannot run program "/data/user/0/com.example.photovideomaker/files/ffmpeg": error=13, Permission denied
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
        at java.lang.Runtime.exec(Runtime.java:698)
        at java.lang.Runtime.exec(Runtime.java:563)
        at com.example.photovideomaker.service.CreateVideoService.joinAudio(CreateVideoService.java:252)
        at com.example.photovideomaker.service.CreateVideoService.createVideo(CreateVideoService.java:89)
        at com.example.photovideomaker.service.CreateVideoService.onHandleIntent(CreateVideoService.java:83)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: java.io.IOException: error=13, Permission denied
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
        at java.lang.ProcessImpl.start(ProcessImpl.java:141)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        at java.lang.Runtime.exec(Runtime.java:698)?
        at java.lang.Runtime.exec(Runtime.java:563)?
        at com.example.photovideomaker.service.CreateVideoService.joinAudio(CreateVideoService.java:252)?
        at com.example.photovideomaker.service.CreateVideoService.createVideo(CreateVideoService.java:89)?
        at com.example.photovideomaker.service.CreateVideoService.onHandleIntent(CreateVideoService.java:83)?
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)?
        at android.os.Handler.dispatchMessage(Handler.java:107)?
        at android.os.Looper.loop(Looper.java:214)?
        at android.os.HandlerThread.run(HandlerThread.java:67)?

This function throwing the error "On Process.runtime"

private void createVideo() {
        long startTime = System.currentTimeMillis();
        toatalSecond = (application.getSecond() * ((float) application.getSelectedImages().size())) - DEFAULT_FONT_SCALE;
        joinAudio();
        while (true) {
            if (ImageCreatorService.isImageComplate) {
                Log.e("image creation ", " complte");

                break;
            }else {
                Log.e("image creation ", "not complte");
            }
        }
        Log.e("createVideo", "video create start");
        new File(FileUtils.TEMP_DIRECTORY, "video.txt").delete();
        for (int i = 0; i < application.videoImages.size(); i++) {
            appendVideoLog(String.format("file '%s'", application.videoImages.get(i)));
        }

        File r0=new File(FileUtils.TEMP_DIRECTORY, "video.txt");
        String videoPath = new File(FileUtils.APP_DIRECTORY, getVideoName()).getAbsolutePath();
        String[] inputCode = application.getMusicData() != null ? new String[]{
                FileUtils.getFFmpeg(this), "-r",
                String.valueOf(BitmapDescriptorFactory.HUE_ORANGE / application.getSecond()),
                "-f", "concat", "-safe", "0", "-i", r0.getAbsolutePath(), "-i",
                audioFile.getAbsolutePath(), "-strict", "experimental", "-r", "30",
                "-t", String.valueOf(toatalSecond), "-c:v", "libx264", "-preset",
                "ultrafast", "-pix_fmt", "yuv420p", "-ac", "2", videoPath}
        : new String[]{FileUtils.getFFmpeg(this),
                "-r", String.valueOf(BitmapDescriptorFactory.HUE_ORANGE / application.getSecond()),
                "-f", "concat", "-i", r0.getAbsolutePath(), "-r", "30", "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", videoPath};

        System.gc();
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(inputCode);
            while (!Util.isProcessCompleted(process)) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                while (true) {
                    String line = reader.readLine();
                    if (line != null) {
                        Log.e("process", line);
                        appendLog(line);
                        final int incr = durationToprogtess(line);
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            public void run() {
                                if (receiver != null) {
                                    receiver.onVideoProgressUpdate(incr);
                                }
                            }
                        });
                        mBuilder.setProgress(100, ((int) ((75.0f * ((float) incr)) / 100.0f)) + 25, false);
                        mNotifyManager.notify(1001, mBuilder.build());
                    }else {
                        break;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            Util.destroyProcess(process);
        }
        mBuilder.setContentText("Video created :" + FileUtils.getDuration(System.currentTimeMillis() - startTime)).setProgress(0, 0, false);
        mNotifyManager.notify(1001, mBuilder.build());
        try {
            long fileSize = new File(videoPath).length();
            String artist = getResources().getString(R.string.artist_name);
            ContentValues values = new ContentValues();
            values.put("_data", videoPath);
            values.put("_size", Long.valueOf(fileSize));
            values.put("mime_type", "video/mp4");
            values.put("artist", artist);
            values.put("duration", Float.valueOf(toatalSecond * 1000.0f));
            getContentResolver().insert(Media.getContentUriForPath(videoPath), values);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        try {
            sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(new File(videoPath))));
        } catch (Exception e3) {
            e3.printStackTrace();
        }

        buildNotification(videoPath);
        final String str = videoPath;
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            public void run() {
                if (receiver != null) {
                    receiver.onVideoProgressUpdate(100);
                    receiver.onProgressFinish(str);
                }
            }
        });
        FileUtils.deleteTempDir();
       stopSelf();
    }

I have tried checking the directory in storage and check mkdir is working or not but this function purely works for creating video from a collection of images, themes, and audio. as per android


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...