Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied error #46

Open
kburra73 opened this issue Feb 1, 2021 · 1 comment
Open

Permission denied error #46

kburra73 opened this issue Feb 1, 2021 · 1 comment

Comments

@kburra73
Copy link

kburra73 commented Feb 1, 2021

I am using this code to convert my mp3 file in m4a because I want to merge audio and video files and using mp4parser library for this. But I red somewhere that mp4parser only works with m4a audio format. When executing this code I am getting this error "/data/user/0/com.jiviz.m4a: Permission denied".......My audio file is in string format..Log - V/Mux-------: ======/storage/emulated/0/DCIM/Jiviz_2021_02_01_07_15_33.mp4======/data/user/0/com.jiviz.app/files/songs/312mp3

public String mux(String videoFile, String audioFile) {
Log.v("Mux-------","======"+videoFile + "======"+audioFile);

    IConvertCallback callback = new IConvertCallback() {
        @Override
        public void onSuccess(File convertedFile) {
            Toast.makeText(CamRecorderActivity.this, "SUCCESS: " + convertedFile.getPath(), Toast.LENGTH_LONG).show();
        }
        @Override
        public void onFailure(Exception error) {
            Log.v("Conversion-------","======"+error.getMessage());
            Toast.makeText(CamRecorderActivity.this, "ERROR: " + error.getMessage(), Toast.LENGTH_LONG).show();
        }
    };
    Toast.makeText(this, "Converting audio file...", Toast.LENGTH_SHORT).show();
    AndroidAudioConverter.with(this)
            .setFile(new File(audioFile))
            .setFormat(AudioFormat.M4A)
            .setCallback(callback)
            .convert();

    Movie video = null;
    try {
        video = new MovieCreator().build(videoFile);
    } catch (RuntimeException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    Movie audio = null;
    try {
        audio = new MovieCreator().build(audioFile);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (NullPointerException e) {

        e.printStackTrace();
        return null;
    }
    int size = audio.getTracks().size();
    Track audioTrack = audio.getTracks().get((size - 1));
    video.addTrack(audioTrack);

    Container out = new DefaultMp4Builder().build(video);

    File myDirectory = new File(Environment.getExternalStorageDirectory(), "/Jiviz");
    if (!myDirectory.exists()) {
        myDirectory.mkdirs();
    }
    String filePath = myDirectory + "/video" + System.currentTimeMillis() + ".mp4";
    try {
        RandomAccessFile ram = new RandomAccessFile(String.format(filePath), "rw");
        FileChannel fc = ram.getChannel();
        out.writeContainer(fc);
        ram.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

// File file = new File(filePath);
Log.v("Filepath-------","========" +filePath);
return filePath;
}

@yyms3275
Copy link

I am using this code to convert my mp3 file in m4a because I want to merge audio and video files and using mp4parser library for this. But I red somewhere that mp4parser only works with m4a audio format. When executing this code I am getting this error "/data/user/0/com.jiviz.m4a: Permission denied".......My audio file is in string format..Log - V/Mux-------: ======/storage/emulated/0/DCIM/Jiviz_2021_02_01_07_15_33.mp4======/data/user/0/com.jiviz.app/files/songs/312mp3

public String mux(String videoFile, String audioFile) {
Log.v("Mux-------","======"+videoFile + "======"+audioFile);

    IConvertCallback callback = new IConvertCallback() {
        @Override
        public void onSuccess(File convertedFile) {
            Toast.makeText(CamRecorderActivity.this, "SUCCESS: " + convertedFile.getPath(), Toast.LENGTH_LONG).show();
        }
        @Override
        public void onFailure(Exception error) {
            Log.v("Conversion-------","======"+error.getMessage());
            Toast.makeText(CamRecorderActivity.this, "ERROR: " + error.getMessage(), Toast.LENGTH_LONG).show();
        }
    };
    Toast.makeText(this, "Converting audio file...", Toast.LENGTH_SHORT).show();
    AndroidAudioConverter.with(this)
            .setFile(new File(audioFile))
            .setFormat(AudioFormat.M4A)
            .setCallback(callback)
            .convert();

    Movie video = null;
    try {
        video = new MovieCreator().build(videoFile);
    } catch (RuntimeException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    Movie audio = null;
    try {
        audio = new MovieCreator().build(audioFile);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (NullPointerException e) {

        e.printStackTrace();
        return null;
    }
    int size = audio.getTracks().size();
    Track audioTrack = audio.getTracks().get((size - 1));
    video.addTrack(audioTrack);

    Container out = new DefaultMp4Builder().build(video);

    File myDirectory = new File(Environment.getExternalStorageDirectory(), "/Jiviz");
    if (!myDirectory.exists()) {
        myDirectory.mkdirs();
    }
    String filePath = myDirectory + "/video" + System.currentTimeMillis() + ".mp4";
    try {
        RandomAccessFile ram = new RandomAccessFile(String.format(filePath), "rw");
        FileChannel fc = ram.getChannel();
        out.writeContainer(fc);
        ram.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

// File file = new File(filePath);
Log.v("Filepath-------","========" +filePath);
return filePath;
}

I solved the same problem as below.
I solved the problem by using a different library.

https://github.com/tanersener/mobile-ffmpeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants