Extended Android Decoder Using FFMPEG framework

Source: Internet
Author: User

The multimedia framework opencore of the andorid platform supports the following audio formats: audio pp(.3gp-4、mpeg-4(.mp4 ,. m4a), MP3, Type 0 and 1 (. mid ,. xmf ,. mxmf ). also rtttl/RTx (. rtttl ,. RTX), audio) (commonly used relatively more than ,、wave(.wav). Only two video formats are supported: 3GP and MP4. Obviously, too few video formats are supported, it is far from enough to make a general multimedia player. Such formats as RM, rmvb, and Avi are the most common video formats. We can use the open-source framework FFMPEG to program the JNI of the ndk framework to decode the above three videos. FFmpeg is a complete open-source solution integrating recording, conversion, audio/video encoding and decoding functions. FFmpeg is developed based on Linux, but can be compiled and used in most operating systems. FFmpeg supports more than 40 types of code, including MPEG, DivX, MPEG4, AC3, DV, and FLV, and more than 90 types of decoding such as Avi, MPEG, Ogg, matroska, and ASF. FFmpeg is used for Open Source players such as tcpmp, VLC, and mplayer.

Let's start our learning:

Step 1: Download The FFMPEG source code and use the andorid ndk framework to compile FFMPEG as the FFMPEG. So class library. For the source code, see http://www.ffmpeg.org/download.html. there are several download methods such as gitand svn. It is recommended that you use git for download. After git (GIT: // git.videolan.org/ffmpeg.git) is compiled, A libffmpeg is generated. so file the dynamic link library file is the FFMPEG framework we will use later. In this so file, the JNI method can be called by the Java layer, the functions used in these JNI methods are called libffmpeg. so

 

Step 2: Use the ndk framework provided by andorid to compile the c file for decoding as follows. A standard ndk example is used to test the hello-JNI project in the ndk samples folder. Enter the JNI directory of the project and copy the FFMPEG source code to the directory. The reason for this is that you need to call the ffmpeg method in the so file to be compiled, naturally, you need to reference the H file in FFMPEG, and then upload libffmpeg. copy the so file to the platforms/Android-5/arch-arm/usr/lib directory under the ndk directory because it is required for system compilation. Then edit the Android. mk and hello-jni.c files

Android. mk

# Copyright (c) 2009 the android open sourceproject

# Licensed under the Apache license, version2.0 (the "License ");

# You may not use this file before t incompliance with the license.

# You may obtain a copy of the license

# Http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law oragreed to in writing, software

# Distributed under the license isdistributed on an "as is" basis,

# Without warranties or conditions of anykind, either express or implied.

# See the license for the specific extends agegoverning permissions and

# Limitations under the license.

#

Local_path: = $ (call my-DIR)

Include $ (clear_vars)

Path_to_ffmpeg_source: = $ (local_path)/FFMPEG

Local_c_shortdes + = $ (path_to_ffmpeg_source)

Local_ldlibs: =-lffmpeg

Local_module: = hello-JNI

Local_src_files: = hello-jni.c

Include $ (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

Hello-jni.c

 

# Include <FFMPEG/libavcodec/avcodec. h>

This line uses the avcodec_version () function.

After modifying these two files, you can compile them ~~ After compiling with the ndk-build command, there will be a libhello-jni.so file under the libs/armeabi directory of the project! (Two lines of tears ~ After the compilation is completed, you can perform the test. Remember to copy libffmpeg. So to the armeabi directory and write it in the Java code.

Static {

System. loadlibrary ("FFMPEG ");

System. loadlibrary ("hello-JNI ");

}

Hellojni. Java

Now, the program is installed on the mobile phone, and "3426306" is printed. Google searches for "FFMPEG 3426306" to find out that it is actually FFMPEG, proving that libffmpeg is successfully called. so library method. This example is just a test demo of the FFMPEG framework. To expand your decoder, you must view the development documentation with FFMPEG.

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.