-
-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Description
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;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels