extract audio in MP3 format from video in android

0 votes

I am using the below code to convert video to MP3:

File source = new File(sourceFile);
File target = new File(destFile);
audioAttributes = new AudioAttributes();

audioAttributes.setCodec("libmp3lame");
audioAttributes.setBitRate(new Integer(128000));
audioAttributes.setChannels(new Integer(2));
audioAttributes.setSamplingRate(new Integer(44100));

EncodingAttributes encodingAttributes = new EncodingAttributes();
encodingAttributes.setFormat("mp3");
encodingAttributes.setAudioAttributes(audioAttributes);

Encoder encoder = new Encoder();

try {
    encoder.encode(source, target, encodingAttributes);
} catch (EncoderException e) {
    e.printStackTrace();
}

But it is not working. Here is the error that I'm getting:

java.io.IOException: Error running exec(). Command: [/bin/chmod, 755, /data/data/com.example.videotomp3_demo/cache/jave-1/ffmpeg] Working Directory: null Environment: null
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.ProcessManager.exec(ProcessManager.java:211)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.Runtime.exec(Runtime.java:173)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.Runtime.exec(Runtime.java:128)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at it.sauronsoftware.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:85)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at it.sauronsoftware.jave.Encoder.<init>(Encoder.java:111)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at com.example.videotomp3_demo.MainActivity.onCreate(MainActivity.java:50)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.Activity.performCreate(Activity.java:6005)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:176)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:111)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.os.Looper.loop(Looper.java:194)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5576)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err: Caused by: java.io.IOException: No such file or directory
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.ProcessManager.exec(Native Method)
12-01 15:19:04.116 19702-19702/com.example.videotomp3_demo W/System.err:     at java.lang.Pr
Jun 16 in Others by nisha
• 2,160 points
12 views

1 answer to this question.

0 votes

Use FFMPEG for android U need to implement a method and u can use the following command to extract audio

ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac
answered Jun 16 by polo
• 1,500 points

Related Questions In Others

0 votes
1 answer

Change date format of cell in excel from dd.mm.yyyy to yyy/mm/dd ( excel version 2013 )

Hello :)   Excel’s Format Cells function can quickly ...READ MORE

answered Feb 9 in Others by gaurav
• 12,420 points
110 views
0 votes
1 answer

How to open YouTube video link in android app?

The below code will do that: Intent intent ...READ MORE

answered Jun 1 in Others by nisha
• 2,160 points
22 views
0 votes
1 answer

I am not able to Autoplay youTube video in android chrome

It will play if you set it to ...READ MORE

answered Jun 6 in Others by nisha
• 2,160 points
19 views
0 votes
2 answers

Code for download video from Youtube on Java, Android

Check the source code (HTML) of YouTube, ...READ MORE

answered Jun 9 in Others by nisha
• 2,160 points
21 views
0 votes
1 answer

Error: IllegalArgumentException: Unable to locate adb in Android Studio v2.3

when you try to move an Android project ...READ MORE

answered Dec 16, 2020 in Others by Gitika
• 65,850 points
1,663 views
0 votes
1 answer

How to take a screenshot of a current Activity and then share it?

For me, I captured and then shared ...READ MORE

answered Feb 8 in Others by Soham
• 8,730 points
15 views
0 votes
1 answer

"Default Activity Not Found" on Android Studio upgrade

If you see that ERROR occurrence after ...READ MORE

answered Feb 11 in Others by Soham
• 8,730 points
149 views
0 votes
1 answer

Invoke-customs are only supported starting with android 0 --min-api 26

After hours of working on this probleme, ...READ MORE

answered Feb 16 in Others by Soham
• 8,730 points
386 views
0 votes
1 answer

How To Create Phone Number Format XXX-XXX-XXXX In Android

 can try: private String formatNumbersAsCode(CharSequence s) { ...READ MORE

answered Jun 14 in Others by polo
• 1,500 points
24 views
0 votes
1 answer

Android open camera from button

you can use the below syntax as ...READ MORE

answered Jun 14 in Others by polo
• 1,500 points
6 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP