Simplest FFmpeg-based mobile sample attachment: SDL Android HelloWorld

Source: Internet
Author: User
Tags bmp image

=====================================================

The simplest example of a ffmpeg-based mobile Sample series article List:

The simplest mobile-based example of FFmpeg: Android HelloWorld

The simplest ffmpeg-based mobile sample: Android Video Decoder

Simplest FFmpeg-based mobile sample: Android Video Decoder-Single library version

Simplest FFmpeg-based mobile sample: Android push-to-stream

The simplest ffmpeg-based mobile sample: Android video transcoding

Simplest FFmpeg-based mobile sample attachment: Android comes with player

Simplest FFmpeg-based mobile sample attachment: SDL Android HelloWorld

The simplest ffmpeg-based mobile sample: IOS HelloWorld

The simplest ffmpeg-based mobile sample: IOS Video Decoder

Simplest FFmpeg-based mobile sample: IOS push-to-stream

The simplest ffmpeg-based mobile sample: IOS video transcoding

Simplest FFmpeg-based mobile sample attachment: iOS comes with player

Simplest FFmpeg-based mobile sample: Windows Phone HelloWorld

=====================================================


This document documents an example of SDL under an Android platform.

The sample reads and displays a BMP image. This sample gives you an idea of how SDL can be used under the Android platform. The SDL version number used in this article is 2.0.



Android Program SDL2 Class Library usage instructions

Simply record how the Android program uses the SDL2 class library. This section of the information can refer to the SDL2 source folder in the Readme-android.txt file.

The steps used by SDL2 can be divided into the following steps:


(1) Configuration Androidproject a) New Androidproject

You can use the Android-projectproject in the SDL2 source folder directly, and you can create a new project yourself. If you create a new project yourself, you need to copy the Sdlactivity.java file under the SRC folder in Android-projectproject. The sdlactivity definition in this file is much longer. It hasn't been studied at the moment.

b) Copy SDL2 source code
Copy the following contents of the SDL2 source folder to the Jni folder of Androidproject:
src folder
Include folder
Android.mk
(2) Compiling C language code a) Writing C language code

Create a new C language file under Androidproject's Jni folder and write code that calls SDL2. It is important to note that the main function name of the C language code is the same as the command-line program. is still "main (int argc, char *argv[])".

b). Change the Android.mk file

Append a piece of code after the android.mk file to compile a libsdl2main.so library. The library is able to invoke its own C language program. You need to be careful here. The name "Libsdl2main" can be arbitrarily started. However, it should correspond to the library name in the LoadLibrary () function in sdlactivity (the default name should be libmain.so). The code content is seen in the following example.

#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)

PS: The above code is changed from the Android.mk file under the Jni\src folder android-projectproject the SDL2 source folder.



c). Writing a application.mk file (optional)
The App_abi in application.mk sets the instruction set supported by the compiled library file. By default, "Armeabi" is used, where default values are used.


d) Execution of Ndk-build
After writing the C language code and ANDROID.MK, you can execute the ndk-build command to compile.

After the Ndk-build command executes successfully, 2 library files are generated in the "Libs/armeabi" folder under the root folder:

Libsdl2.so
libsdl2main.so
You can then test the entire androidproject on your Android phone or virtual machine.

Source

The folder structure of the project is seen. Java source code is located in the SRC folder. The C code is located in the Jni folder.


The Java side code of the Android program is located in Src\org\libsdl\app\sdlactivity.java.

The activity is taken from the Android-projectproject in the SDL2 source folder. is no longer recorded here.

The SRC and include folders in the Jni folder are each The SRC and include folders in the SDL2 source folder.

C Language Side source code is located in Jni/simplest_showbmp.c. For example, see below. The source reads a test.bmp file from the memory card and displays it.

/** * porting SDL to Android platform Helloworld program * simplest SDL Android Helloworld * Lei Huawei Lei Xiaohua * [email protected] * Communication University/Digital TV Technology * Communication University of China/digital TV technology * http://blog.csdn.net/leixiaohua1020 * * * This program is the simplest program to migrate SDL to Android platform 。 It can read and display a BMP image.

* * This software are 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;st Ruct sdl_texture *texture = NULL; Char *filepath = "/storage/emulated/0/test.bmp"; if (Sdl_init (Sdl_init_video | Sdl_init_audio | Sdl_init_timer) = =-1) {LOGE ("Sdl_init failed%s", Sdl_geterror ()); } window = Sdl_createwindow ("SDL helloworld!", +, 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); Sdl_destroyrenderer (render); Sdl_destroywindow (window); Quit SDL sdl_quit (); return 0;}


The Android.mk file is located in Jni/android.mk, as seen in the following.
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)

Execution results

The results of the app's execution on the phone, for example, are seen. Can see the app read the Test.bmp file and display it.

Note that you need to copy the BMP file to the corresponding folder in the memory card. The program reads the "test.bmp" file under the root folder by default.




Download
simplest ffmpeg Mobile

Project Home

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

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

sourceforge:https://sourceforge.net/projects/simplestffmpegmobile/


csdnproject:http://download.csdn.net/detail/leixiaohua1020/8924391


This solution includes various examples of using FFMPEG to process multimedia on the mobile side:
[Android]
Simplest_android_player: Android interface-based video player
Simplest_ffmpeg_android_helloworld: FFmpeg-based HelloWorld program under Android platform
Simplest_ffmpeg_android_decoder: The simplest ffmpeg-based video decoder on the Android platform
Simplest_ffmpeg_android_decoder_onelib: The simplest ffmpeg-based video decoder on the Android Platform-Library edition
Simplest_ffmpeg_android_streamer: The simplest ffmpeg-based push-to-flow device under the Android platform
Simplest_ffmpeg_android_transcoder: FFmpeg command-line tool ported under Android platform
Simplest_sdl_android_helloworld: The simplest program for porting SDL to the Android platform
[IOS]
Simplest_ios_player: Video player based on iOS interface
HelloWorld program based on FFmpeg under the Simplest_ffmpeg_ios_helloworld:ios platform
The simplest ffmpeg-based video decoder under the Simplest_ffmpeg_ios_decoder:ios platform
The simplest ffmpeg based on the Simplest_ffmpeg_ios_streamer:ios platform
FFMPEG.C command-line tool ported under Simplest_ffmpeg_ios_transcoder:ios Platform
Simplest_sdl_ios_helloworld: The simplest program to migrate SDL to the iOS platform





Simplest FFmpeg-based mobile sample attachment: SDL Android HelloWorld

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.