Lame MP3 Encoder compile for Android

16,883

Solution 1

There used to be a good blog post on how to compile lame for Android, but for some reason it's been offline for a while and only available on some dodgy Chinese sites.

I'll just copy the content below:

porting compiling lame encoder to Android ARM arch using Android NDK

I was looking for a mp3 encoding application in Android Market, and found very few, the reason I think Android doesn't support mp3 encoding is because mp3 is patented technology. Another reason is I guess people prefer Java programming and Android SDK rather than Android native development kit.

Nevertheless compiling libmp3lame library for Android using Android NDK is very easy actually.

  1. download Android NDK(also you need Android SDK and Eclipse with ADT plugin) and create simple project.
  2. create directory called "jni" in your project's directory.
  3. download lame sources, extract, copy all sources from directory libmp3lame to jni directory. Also copy lame.h which is located in include directory of lame sources.
  4. create jni/Android.mk file. it should look like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)`
LOCAL_MODULE    := mp3lame
LOCAL_SRC_FILES := bitstream.c fft.c id3tag.c mpglib_interface.c presets.c  quantize.c   reservoir.c tables.c  util.c  VbrTag.c
   encoder.c  gain_analysis.c lame.c  newmdct.c   psymodel.c
   quantize_pvt.c set_get.c  takehiro.c vbrquantize.c version.c
include $(BUILD_SHARED_LIBRARY)
  1. clean lame sources, remove what's left from GNU autotools, Makefile.am, Makefile.in, libmp3lame_vc8.vcproj, logoe.ico, depcomp, folders i386, vector.
  2. edit file jni/utils.h, and replace definition extern ieee754_float32_t fast_log2(ieee754_float32_t x); with this extern float fast_log2(float x);
  3. go to the root directory of your Android project and run $pathtoandroidndk/ndk-build and you're done, you'll have limp3lame.so compiled.

Also, the following question on SO might be of interest for you, as it deals with some issues after compiling lame for Android:

Solution 2

The above solution worked for me except:

  • don't delete the vector directory from the source directory
  • you can get rid of the compile warnings by adding a compiler flag: LOCAL_CFLAGS = -DSTDC_HEADERS
Share:
16,883
Cool Java guy מוחמד
Author by

Cool Java guy מוחמד

I am Android developer, I am working in IT industry since 2001. I started my career as a network engineer and then I switched my career in programming in 2006. Since Jan-2006 I am working in Java technology. My most of the experience in J2ME and Android. Since May-2010 I started working for Android platform and now I am full time Android developer. I am developing various applications for the Android platform. Soon I'll add my new application from the Android market.

Updated on June 03, 2022

Comments

  • Cool Java guy מוחמד
    Cool Java guy מוחמד about 2 years

    I want to compile the lame encoder for Android. How can I find the tutorials for Lame and its compiling for Android platform.

    Thanks,

  • Zhou Chang
    Zhou Chang over 11 years
    1. Don't remove vector floder; 2. Some source include lame.h using "lame.h" some source using <lame.h>, so you must add -I./ flags in Android.mk
  • frankish
    frankish over 10 years
    How to compile it as a static library that can be used with ffmpeg?
  • exploitr
    exploitr over 5 years
    I'm having an mp3 file with just noise like radio without signal after converting any webm/wav