Android uses FFMPEG instance programs

Source: Internet
Author: User

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 ();}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.