7

I am trying to create a screen recording app in Android. For this, i am using FFmpeg. I have created the libffmpeg.so file. Now i would like to use the same in Android project for calling it's native function. How can i do that..?

Mycoola
  • 1,135
  • 1
  • 8
  • 29
Neernay
  • 379
  • 1
  • 4
  • 13

2 Answers2

5

This tutorial provides a detail explanation about this topic. How to Build Android Applications Based on FFmpeg by An Example

Shaiful
  • 5,643
  • 5
  • 38
  • 41
  • Thanks, but i have built the the libffmpeg.so from that site only. but it does not says whether to include the only libffmpeg.so file or to include the complete folder in /jni folder. The "ffmpeg" is of 91mb. Do you know anything about that..? – Neernay May 29 '12 at 12:15
  • The ffmpeg.so should be approximately 5mb in size. I built my ffmpeg.so from another site. Don't remember which one. But I used the native code and JNI code from this page. And it worked with my library. – Shaiful May 29 '12 at 12:33
  • mine libffmpeg.so is of 8.2 mb. So should i put this file (libffmpeg.so) alone in /jni folder..? Also load this (libffmpeg.so) alone to call the native functions..? Will that be sufficient..? – Neernay May 29 '12 at 13:25
  • Nop you should put this ffmpeg.so in `libs/armeabi`. Actually this depends on the platform. If you build the so for `armeabi-v7a` then you should put your so file in `libs/armeabi-v7a`. Or you can put each file in both folder. – Shaiful May 29 '12 at 14:16
  • and simply call the System.load("ffmpeg"); to load the library. And invoke the native functions in usual way.. right..? Also if i want to invoke ffmpeg commands i can invoke them using RunTime.exec(); right..? – Neernay May 29 '12 at 14:42
  • It's a library file, I don't think you can invoke the commands using Runtime.exec(). But why don't you try? It's better try and learn from the result. You'll learn from your mistakes. Follow the instruction from above link. They also have a sample project. – Shaiful May 29 '12 at 14:49
  • http://stackoverflow.com/questions/6449225/using-existing-shared-library-so-in-android-application . this link may be relevant – Robert Rowntree May 29 '12 at 16:01
  • @RobertRowntree Thts a grt linked.. cleared my many doubts.. thanks..! – Neernay May 30 '12 at 12:48
  • hey.. my ffmpeg.so is only 26 KB. did i went wrong during compilation? you said it should be worth 5 mb – Chaitanya Chandurkar Aug 28 '12 at 14:26
  • The size can be more or less depending on your configuration. You can choose specific encoder or decoder. But 26KB? there should be something wrong. Did you build static library or shared library. If you build static library & don't link the library your final library can be small. Not sure though. Follow the tutorial exactly. You'll find your answer. – Shaiful Aug 28 '12 at 15:18
  • 1
    hey.. that tutorial shows how to use ffmpeg's native functions in android !! will i able to run ffmpeg commands from android using "Runtime.getRuntime.exec("ffmpeg -codecs")" ?? or do i have to use native functions only to do any multimedia operations?? – Chaitanya Chandurkar Aug 29 '12 at 10:12
  • hey i tried above tutorial and i m getting many errors in ffmpeg-test-jni.c at lines like "AVFormatContext *gFormatCtx;" error is "Unknown type name AVFormatContext". can u help? i build it on api-8 and android-ndk-r8b – Chaitanya Chandurkar Aug 29 '12 at 12:47
  • I think you copy the code from the webpage. Right? That's why you miss the includes. Download the source code from their site. You should be able to build the source code. `http://www.roman10.net/src/ffmpegtest.tar.gz` – Shaiful Aug 29 '12 at 19:17
  • The link given redirects to antom.xyz, where landing page asks to allow notifications then loads malware to open backdoors through firewall – Zimba Jul 24 '21 at 17:12
2

You can find the example How to load another .so file in your android project?

That is the good way to show you how to load *.so file.

1 - Add folder jni/libs/*.so

2 - Use "Right-click mouse" -> Android Tools -> Add native support -> Set name of file *.cpp

3 - Two files : *.cpp and Android.mk appeared.

4 - Use Cygwin to build & compile *.so into the project.

Thanks,

Community
  • 1
  • 1
Huy Tower
  • 7,769
  • 16
  • 61
  • 86