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, 2022 in Others by nisha
• 2,210 points
1,858 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, 2022 by polo
• 1,480 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, 2022 in Others by gaurav
• 23,260 points
1,618 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, 2022 in Others by nisha
• 2,210 points
2,436 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, 2022 in Others by nisha
• 2,210 points
1,577 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, 2022 in Others by nisha
• 2,210 points
5,143 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,770 points
2,528 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, 2022 in Others by Soham
• 9,710 points
1,079 views
–1 vote
1 answer

"Default Activity Not Found" on Android Studio upgrade

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

answered Feb 11, 2022 in Others by Soham
• 9,710 points
1,233 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, 2022 in Others by Soham
• 9,710 points
3,356 views
+1 vote
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, 2022 in Others by polo
• 1,480 points
9,028 views
0 votes
1 answer

Android open camera from button

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

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