Android/FFMPEG dynamic module, JNI simple wrapper on production device, we can't use "Executable File ".
We need to build "dynamic, so module" for FFMPEG/ffserver.
This post explain how to build so module and simple JNI interface for FFMPEG.
1) Change FFMPEG. c
A) Add JNI part.
//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////
// Kks...
# Include
Int m_argc = 0;
Int m_max_argc = 30;
Char * m_pargv [30];
Int dynamic_ffpmeg_main (INT argc, char ** argv );
Jint jnicall java_com_ccmedia_codec_ffmpeg_mod_1run (jnienv *, jclass, jstring, jstring );
Jint jnicall java_com_ccmedia_codec_ffmpeg_mod_1run (jnienv * ENV, jclass, jstring pj1, jstring pj2 ){
Jint JI;
Jboolean IC;
Char sz_temp [2, 1024];
Char SEPs [] = "";
Char * psztoken, * pszdata;
Int I = 0;
Const char * pszname;
Pszname = (* env)-> getstringutfchars (ENV, pj1, & ic );
Sprintf (sz_temp, "FFMPEG % s", pszname );
If (Ic = jni_true) (* env)-> releasestringutfchars (ENV, pj1, pszname );
// Strcpy (sz_temp, "FFMPEG-I/sdcard/arm_and/bin/TV _dump.mpg http: // localhost: 8090/feed1.ffm ");
Printf ("[debug] % s/n", sz_temp );
Psztoken = strtok (sz_temp, SEPs );
While (psztoken! = NULL ){
M_pargv [m_argc] = (char *) malloc (strlen (psztoken ));
Strcpy (m_pargv [m_argc], psztoken );
M_argc ++;
Psztoken = strtok (null, SEPs );
}
For (I = 0; I <m_argc; I ++ ){
Printf ("argc [% d] = % s/n", I, m_pargv [I]);
}
Dynamic_ffpmeg_main (m_argc, m_pargv );
Ji = 0;
Return JI;
}
B) Change main function
Original --> int main (INT argc, char ** argv)
New --> int dynamic_ffpmeg_main (INT argc, char ** argv)
C) Add "new main function"
Int main (INT argc, char ** argv)
{
Dynamic_ffpmeg_main (argc, argv );
Return 0;
}
2) Build FFMPEG.
-On preivious post, you can find "Configure" option to build FFMPEG.
Http://demo860.blogspot.com/2010/06/ffmpeg-libx264-build-for-android.html
3) Build FFMPEG so module using following command.
I use ndk R4,/export/home/Android/ndk/
/Export/home/Android/ndk/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/ARM-Eabi-gcc/
-Nostdlib-wl,-soname, libffmpeg. So-wl,-shared,-bsymbolic/
Cmdutils. o ffmpeg. O/
-Wl, -- no-whole-archive-wl, -- whole-archive/
/Export/home/Android/android-ndk-r4/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/GCC/ARM-Eabi/4.4.0/libgcc./
/Export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/libc. So/
/Export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/libstdc ++. So/
/Export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/libm. So/
/Export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/libz. So/
/Export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/libdl. So/
-Wl, -- no-undefined-wl,-Z, noexecstack-wl, -rpath-link =/export/home/Android/ndk/build/platforms/Android-8/arch-arm/usr/lib/
./Libavutil./
./Libavcodec./
./Libavfilter./
./Libavformat./
./Libswscale./
./Libavdevice./
-O libffmpeg. So
4) Now you can use using following FFMPEG wrapper.
Public class FFMPEG implements runnable {
Static Boolean m_bret = false;
Static string m_szconfig = "-I/sdcard/file. mpg-vcodec MPEG4 AAA. mpg ";
Public native string unimplementedstringfromjni ();
Static {
Try {
System. Out. println ("[addbcache] module load try FFMPEG:" + system. getproperty ("Java. Library. Path "));
// System. Load ("/sdcard/arm_and/bin/libffmpeg. So ");
System. loadlibrary ("FFMPEG ");
System. Out. println ("[addbcache] module load success ");
}
Catch (exception e ){
System. Out. println ("[addbcache] module load err:" + system. getproperty ("Java. Library. Path "));
}
}
Private Static synchronized final native int mod_run (string name, string sztoken );
Public void set_config (string sz_config ){
M_szconfig = sz_config;
}
Public void run_core (string sz_file, string sz_token ){
Int n_stat;
M_bret = false;
N_stat = mod_run (m_szconfig, sz_token );
M_bret = true;
}
Public void run (){
Run_core ("","");
}
}
5) FFMPEG/ffserver,
-I made both, dynamic module and run it.
-The speed is OK but it's used cpu so much.
Posted by demo860
1 comments:
-
BRYAN:
-
Hello, what does your FFMPEG make file look like?
Thanks!