The simplest example of FFmpeg-based mobile terminal attachment: SDL Android HelloWorld, ffmpegsdl

Source: Internet
Author: User
Tags bmp image

The simplest example of FFmpeg-based mobile terminal attachment: SDL Android HelloWorld, ffmpegsdl
This document describes an SDL example on the Android platform. This example reads and displays a BMP image. You can use this example to understand how SDL works on Android. The SDL version used in this article is 2.0.

Android SDL2 class library usage instructions

A simple record of how the Android program uses the SDL2 class library. You can refer to the readme-android.txt file in the sdl2source code directory. The steps for using SDL2 are as follows:


(1) configure the Android Project A) create an Android Project

You can directly use the android-project in the SDL2 source code directory or create a new project on your own. If you create a new project, you need to copy the SDLActivity. java file under the src directory of the android-project. The SDLActivity definition in this file is long and has not been studied yet.

B) Copy SDL2 source code
Copy the following content from the SDL2 source code directory to the jni directory of the Android project:
Src directory
Include directory
Android. mk
(2) compile C language code A) write C language code

Create a C language file in the jni directory of the Android project and write the code that calls SDL2. Note that the main function name in the C language code is the same as that in the command line program. It is still "main (int argc, char * argv [])".

B) modify the Android. mk File

Append a piece of code behind the Android. mk file to compile a library of libSDL2main. so. This library can call its own C language program. Note that the name "libSDL2main" can be set at will, but it must correspond to the library name in the LoadLibrary () function of SDLActivity (the default name should be libmain. so ). The Code is as follows.

#libSDL2main=======================================# Lei Xiaohuainclude $(CLEAR_VARS)LOCAL_MODULE := SDL2mainSDL_PATH := ./LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include# Add your application source files here...LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \$(SDL_PATH)/src/simplest_showbmp.cLOCAL_SHARED_LIBRARIES := SDL2LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -lloginclude $(BUILD_SHARED_LIBRARY)

PS: The above code is modified from the android. mk file under the jni \ src directory of the Android-project in the SDL2 source code directory.

C) Compile the Application. mk file (optional)
APP_ABI in Application. mk sets the instruction sets supported by the library files after compilation. "armeabi" is used by default, and the default value is used here.
D) Run ndk-build
After compiling the C language code and Android. mk, you can run the ndk-build command to compile it. After the ndk-build command is run successfully, two library files are generated in the "libs/armeabi" directory under the root directory:
LibSDL2.so
LibSDL2main. so
Next we can test the entire Android project on the Android mobile phone or virtual machine.

Source code

The directory structure of the project. Java source code is located in the src directory, while C code is located in the jni directory.


The Java code of the Android program is located in src \ org \ libsdl \ app \ SDLActivity. java. This Activity is taken from the android-project in the SDL2 source code directory and is not recorded here.

The src and include folders in the jni directory are the src and include folders in the SDL2 Source Code Directories.

The C language source code is located in jni/simplest_showbmp .c, as shown below. The source code reads and displays a file test.bmp in the storage card.

/*** Transplant SDL to the Android platform's HelloWorld Program * Simplest SDL Android Helloworld ** leixiao Lei Xiaohua * leixiaohua1020@126.com * China Media University/Digital TV technology * Communication University of China/ digital TV Technology * http://blog.csdn.net/leixiaohua1020 ** this program is the simplest program to transplant SDL to the Android platform. It can read and display a BMP image. ** This software is the simplest program transplant SDL2 to Android platform. * It shows a BMP file on the screen. */# ifdef _ ANDROID __# include <jni. h> # include <android/log. h> # define LOGI (...) _ android_log_print (ANDROID_LOG_INFO, "(^_^)", _ VA_ARGS _) # define LOGE (...) _ android_log_print (ANDROID_LOG_ERROR, "(^_^)", _ VA_ARGS _) # else # define LOGE (format ,...) printf ("(>_<)" format "\ n", ##__ VA _ ARGS _) # define LOGI (format ,...) printf ("(^_^)" format "\ n", ##__ VA_ARGS _) # endif # include "SDL. h "# include" SDL_log.h "# include" SDL_main.h "int main (int argc, char * argv []) {struct SDL_Window * window = NULL; struct SDL_Renderer * render = NULL; struct SDL_Surface * bmp = NULL; struct SDL_Texture * texture = NULL; char * filepath = "/storage/emulated/0/test.bmp"; if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDI O | SDL_INIT_TIMER) =-1) {LOGE ("SDL_Init failed % s", SDL_GetError ();} window = SDL_CreateWindow ("SDL HelloWorld! ", 100,100,640,480, SDL_WINDOW_SHOWN); if (window = NULL) {LOGE (" SDL_CreateWindow failed % s ", SDL_GetError ();} render = SDL_CreateRenderer (window,-1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (render = NULL) {LOGE ("SDL_CreateRenderer failed % s", SDL_GetError ();} bmp = SDL_LoadBMP (filepath ); if (bmp = NULL) {LOGE ("SDL_LoadBMP failed: % s", SDL_GetError ();} texture = SDL_CreateTextureFromSurface (render, bmp); SDL_FreeSurface (bmp ); SDL_RenderClear (render); SDL_RenderCopy (render, texture, NULL, NULL); SDL_RenderPresent (render); SDL_Delay (10000); SDL_DestroyTexture (texture); render (render ); SDL_DestroyWindow (window); // Quit SDL SDL_Quit (); return 0 ;}

The Android. mk file is located in jni/Android. mk, as shown below.
LOCAL_PATH := $(call my-dir)############################# SDL shared library############################include $(CLEAR_VARS)LOCAL_MODULE := SDL2LOCAL_C_INCLUDES := $(LOCAL_PATH)/includeLOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)LOCAL_SRC_FILES := \$(subst $(LOCAL_PATH)/,, \$(wildcard $(LOCAL_PATH)/src/*.c) \$(wildcard $(LOCAL_PATH)/src/audio/*.c) \$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \$(LOCAL_PATH)/src/atomic/SDL_atomic.c \$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \$(wildcard $(LOCAL_PATH)/src/core/android/*.c) \$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \$(wildcard $(LOCAL_PATH)/src/dynapi/*.c) \$(wildcard $(LOCAL_PATH)/src/events/*.c) \$(wildcard $(LOCAL_PATH)/src/file/*.c) \$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \$(wildcard $(LOCAL_PATH)/src/power/*.c) \$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \$(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) \$(wildcard $(LOCAL_PATH)/src/render/*.c) \$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \$(wildcard $(LOCAL_PATH)/src/thread/*.c) \$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \$(wildcard $(LOCAL_PATH)/src/timer/*.c) \$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \$(wildcard $(LOCAL_PATH)/src/video/*.c) \$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \    $(wildcard $(LOCAL_PATH)/src/test/*.c))LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPESLOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroidinclude $(BUILD_SHARED_LIBRARY)############################# SDL static library############################LOCAL_MODULE := SDL2_staticLOCAL_MODULE_FILENAME := libSDL2LOCAL_SRC_FILES += $(LOCAL_PATH)/src/main/android/SDL_android_main.cLOCAL_LDLIBS := LOCAL_EXPORT_LDLIBS := -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroidinclude $(BUILD_STATIC_LIBRARY)#libSDL2main=======================================# Lei Xiaohuainclude $(CLEAR_VARS)LOCAL_MODULE := SDL2mainSDL_PATH := ./LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include# Add your application source files here...LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \$(SDL_PATH)/simplest_showbmp.cLOCAL_SHARED_LIBRARIES := SDL2LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -lloginclude $(BUILD_SHARED_LIBRARY)

Running result

The result of the App running on the mobile phone is shown in. You can see that the app reads the test.bmp file and displays it.

Copy the BMP file to the corresponding directory on the memory card. The program will read the test.bmp file under the root directory.



Download
Simplest ffmpeg mobile

Project Homepage

Github: https://github.com/leixiaohua1020/simplest_ffmpeg_mobile

Open source China: https://git.oschina.net/leixiaohua1020/simplest_ffmpeg_mobile


CSDN project: http://download.csdn.net/detail/leixiaohua1020/8924391


This solution contains various examples of using FFmpeg to process multimedia on mobile terminals:
[Android]
Simplest_android_player: Android-Based Video Player
Simplest_ffmpeg_android_helloworld: The FFmpeg-based HelloWorld program in Android
Simplest_ffmpeg_android_decoder: the simplest FFmpeg-based video decoder on Android
Simplest_ffmpeg_android_decoder_onelib: the simplest FFmpeg-Based Video Decoder for Android-single library
Simplest_ffmpeg_android_streamer: the simplest FFmpeg-based streamer on Android
Simplest_ffmpeg_android_transcoder: The FFmpeg command line tool transplanted on the Android platform
Simplest_sdl_android_helloworld: the simplest program to port SDL to Android.
[IOS]
Simplest_ios_player: A Video Player Based on the IOS Interface
Simplest_ffmpeg_ios_helloworld: The FFmpeg-based HelloWorld program in IOS
Simplest_ffmpeg_ios_decoder: the simplest FFmpeg-based video decoder on IOS
Simplest_ffmpeg_ios_streamer: the simplest FFmpeg-based streamer on IOS
Simplest_ffmpeg_ios_transcoder: The ffmpeg. c command line tool transplanted on the IOS platform
Simplest_sdl_ios_helloworld: the simplest program to port SDL to IOS.





Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.