bambuser ffmpeg on Android - android

Basically, I need to combine(append) audio files in android. This is required to perform pause / resume function for a voice recorder.
I have successfully compiled bambuser ffmpeg on Android with the following.
1. Oracle Virtual Box
2. Ubuntu 12.04 x86
3. android-ndk r8
4. Archive for client versions 1.3.7 to 1.6.6
(from bambuser http://bambuser.com/opensource)
I have changed the package name in build.sh to suit my package name.
After building, I have got the ffmpeg from build folder with the following structure
ffmpeg
-armeabi
-armeabi-v7a
I have copied the ffmpeg folder into my project/jni folder in my windows machine.
Created a native.c file to include the necessary libs.
Made ndk-build. Got the .so file.
When I try to do this in android activity,
try {
System.loadLibrary("FFmpegTest");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
File dir = new File("/mnt/sdcard");
Process p=Runtime.getRuntime().exec("ffmpeg -i test.wav test1.wav",null,dir);
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
I get the following error.
05-31 11:57:53.532: D/dalvikvm(278): Trying to load lib /data/data/com.example.ffmpegtest/lib/libFFmpegTest.so 0x43e37a88
05-31 11:57:53.532: D/dalvikvm(278): Added shared lib /data/data/com.example.ffmpegtest/lib/libFFmpegTest.so 0x43e37a88
05-31 11:57:53.532: D/dalvikvm(278): No JNI_OnLoad found in /data/data/com.example.ffmpegtest/lib/libFFmpegTest.so 0x43e37a88, skipping init
05-31 11:57:53.562: W/System.err(278): java.io.IOException: Error running exec(). Command: [ffmpeg, -i, test.wav test1.wav] Working Directory: /mnt/sdcard Environment: null
Can anyone guide me the procedure ?

I think you do no need any *.so.
You , probably, should compile ffmpeg binary for Android.
Then put the binary into you res/raw folder.
Then, upon first execution, your program should copy it from the res/raw to the app's dir and set chmod +x on it.
Then you can call ffmpeg binary with System.exec or the like.
It worked for me fine. I have used the code here https://github.com/halfninja/android-ffmpeg-x264 as an example.

Related

Shell script in Gradle build: java.io.IOException

I have the following lines in my build.gradle file of my Android project:
"./prebuild.sh".execute()
But during the build I get this error:
java.io.IOException: Cannot run program "./prebuild.sh": error=2, No such file or directory
The prebuild.sh script is in the root directory of the app and executable.
What's weird is that this exact build works for everyone on the team, just not on my machine (M1). I also remember that this used to work months ago.
This happens on a fresh clone of the repository and a fresh install of Android Studio.
I think I've narrowed it down to a problem with the working directory. If I try to print it like this:
println new File(".").absolutePath
I get the following:
/Users/ale/.gradle/daemon/6.5/.
Which is obviously not my project directory.
Any hints on what I could do to fix it?
Assuming a functional shell prompt; pass the absolute path instead of . current working directory:
if(rootProject.file('prebuild.sh').exists()) {
commandLine 'sh', rootProject.file('prebuild.sh').absolutePath
} else {
println "missing: prebuild.sh"
}
Or how you start it as process, one can also pass the current working directory as second argument:
def proc = "./prebuild.sh".execute([], rootProject.absolutePath)
proc.waitForProcessOutput(System.out, System.err)
I'd run cd first, then pwd should return the expected value:
def proc = "cd ${rootProject.absolutePath} && pwd".execute()
...
Check if the file has DOS line endings (\r\n). This can lead to a confusing "no such file or directory", because it searches for a file called /bin/sh\r (ending with an actual carriage return), which does not exist.

File is not recognized after generating the ".APK" file from Go to Android using gomobile tool

I am working on a project in which i need to generate an APK file form a Golang code base using gomobile tool.
the plan is to be able to run it on android tablet.
When I install the apk file on the tablet, through the Android Studio I get the following error.
E/Go: panic: open C:/Users/ash/OneDrive/Desktop/go-workSpace/src/Myproject/config.json: no such file or directory
However, after clicking on the given path in the error message, the Android Studio opens the the file it is complaining to find (config.json)
Here is the source code I have in Go
exDir := "C:/Users/ash/OneDrive/Desktop/go-workSpace/src/Myproject/"
configFile, err := ioutil.ReadFile(filepath.Join(filepath.Dir(exDir), "config.json")) // Look for the config file in the same directory as the executable
Check(err)
func Check(err error) {
if err != nil {
fmt.Println("Received generic error, panicking")
fmt.Println(err)
panic(err)
}
}
Any suggestion how to fix the file path?
After reviewing this thread.
Here is the official go support page.
So, I think I need to
move all the files into a directory called assets.
The assets directory is embedding to the ".APK" can be accessed through Android code base.
import "golang.org/x/mobile/asset"
jsonFile, errOpen := asset.Open(config.json)
if errOpen != nil {
fmt.Println(errOpen)
}
defer jsonFile.Close()
buf, errRead := ioutil.ReadAll(jsonFile)
if errRead != nil {
fmt.Println(errRead)
}

Cross compiling c program with openssl for Android

I am facing the following issue when trying to compile a c program using openssl for android x-86. I set up the environment variables as follows using the following script:
setenv-android.sh
After running the script I have the following environment.
./setenv-android_x86.sh
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
Error: FIPS_SIG does not specify incore module. Please edit this script.
ANDROID_NDK_ROOT: /opt/android-ndk-r9d-x86
ANDROID_ARCH: arch-x86
ANDROID_EABI: x86-4.6
ANDROID_API: android-18
ANDROID_SYSROOT: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86
ANDROID_TOOLCHAIN: /opt/android-ndk-r9d-x86/toolchains/x86-4.6/prebuilt/darwin-x86_64/bin
FIPS_SIG:
CROSS_COMPILE: i686-linux-android-
ANDROID_DEV: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86/usr
However when trying to compile with the following command I get the following error:
pwd
/opt/android-ndk-r9d-x86/bin
./i686-linux-android-gcc Test.c -o test -lcrypto
fatal error: openssl/conf.h: No such file or directory
When I locate for the openssl/conf.h I see the file is available in many places:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/openssl/conf.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/openssl/conf.h
/data/local/arm/ssl/include/openssl/conf.h
/data/local/ssl/include/openssl/conf.h
/openssl/include/openssl/conf.h
/openssl-1.0.1e/include/openssl/conf.h
/openssl-1.0.1g/include/openssl/conf.h
/opt/local/include/openssl/conf.h
/usr/include/openssl/conf.h
/usr/local/include/openssl/conf.h
/usr/local/ssl/android-14/include/openssl/conf.h
/usr/local/ssl/android-18/include/openssl/conf.h
/usr/local/ssl/android-18-x86/include/openssl/conf.h
/usr/local/ssl/include/openssl/conf.h
I think the proper path is this:
/usr/local/ssl/android-18-x86/include/openssl/conf.h
I tried with the -L option but with no luck.
-L/usr/local/ssl/android-18-x86/include/
Can anybody please explain how to setup the path properly to solve this issue. (finally there is no issue with the C code as it compiles properly with gcc)
You are compiling your code using the Android NDK, which creates a "virtual" compiling environment by placing everything you need to compile for android into the ${ANDROID_SYSROOT} directory.
Those directories you listed are outside that sysroot, and therefore are not available to the build system, hence the errors. You must install OpenSSL for Android and putting the resulting headers and binaries there. You might follow this guide to assist you in that.

Using FFMPEG via command line in android

I want to use FFMPEG via COMMAND LINE in my android application.For this purpose:
I have cross-compiled the ffmpeg lib and got the libffmpeg.so
I have stored libffmpeg.so and the ffmpeg exectable in files directory of the my project.
This is the code i am using:
public class FFMPEGActivity extends Activity {
Process p;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] cmd =new String[4];
cmd[0]="/data/data/com.example.ffmpegnew/files/libffmpeg";
cmd[1]="-i";
cmd[2]="mnt/sdcard/music/baba.mp4";
cmd[3]="mnt/sdcard/music/outfile.mp4";
p = Runtime.getRuntime().exec(cmd,null, new File("/data/data/com.example.ffmpegnew/files"));
}
catch(Exception e)
{
System.out.println("exception"+e);
}
}
}
This is the exception i am getting:
09-17 13:47:01.679: I/System.out(3752): exceptionjava.io.IOException: Error running exec(). Command: [/data/data/com.example.ffmpegnew/files/libffmpeg.so, -i, mnt/sdcard/music/baba.mp4, mnt/sdcard/music/outfile.mp4] Working Directory: /data/data/com.example.ffmpegnew/files Environment: null
Please tell me how to solve this problem.Thanks in advance.
I think this won't work, unless you somehow manage to compile ffmpeg executable, place it somewhere in the file system , then access it through your native layer. Normally, though, they use libffmpeg API in android such as in Dolphin Player
Your code seems to try to run the library, not the ffmpeg executable. Note that even after fixing your cmd you will need extra tricks to load the libffmpeg.so, because Android loader does not load shared libs from ./
I would suggest to build a statically linked ffmpeg executable to save hassle.
Place ffmpeg and all the files it accesses on the internal card (obtain through context.getDir("", 0).
After you do this, you will be able to run ffmpeg through exec().
Some models, however, will refuse running this too.

Android NDK - Library not found CANNOT LINK EXECUTABLE - how to set LD_LIBRARY_PATH?

I have an Android activity where I'm executing NDK compiled code (command line program) with:
Runtime.getRuntime().exec(myCommand);
and load the needed shared libraries with:
static {
System.loadLibrary(myLib);
}
but when running my project and printing the output from error stream I get the following error:
link_image[1963]: 7520 could not load needed library 'libmyLib.so' for './myCommand'
(load_library[1105]: Library 'libmyLib.so' not found)CANNOT LINK EXECUTABLE
I assure libmyLib.so does exist in my project under libs/armeabi/ directory and it's copied to my Android device under /data/data/myProject.path.package/lib/ directory. Owner and group of both executable and library are system:system and permissions are ok as well.
When executing the command from adb shell in the beginning I get the same error but then I can set LD_LIBRARY_PATH and it runs ok:
./adb shell
export LD_LIBRARY_PATH=/data/data/myProject.path.package/lib:$LD_LIBRARY_PATH
/data/data/myProject.path.package/myCommand
So the question is, how to do that from java Android project?
Note: I'm using Linux, Eclipse + Sequoyah, NDK-r5b, Android 2.3.6 (API 10) on GT-P1010.
Solved: you can use exec(String prog, String[] envp). In my case this was:
String[] envp = {"LD_LIBRARY_PATH=/data/data/cse.ecg.dcmtk/lib:$LD_LIBRARY_PATH"};
Runtime.getRuntime().exec(myCommand, envp);
The issue now is that with exec() the process executed can't resolve hostnames (it does from adb shell; Internet permission is set). Any hint about that?

Categories

Resources