Reference http://www.cnblogs.com/jrvin/archive/2011/04/25/2027368.html
1. first, compile FFMPEG with Android ndk to generate a link library of about 5 MB (refer to the previous article), and place it in the corresponding platform directory, such as C: \ android-ndk-r6 \ platforms \ Android-9 \ arch-Arm \ USR \ Lib
2. Create an android program, the API should correspond to the above, such as the andorid-9 to create a JNI folder, enter, put the previously compiled FFMPEG code into the re-name FFMPEG folder. Create the Android. mk file and ffmpegtest. c file in JNI. The content is as follows:
3. Then use the nkd command to compile:
./Ndk-Build-C/home/s_jrvin/workspace/jnitest
Libjnitest. So is generated under libs \ armeabi \ under the project root directory. Yes .. Haha ..
Copy libffmpeg. So to libs \ armeabi \ under the project root directory.
Run the android program and print the log information.
Main program. Java
Package vplayer. test; import android. app. activity; import android. OS. bundle; import android. util. log; public class vplayer extends activity {public native int version ();/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); int x = version (); log. D ("version", String. valueof (x);} static {system. loadlibrary ("FFMPEG"); // call the so system compiled before FFMPEG. loadlibrary ("jnitest"); // call libjnitest compiled by ndk. so }}
Android. mk:
Local_path: = $ (call my-DIR) include $ (clear_vars) local_module: = jnitest // so name local_src_files: = ffmpegtest. C // used. c file local_c_includes + =$ (local_path)/FFMPEG/$ (local_path)/FFMPEG/libavutil/$ (local_path)/FFMPEG/libavcodec/$ (local_path) /FFMPEG/libavformat/$ (local_path)/FFMPEG/libavcodec/$ (local_path)/FFMPEG/libswscale/local_ldlibs + =-lffmpeginclude $ (build_shared_library)
Path_to_ffmpeg_source: = $ (local_path)/FFMPEG
This line defines a variable, that is, the path of the FFMPEG source code.
Local_c_shortdes + = $ (path_to_ffmpeg_source)
This line specifies the source code path, that is, the FFMPEG source code copied just now. $ (local_path) is the root directory, if this line is not added, the hfile in the ffmpeg library will be introduced for compilation, and the hfile cannot be found.
Local_ldlibs: =-lffmpeg
This line is very important. This indicates that your so runtime depends on libffmpeg. for example, if you want to compile the so library, you must not only use libffmpeg. so this library also uses libopencv. so, your parameter should be written
Local_ldlibs: =-lffmpeg-lopencv
Other parameters are normally compiled and used by ndk. If you don't understand them, Google it.
Ffmpegtest. c
# Include <JNI. h> # include <stdio. h> jniexport jint jnicall java_vplayer_test_vplayer_version // this function can be generated using javah. For details, see the previous article (jnienv * EVN, jobject OBJ) {return (INT) avcodec_version ();}