Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Can build a ffmpeg bin executable file for android? #30

Closed
suncj518 opened this issue Oct 1, 2018 · 39 comments
Closed

Can build a ffmpeg bin executable file for android? #30

suncj518 opened this issue Oct 1, 2018 · 39 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@suncj518
Copy link

suncj518 commented Oct 1, 2018

Is it pissible to build a ffmpeg bin executable file for android?

@tanersener
Copy link
Owner

tanersener commented Oct 1, 2018

Current versions do not produce ffmpeg binary but it is possible to generate it by modifying a few lines in build/android-ffmpeg.sh or build/ios-ffmpeg.sh.

@tanersener tanersener self-assigned this Oct 1, 2018
@tanersener tanersener added good-question enhancement New feature or request labels Oct 1, 2018
@tanersener
Copy link
Owner

If you make the following three changes in build/android-ffmpeg.sh script, top level android.sh will generate ffmpeg finary under prebuilt/android-<arch>/ffmpeg/bin path.

1. Delete --disable-programs line
2. Change --disable-static line to --enable-static
3. Change --enable-shared line to --disable-shared

@tanersener
Copy link
Owner

@suncj518 do you still need help about this?

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

Thanks very much. I did not config a environment to build ffmpeg executable bin file. Would you please help generate ffmpeg executable file and upload it for download if possible?
I prefer the version of mobile-ffmpeg-full-gpl-2.1.1 on arm-v7a.

If is it not easy for you to upload ffmpeg bin executable file, just ignore my comment, thanks again.

@tanersener
Copy link
Owner

tanersener commented Oct 5, 2018

Hi, I just built ffmpeg binaries for all five android architectures from mobile-ffmpeg-full-gpl-2.1.1 release and uploaded here.

Please let me know if they don't work for you.

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

Thanks a lot.
I tried the link, seems that it can not connect, could yo please try the link ?

@tanersener
Copy link
Owner

It's a Dropbox link actually. It works for me. Is there a restriction to Dropbox, in your area?

link

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

oh, yes, you are right, I found I can not access dropbox in my side. Could you please upload it in the same place as the .so files?

@tanersener
Copy link
Owner

Can you access this link ffmpeg binaries for arm-v7a & arm-v7a-neon?

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

Yes, I can download now via this new link. Thanks.
I tried to run ffmpeg executable file , failed. However I can run previous old version ffmpeg file I have.
I am not sure whether this ffmpeg I downloaded just can run in Android or not.
Can the ffmpeg file run in your side using steps below?

adb push ffmpeg /sdcard
adb shell
run-as a_debuggable_app
cp /sdcard/ffmpeg .
chmod +x ffmpeg
./ffmpeg

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

Supply the error message I found here.

$ ./ffmpeg
"./ffmpeg": error: only position independent executables (PIE) are supported.
Aborted

@tanersener
Copy link
Owner

Supply the error message I found here.

$ ./ffmpeg
"./ffmpeg": error: only position independent executables (PIE) are supported.
Aborted

You are right, it fails with this message. Let me build it with PIE.

@tanersener
Copy link
Owner

@suncj518 Can you try with these?

You need to put both files in the same directory and run export LD_LIBRARY_PATH=. before running.

@suncj518
Copy link
Author

suncj518 commented Oct 5, 2018

The error still existed.
"./ffmpeg": error: only position independent executables (PIE) are supported.
Aborted

Could you please compile the ffmpeg using flags below?

LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE

Thanks a lot!

@suncj518
Copy link
Author

suncj518 commented Oct 6, 2018

@tanersener Sorry, my fault, I did not copy new ffmpeg. after copied new ffmpeg, the error is below.

$ ./ffmpeg
CANNOT LINK EXECUTABLE "./ffmpeg": library "libcpufeatures.so" not found *** uid
:10899 pid:5985 env:_=./ffmpeg ldpath:.
Aborted

After I copied the libcpufeatures.so, it is working now.

$ ./ffmpeg
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.9.x (GCC) 20150123 (prerelease)

Thanks very much for your time to help!!!

@tanersener
Copy link
Owner

Anytime mate 👍

@suncj518
Copy link
Author

suncj518 commented Oct 6, 2018

@tanersener ,thank you, just ask a further question , it is working well in adb shell.
However when I used ffmpeg in android app, still show the error below.

library "libc++_shared.so" not found

May I know whether can build the libcpufeatures.so and libc++_shared.so into one single ffmpeg ?

I tried for many times, put the libcpufeatures.so and libc++_shared.so into libs/armeabi-v7a, ffmpeg in app can not find them yet.

Thanks.

@tanersener
Copy link
Owner

May I know whether can build the libcpufeatures.so and libc++_shared.so into one single ffmpeg ?

Well, they are .so files, they can't be embedded into ffmpeg executable. They have static versions with .a extension, they are the ones to embed into ffmpeg executable.

But the case here is that ffmpeg itself is not the actual library which needs libcpufeatures.so and libc++_shared.so. ffmpeg is linked to other external libraries and they are the actual libraries which depend on libcpufeatures.so and/or libc++_shared.so. I made a few tests in the last 2 hours to see if I can make it work but unfortunately I wasn't successful.

I don't know why you to want to use ffmpeg binary, but I have to remind you that there are compiled mobile-ffmpeg binaries which you can use more easily. They have extra features which ffmpeg executable can't provide. Additionally there exists a working test-app under android/test-app folder which will save a lot of time for you.

If you want to stick with ffmpeg executable, there are other ffmpeg projects like this which provides precompiled ffmpeg. I would recommend using them since they are already doing what you need.

@suncj518
Copy link
Author

suncj518 commented Oct 6, 2018

@tanersener Thanks a lot for your detailed response. The project you recommended is slower than yours when converting mp4 to mp3. Anyway, let me try all these, thanks again.

@tanersener
Copy link
Owner

I'm closing this issue, you can create a new one if you need help.

@danielkucera
Copy link

Hi @tanersener, would it be possible to add it to automatic building of releases? I would also like to use static binary instead of shared libs.

@tanersener
Copy link
Owner

Nope. It's a design decision. There are other projects that provide ffmpeg binary. Please use them if you don't want to use shared libraries on Android.

@tanersener tanersener added the wontfix This will not be worked on label May 27, 2019
@danielkucera
Copy link

I know but they don't provide Android camera support. This is very specific to your project.

@tanersener
Copy link
Owner

tanersener commented May 28, 2019

Can't you try to build it yourself using instructions in this thread?

Besides, why do you want to use ffmpeg binary? mobile-ffmpeg library offers more features as I reminded here.

@danielkucera
Copy link

Ok, I had to install android studio and ndk (few hours of work :( ), compiled binaries and here they are for anyone interested: https://blog.danman.eu/wp-content/uploads/2019/05/ffmpeg-android.tar.gz

I don't want to build a standard app. I want to capture camera and stream from shell.

@sourabhgupta811
Copy link

sourabhgupta811 commented Sep 2, 2019

Hi @tanersener
Thanks for such a straightforward library.
I followed all procedures discussed in this issue discussion and built a binary executable with x264 and x265 codecs. But it is not working in android. Can you please test the binary and tell me what i am doing wrong. Here's the link to arm64 executable. https://www.dropbox.com/s/982ev3k8wf1g7rx/ffmpeg?dl=0

@danielkucera
Copy link

Do you have some error message?

@sourabhgupta811
Copy link

sourabhgupta811 commented Sep 3, 2019

No @danielkucera
I don't get any error. It just does not run the command and the process exits without any output on Android. The binary works when i build it without x264 and x265. But when i enable both these libs, it stops working.

@tanersener
Copy link
Owner

tanersener commented Sep 3, 2019

@sourabhgupta811 I can't test your file, I don't have an arm64 device right now.

If you have enabled x264 and x265 libraries then you need to push x264 and x265 libraries as well, besides ffmpeg.

@sourabhgupta811
Copy link

sourabhgupta811 commented Sep 3, 2019

Hi @tanersener
So, I'll have to push x265.a and x264.a to the same path as ffmpeg? Isn't there any way to include all these files in a single binary?

@tanersener
Copy link
Owner

Sorry, my mistake. You don't need to push x265.a and x264.a. I think it is libc++_shared.so which is causing the trouble. Let me test a few things on my local environment.

@sourabhgupta811
Copy link

sourabhgupta811 commented Sep 3, 2019

Yes, this issue arise particularly when compiling with x265.
Also got this issue-
CANNOT LINK EXECUTABLE "/data/user/0/com.sample.ffmpegl/files/ffmpeg": library "libcpufeatures.so" not found

@tanersener
Copy link
Owner

"libcpufeatures.so" not found

cpufeatures is only used by libvpx. It shouldn't cause a problem for you.

I don't get any error. It just does not run the command and the process exits without any output on Android. The binary works when i build it without x264 and x265. But when i enable both these libs, it stops working.

x265, snappy and tesseract libraries requires a c++ library and scripts are configured to use libc++_shared.so by default. So you need to put it in your directory as well. I tested some modifications to include in ffmpeg binary but they didn't work unfortunately.

@sourabhgupta811
Copy link

Thanks @tanersener for this detailed response.
One more thing, I will be executing this binary after placing it some external folder in android. Do i need to copy this .so file there or it will work even when i keep it as a lib inside the app? Can you tell me the directory pattern of how i should place this lib in Android.

@tanersener
Copy link
Owner

Thanks @tanersener for this detailed response.
One more thing, I will be executing this binary after placing it some external folder in android. Do i need to copy this .so file there or it will work even when i keep it as a lib inside the app? Can you tell me the directory pattern of how i should place this lib in Android.

libc++_shared.so should be under your applications lib folder.

@sourabhgupta811
Copy link

Okay Thanks @tanersener . I'll try it.
I have found this binary that is compiled with x265 but does not need separate .so to be placed into libs. https://www.dropbox.com/s/982ev3k8wf1g7rx/ffmpeg?dl=0.
Please have a look at it.

@tanersener
Copy link
Owner

Please have a look at it.

Why? I don't want to support ffmpeg executables. You have my tips for building it but if it does not work for you I can't do anything else. If that executable with x265 inside is what you are looking then please use it.

@sourabhgupta811
Copy link

Okay. Thanks for all the help.

@mgood7123
Copy link

mgood7123 commented May 15, 2020

May I know whether can build the libcpufeatures.so and libc++_shared.so into one single ffmpeg ?

Well, they are .so files, they can't be embedded into ffmpeg executable. They have static versions with .a extension, they are the ones to embed into ffmpeg executable.

But the case here is that ffmpeg itself is not the actual library which needs libcpufeatures.so and libc++_shared.so. ffmpeg is linked to other external libraries and they are the actual libraries which depend on libcpufeatures.so and/or libc++_shared.so. I made a few tests in the last 2 hours to see if I can make it work but unfortunately I wasn't successful.

I don't know why you to want to use ffmpeg binary, but I have to remind you that there are compiled mobile-ffmpeg binaries which you can use more easily. They have extra features which ffmpeg executable can't provide. Additionally there exists a working test-app under android/test-app folder which will save a lot of time for you.

If you want to stick with ffmpeg executable, there are other ffmpeg projects like this which provides precompiled ffmpeg. I would recommend using them since they are already doing what you need.

i get that as well, tho i also get an undefined __*ndk* symbol when attempting to run

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants