修剪MP3文件编程 [英] Trim mp3 file programmatically

查看:204
本文介绍了修剪MP3文件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿<>我要修剪/剪切/编辑我的应用程序一段音频文件,我试图用ffmpeg的,但我不知道如何安装这个库或如何甚至用它..所以,可有人给我一个很好的指导如何使用ffmpeg的2.3与Android NDK R10为Windows 7 64位?或任何其他建议如何削减mp3文件?

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 ?

当我加入的ffmpeg库到我的项目,我在控制台收到此错误:

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.

和所有的东西像 R.raw.music R.menu.actionbarmenu R.layout.activity 现在的错误,:研究不能被解析为一个变量也行的ffmpeg - 牛逼30 -i inputfile.mp3 -a codeC副本outputfile.mp3 是错误的:

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 :)

推荐答案

有一些开源的Andr​​oid的ffmpeg项目,这似乎是最常用的或讨论之中一个:

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

这提供了一个Android平台上的ffmpeg和相关项目提供了一个Java包装(使用调用Runtime.getRuntime()EXEC的方式,而不是JNI,因为我原以为),让你从一个普通的Java的Andr​​oid应用程序使用它:

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.

的正在使用的ffmpeg二进制的Java包装项目方法声明的一些例子如下所示。你可以看到完整的code文件中的Android的ffmpeg的-的Java / SRC /组织/的ffmpeg /安卓/ FfmpegController.java在android-的ffmpeg-java项目已下载:

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
{ ...

如果你看看这些,你应该能够看到如何添加一个不正是您所需要。从本质上讲,这些方法调用CMD线ffmpeg的所需特定任务的参数,使用调用Runtime.getRuntime()。exec函数。

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.

这几件事情要注意,使用调用Runtime.getRuntime()过去的经验Exec的Andr​​oid上:

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

  • 在早期版本的Andr​​oid有bug意味着调用Runtime.getRuntime()EXEC有时会挂起:<一href="http://stackoverflow.com/a/11411709/334402">http://stackoverflow.com/a/11411709/334402
  • 调用Runtime.getRuntime()EXEC需慎用 - 看看这个链接了解更多信息:的http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html
  • 据我所知,你需要有根的设备上使用调用Runtime.getRuntime()。EXEC在Android上。这可能已经改变,因为我上次看的,但值得一试,如果这是你的应用程序非常重要的。
  • Earlier versions of Android had a bug that means that Runtime.getRuntime().exec would sometimes hang: http://stackoverflow.com/a/11411709/334402
  • Runtime.getRuntime().exec needs to be used with caution - take a look at this link for more info: http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html
  • As far as I am aware you need to be on a rooted device to use Runtime.getRuntime().exec on Android. This may have changed since I last looked, but worth checking if this is important for your application.

这篇关于修剪MP3文件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆