B4A Library FFmpeg_b4a - a FFmpeg library for b4a (decoding/streaming)

FFmpeg_b4a

EDIT: As of August 2019, this library is not compliant with Google Play store's latest requirements which require native 64bits libs. It is still useable for apps not being distributed on Google Play Store though.

Personally I would probably use the ExoPlayer (search the forum) these days unless you have codec-issues. Alternatively, you can use my Vitamio5 library/wrapper which is compliant with Google Play store's latest requirements.


FFmpeg_b4a
wraps the IJKPlayer library. Before FFmpeg_b4a, the only FFmpeg library available for B4A was Vitamio (for which I wrote a wrapper library back in 2012 - see here). My library for Vitamio was later enhanced by @warwound to support more recent versions of Vitamio - see here.

What is so special with FFmpeg and these libraries?
-Well, these libraries work like Android's default MediaPlayer and VideoView (see b4a's Audio-library) except that they include much more powerful features. They include a collection of media demuxers, decoders, filters - with FFmpeg you can decode many formats which are not supported natively by Android.

Why this new FFmpeg_b4a wrapper when there is already Vitamio?
- Good question! I wrote this library mainly due to licensing costs. As long as you develop personal and free apps (and with no ads) with Vitamio integrated, you can use Vitamio for free if I have understood things correctly. However, if you publish a pay app, an app with ads or develop an app for a third party where Vitamio is integrated, then you need a license which of course is fair enough. However, when I contacted Vitamio asking for license costs, I was informed the license costs were in thousands USD per app and per year! Well, this may be OK for larger companies but for a hobby programmer like myself (and probably others here on the forum), it is far too expensive. With the FFmpeg_b4a wrapper I believe the license costs are not any longer necessary. Please refer to the "read-me" in the link I cited above for IJKPlayer where the author of IJKPlayer explains licensing issues. I think the important thing here is that the author wrote the C++ code and the JAVA wrapper code himself and that his work may be used also in commercial projects. Please note that I am not a lawyer so I cannot be certain about this so don't blame me if you run into any licensing problems. However, personally I feel more confident to include this library in commercial projects compared to Vitamio.

Any disadvantages with FFMpeg_b4a compared to Vitamio?
-well, Vitamio is very mature and exposes more methods and attributes than FFmpeg_b4a. However, the only things that I personally miss in FFmpeg_b4a are support for subtitles and multiple audio tracks. Some other things missing in FFMmeg_b4a are: possibility to select video-quality (for now I believe all streams are "highest quality" only), no support for MIPS, you cannot set buffer-size and some other minor things. However, most methods and attributes available in Vitamio are available also in FFmpeg_b4a. The implementation of the methods are similar and use mostly the same syntax so replacing Vitamio should be rather easy and straight-forward. Hopefully the author of IJKPlayer will continue improving the library and add missing features.

How to use FFmpeg_b4a?

-Requirements:
a) You need B4A v3.20 or later to compile your app.
b) Min SDK version is API level 9 (Android 2.3–2.3.2 Gingerbread)

-Instructions:
1)In your B4A-project (refer to the included demo in the attached zip-file), under Project attributes, add 2 lines as follows:
B4X:
#AdditionalRes: C:\testingb4a\testffmpeg\ijkmediaplayer\res, tv.danmaku.ijk.media.player
#AdditionalRes: C:\testingb4a\testffmpeg\ijkmediawidget\res, tv.danmaku.ijk.media.widget

IMPORTANT - Replace "C:\testingb4a\testffmpeg\ijkmediaplayer\res" and "C:\testingb4a\testffmpeg\ijkmediawidget\res" with the path to your folder where you saved the supplied res-folders on your PC.
The res-folders are included in the attached zip-file. Please note that the res-folder for ijkmediaplayer is empty. I am unsure if B4A still needs the path when compiling so I included it anyway.

2) Copy the libraries (ijkmediaplayer.jar and ijkmediawidget.jar) included in the attached zip-file to your B4A extra-library folder.

3) The wrapper with the necessary FFmpeg-library (support for armeabi, armeabi-v7a and x86) is available here:
- FFmpeg_B4A - first version
- FFmpeg_B4A_v2 - added support for rtsp and some extra codecs
- FFmpeg_B4A_v3 - added support for some speech codecs suitable for IP-cams (https://www.dropbox.com/s/j5fqvgkl4be4dtk/FFMpeg_B4A_v3.zip?dl=0)

Extract and copy the library (jar-file and xml-file) into your B4A extra-library folder.

4) In B4A (in the the libs-tab), remember to tick the FFmpeg_b4a library.

Notes:
-armeabi, armeabi-v7a and x86 architecture are supported while ARMv5, ARMv6, MIPS are not.
-If the author of the IJKPlayer adds new features and I think it would be a worthwhile upgrade, I will try to include them and release an updated version of the wrapper.

Important final notes:
-Compared to the original FFmpeg build by bbcallen, I built and recompiled the basic FFmpeg-configuration by adding some codecs which I needed. I built the FFmpeg-library according to my needs but I think the FFmpeg_b4a wrapper should now work with most containers and video/audio decoders. This means that the FFmpeg-library is also rather light-weight compared to others.
-If you have problems with some streams or with playback of some video/audio-files, you can check the unfiltered logs in B4A and look for a line similar to the following: "No codec could be found with id XXX".
If you see this, then it is likely you need a codec which is not included the FFmpeg-library. Further down in the unfiltered log, you should see an indication which codec is missing. You can then add the missing containers, demuxers, muxers and codec by building and recompiling the FFmpeg-libraries yourself and then replace the existing FFmpeg-libraries (so-files) in the FFmpeg_B4A wrapper with the ones you generated (you can use 7Zip for that). In this way, you are independent as long as there are no major changes in the wrapper itself which could break the code.
-The wrapping of the library itself was not tricky. The difficult and time-consuming part was actually learning how to set up everything on a Linux-box, configure everything (dependencies, system environments etc.), get some basic understanding of FFmpeg in order to create and/or modify the FFmpeg-libraries, trouble-shooting errors and make sure that everything worked. I spent quite some time on this to get a better understanding. Most projects which can be found on the Internet are not supplying the FFmpeg-libraries while I actually decided to furnish a basic working set.
-If you need help with adding missing codecs, then I might be able to help you but you need to contact me by PM for further discussion.

Credits/Thanks:
-to the author of IJKPlayer: Zhang Rui (bbcallen)
-to @warwound (Martin) for permission to use (and modify) wrapper code for MediaController and OutlineTextView. The wrapper code for VideoView is based on code by myself and Martin.

PS: FFmpeg is actually a solution to record, convert and stream audio and video. It is used also for video and audio creation and manipulation. You can for instance download a YouTube-video and extract the audio-file. The version posted cannot do this since it only handles decoding/streaming. However, if I find some time later on, I will try to wrap a FFmpeg-library which will permit you to do other things and not only streaming(decoding).

Good luck!
 

Attachments

  • FFMpeg_b4a.zip
    105.9 KB · Views: 2,016
Last edited:

wimpie3

Well-Known Member
Licensed User
Longtime User
I've attached the code + a png explaining the problem.
 

Attachments

  • notworking.zip
    263.1 KB · Views: 278
  • notworking.png
    notworking.png
    289 KB · Views: 367

aignatd

Member
Licensed User
Longtime User
Dear All,

can I get the ffmpeg wrapper source code ?
I will use that source code to learn how to create wrapper for basic4android.

Thank you
 

Victor jung

Member
Licensed User
Longtime User
Hello, first off all thanks for this lib, which seems to do what I need.
I tried a lot of different streams, using different video encoder and wrapper generated by ffmpeg/ffserver on a linux computer, I can read those streams WITH vlc, but never with the example code, Actually, the only video stream that works, is the iphone clock stream given in the example.
Any ideas why?
Anytime I try to open another stream, the app crashes at opening.
Thanks a lot for your help.
Nice evening.
 

moster67

Expert
Licensed User
Longtime User
Hello, first off all thanks for this lib, which seems to do what I need.
I tried a lot of different streams, using different video encoder and wrapper generated by ffmpeg/ffserver on a linux computer, I can read those streams WITH vlc, but never with the example code, Actually, the only video stream that works, is the iphone clock stream given in the example.
Any ideas why?
Anytime I try to open another stream, the app crashes at opening.
Thanks a lot for your help.
Nice evening.

What transport-protocol are you using? Http?
Can you post some stream-urls which are not working? Then I can check this weekend. It has been ages I looked into this library due to the rather modest interest.
 

Victor jung

Member
Licensed User
Longtime User
Sadly I have only local ip streaming url, so it wont work outside my network for you to try. I tried with both rtp and http.
 

Victor jung

Member
Licensed User
Longtime User
What transport-protocol are you using? Http?
Can you post some stream-urls which are not working? Then I can check this weekend. It has been ages I looked into this library due to the rather modest interest.
Have you ever tried to display a stream created with ffmpeg-ffserver in this app? If yes, did you find any association format/codec which worked ?
Also do you know if FFMpegVideoView uses ffplay?
Thanks a lot!
 
Last edited:

Victor jung

Member
Licensed User
Longtime User
Hi again, on a post of 2nd page you gave the list of supported features in the module-lite.sh, it seems that rtp is disabled, I would like to give a few tries, by enabling features. What do I have do to, if modifying this file to rebuild the library and add it to b4A?
Thanks for the help.
 

walterf25

Expert
Licensed User
Longtime User
Hi Moster67, first of all thank you for this awesome library, i have been trying to wrap the ffmpeg-android library found here https://github.com/guardianproject/android-ffmpeg-java, i had not done a search in the forums, to my surprise i found your library. However it does not accomplish what i want to do.

Basically i want to merge a video file with an audio file, i know that ffmpeg can do this. Is there a way to add this methods to your library, or is this totally different than the link i've posted.

I have managed to create the wrapper and everything runs fine, but for some reason the app does not merge the video and audio files, i believe this is due to the fact that the library has to be built either with Gradle or Maven, and then the produced library files have to be placed in the RAW folder in the project file, since i have no idea how to use Gradle or Maven i'm stuck. I've reading a ton of tutorials on line i've found but they all say different things on how to build the binary files. I've been at this for almost 2 weeks now without any positive results, I was hoping you had more experience on this since you were able to wrap this library.

Please let me know if adding the rest of the functionalities would be possible?

Thanks,
Walter
 

moster67

Expert
Licensed User
Longtime User
@walterf25
sorry for replying so late but I only noted your post now and I have also been away on holiday.

Unfortunately my library won't help you. My library only decodes and I selected IJKPlayer on purpose since I was only interested in decoding. So, neither my wrapper library nor the original IJKPlayer won't be any good for you.

I remember looking at the library you are linking to since I also wanted a library which permitted encoding and manipulation of video/audio files but I never found the time necessary to look into it further. Maybe in the future...

If I recall correctly, I also had a look at this project on Github:
https://github.com/hiteshsondhi88/ffmpeg-android-java
It includes so-files and some good documentation. It might be an alternative project to wrap?

In addition, I think there was another forum-user here who managed to wrap the library you are trying. I think he posted about it in the thread about the utility Erel wrote for compiling b4a-libraries (in alternative to using Eclipse) although I am not sure. Maybe he can share his knowledge with you?

I am sorry I was unable to help but I hope you will finally manage to get your wrapper working.
 

moster67

Expert
Licensed User
Longtime User
Have you ever tried to display a stream created with ffmpeg-ffserver in this app? If yes, did you find any association format/codec which worked ?
Also do you know if FFMpegVideoView uses ffplay?

Sorry but I don't know what ffmpeg-ffserver is and what format/codecs it creates. I am not 100% sure that IJKPLayer uses ffplay but I believe it does.

Hi again, on a post of 2nd page you gave the list of supported features in the module-lite.sh, it seems that rtp is disabled, I would like to give a few tries, by enabling features. What do I have do to, if modifying this file to rebuild the library and add it to b4A?

To add your own codecs etc, you need to modify the ffmpeg configuration and create/compile new so-files and replace the original ones with your new ones as I mentioned in my first post in this thread. You can find instructions on the original project-page on Github (see link in first post). It took me some time to learn this but it is well worth the effort if you are interested in supporting more formats/codecs.
 

Jerez

Active Member
Licensed User
Longtime User
Hi moster67

have tried few with this lib but no luck so far. I will try to compile new so-files.
thank you.

Regards,
Gabi.

Anyone can confirm if this library can play rtsp videos?
 

moster67

Expert
Licensed User
Longtime User
Check unfiltered log and read first post in this thread how to track down any missing codecs/containers.
The library can cover most scenarios but you may need to do some extra work if necessary.
 

lomosami

Member
Licensed User
Longtime User
I checked. FFMpegVideoView1_Error function return error -10000. I checked the c source of the lib: it say MEDIA_ERROR_IJK_PLAYER = -10000. I don't know what is this code. Probably in the lib there isn't enable the rtsp protocol?
It is better to create another .so lib as described in the first post and try again enabling rtsp video?
Thanks
 

moster67

Expert
Licensed User
Longtime User
Send me a link of the stream (PM if you prefer) and perhaps this weekend I can have a look....
 

lomosami

Member
Licensed User
Longtime User
It is a local link from ipcam. Tomorrow I will create a host link with ddns service and give to you the address. How I can write to you in PM?
Thanks for your time
 
Top