3

Hey <> I need to trim / cut / edit a audio file in my app, I tried to use ffmpeg but I don't know how to install this library or how to even use it.. so , can someone give me a good guide how to use ffmpeg 2.3 with android ndk r10 for windows 7 64bit? or any other suggestion how to cut the mp3 file ?

When I am adding ffmpeg library to my project I get this errors at the Console:

    [2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] C:\Users\David\Workspace\RecordTheLast20Minutes\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] C:\Users\David\Workspace\RecordTheLast20Minutes\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] C:\Users\David\Workspace\RecordTheLast20Minutes\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
[2014-07-29 00:04:06 - RecordTheLast20Minutes] C:\Users\David\Workspace\RecordTheLast20Minutes\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:28 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:29 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:32 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:50 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:07:52 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:18 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-hdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-mdpi\ic_launcher.jpg:0: Originally defined here.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.png:0: error: Resource entry ic_launcher is already defined.
[2014-07-29 00:10:19 - RecordTheLast20Minutes] res\drawable-xhdpi\ic_launcher.jpg:0: Originally defined here.

And all the things like R.raw.music or R.menu.actionbarmenu R.layout.activity are now errors, : R cannot be resolved to a variable and also the line ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3 is an error:

Multiple markers at this line
    - Syntax error on token "copy", @ expected
    - Syntax error on token "inputfile", delete this 
     token
    - Syntax error on token(s), misplaced 
     construct(s)
    - Syntax error on token(s), misplaced 
     construct(s)
    - Syntax error on token "30", delete this token

Ty for helping :)

DAVIDBALAS1
  • 484
  • 10
  • 31
  • Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – AStopher Jul 28 '14 at 19:32
  • @zyboxinternational I haven't done nothing yet, I don't know how to use a tool or a library so I came her – DAVIDBALAS1 Jul 28 '14 at 20:31
  • Stack Overflow isn't here for people to ask for libraries. – AStopher Jul 28 '14 at 20:52
  • @zyboxinternational So can you see what I have commented on Mick answer? – DAVIDBALAS1 Jul 28 '14 at 20:59
  • Of cause. You need to comment on exactly what error you're getting, as 'I'm getting an error' isn't helpful. – AStopher Jul 28 '14 at 21:06

1 Answers1

2

There are a number of open source Android ffmpeg projects, the one which appears to be most used or discussed being:

https://github.com/guardianproject/android-ffmpeg

This provides ffmpeg on an Android platform and a related project provides a Java wrapper (using the Runtime.getRuntime().exec approach, not JNI as I thought originally) to allow you use it from a regular Java Android app:

https://github.com/guardianproject/android-ffmpeg-java

The top project above includes build instructions and some examples to test the installation.

Some examples of the Java Wrapper project method declarations that are using ffmpeg binary are shown below. You can see the full code in the file 'android-ffmpeg-java/src/org/ ffmpeg/android/FfmpegController.java' in the android-ffmpeg-java project you have downloaded:

public void extractAudio (Clip mdesc, String audioFormat, File audioOutPath, ShellCallback sc) throws IOException, InterruptedException 
    { ...

public void concatAndTrimFilesMPEG (ArrayList<Clip> videos,Clip out, boolean preConvert, ShellCallback sc) throws Exception
{ ...

public Clip convertToMPEG (Clip mediaIn, String outPath, ShellCallback sc) throws Exception
{ ...

If you take a look at these you should be able to see how to add one that does exactly what you require. Essentially, these methods call the cmd line ffmpeg with the parameters required for a specific task, using the Runtime.getRuntime().exec function.

A couple of things to be aware of, from past experience using Runtime.getRuntime().exec on Android:

Community
  • 1
  • 1
Mick
  • 24,231
  • 1
  • 54
  • 120
  • Ok, I downloaded this : https://github.com/guardianproject/android-ffmpeg-java .. Imported it to `Eclipse`, went to my project properties and under the `Android section` I added the `library (now I have android-ffmpeg-library and appcompat_v7_2)`, but still when im trying this code: ` ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3` I just get an error. – DAVIDBALAS1 Jul 28 '14 at 20:35
  • Looking at the 'R not resolving error' in your updated question: this is a common error in Android with a number of possible causes/solutions. Take a look at this question for more info/help: http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating – Mick Jul 29 '14 at 21:05
  • Looking at the ffmpeg errors, I think based on your questions elsewhere you are trying to execute the commands somehow without the Java wrapper maybe? I can't see any examples or documentation but if you take a look at the code in 'android-ffmpeg-java/src/org/ffmpeg/android/FfmpegController.java' in the project you downloaded you can see examples of how to invoke ffmpeg via the Java wrapper, which is what I think you want. I've updated the answer to show this. – Mick Jul 30 '14 at 17:39
  • Thank you, I have been stupid and I haven't checked how to trim a mp3 file before I started creating my application, I think I will give up. – DAVIDBALAS1 Jul 30 '14 at 19:14
  • ffmpeg library is not bulid in windows os 32bit – Ajay Nov 15 '14 at 05:20
  • You can use SoxController to solve your problem. Currently I did on this part too – sonida Apr 30 '15 at 08:30