Using FFMPEG via command line in android - 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.

Related

Unity command line arguments for android and iOS

Please pardon my ignorance, relatively new to working with Unity3D. I am working on automating Unity3d builds from the command line.
I am looking for command line arguments to build apk & xcode project.
Unity's documentation does mention arguments to build a standalone Mac OSX player (-buildOSXPlayer) and a standalone Windows player (-buildWindowsPlayer) but not for android and iOS.
Any help would be really appreciated. Thanks.
Start with Unity's own documentation for command line builds for iOS and android.
For example, put this script in your Assets/Editor folder:
// C# example
using UnityEditor;
class Autobuilder
{
[MenuItem ("File/AutoBuilder/iOS")]
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
string buildPath = "../../../Build/iOS";
// Create build folder if not yet exists
Directory.CreateDirectory(buildPath);
BuildPipeline.BuildPlayer(scenes, buildPath, BuildTarget.iOS, BuildOptions.Development);
}
}
You can actually run this script in the Unity application by going to File -> Autobuilder -> iOS
To run on command line, it looks something like this:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Autobuilder.PerformBuild -email me#email.com -password myPassword
Of course, you're going to want to check the debug log for any errors:
Mac OS X ~/Library/Logs/Unity/Editor.log
Windows XP C:\Documents and Settings\username\Local Settings\Application Data_\Unity\Editor\Editor.log
Windows Vista/7 C:\Users\username\AppData\Local\Unity\Editor\Editor.log
The -executeMethod command line parameter is a very simple option to invoke any function in any of your scripts - which you can then use to do pretty much anything, including firing off an Android build.

how to convert pdf to pksmraw by using ghostscript in android system?the error code is -15

I want to convert pdf to pksmraw by using ghostscript9.04, the command is:
gs -q -dBATCH -dSAFER -dQUIET -dNOPAUSE -sPAPERSIZE=a4 -r300x300 -sDEVICE=pksmraw -sOutputFile=printjob.pksmraw printjob.pdf
But in android system, it's no output, and the error code is -15.
I think it's maybe Resources and libs is can't be found.
So in android system, how to set up the Resources and libs?
error code -15 is a rangecheck error. In order to find out more you are going to have to find out where stdout and stderr are going, and capture them.
We don't supply Ghostscript for Android systems, so I assume you built this yourself, in which case it should be reasonably straight-forward for you to figure out where the error messages are going.
Oh, the current version is 9.10, you might well want to upgrade too.
Library and resource files are ordinarily built into the executable using a rom file system, unless you specified COMPILE_INITS=0 at build time.
Try this example
gs \
-sDEVICE=pdfwrite \
-o foo.pdf \
/usr/local/share/ghostscript/8.71/lib/viewjpeg.ps \
-c \(my.jpg\) viewJPEG
reads my.jpg and produces foo.pdf. You will have to find where your installation installed the PostScript program viewjpeg.ps.
Same way do it for to convert pdf to pksmraw it will work for you.

Android FFMPEG: Could not execute the ffmpeg from Java code

I am working on an Android app where I want to create a video from a
list of static images. After doing some search on internet, it made me
realized that using "FFMPEG" is the way to go in getting this thing
done. So I got hold of this site:
https://github.com/guardianproject/android-ffmpeg-java from where I
downloaded the C library and the Java wrapper. I was able to compile the
C library - of course not the way the instruction was laid out - but
still I was able to get "ffmpeg" executable under
/external/android-ffmpeg/ffmpeg directory. I copied that executable in
my current directory and then copied it to a directory under Android
where my app can access it. Then I called the provided Java wrapper but
I am seeing some errors in the log file like follows:
08-13 11:55:37.848: D/FFMPEG(29598): /data/data/com.sample/app_bin/ffmpeg -y -loop 1 -i /storage/emulated/0/usersnapshot/ffmpeg/image%03d.jpg -r 25 -t 2 -qscale 5 /storage/emulated/0/video/snapshot-video.mp4
08-13 11:55:37.898: I/ShellCallback : shellOut()(29598): /data/data/com.sample/app_bin/ffmpeg[1]: syntax error: '(' unexpected
08-13 11:55:37.938: I/ShellCallback : processComplete()(29598): 1
And following is the code snippet (where targetDirectoryForFFMPEG = directory where the images are stored):
FfmpegController ffmpegController = new FfmpegController(this, targetDirectoryForFFMPEG);
String out = videoOutPutFile.getPath();
MediaDesc mediaIn = new MediaDesc();
mediaIn.path = targetDirectoryForFFMPEG+"/image%03d.jpg";
mediaIn.videoFps = "25";
ffmpegController.convertImageToMP4(mediaIn, 2, out,new ShellCallback() {
#Override
public void shellOut(String shellLine) {
Log.i("ShellCallback : shellOut()", shellLine);
}
#Override
public void processComplete(int exitValue) {
Log.i("ShellCallback : processComplete()", exitValue+"");
}
});
Has anybody implemented this before? If yes, can you point me to what am I doing incorrect? I will provide more information if needed.
Do you have root on the device?
Mount '/data' and then enter your same 'ffmpeg' command in the shell and see whether the error is the same.
Try using the shell to test out different command expressions.
Try 'ffmpeg' alone and with just one input file. See whether those commands produce expected output.
My wild guess would be that there is an issue with calling 'ffmpeg.main()' that relates to the details of your build.
Your ffmpeg might not be compiled properly for the arm. I was getting the same error when not using a correctly compiled ffmpeg.

bambuser ffmpeg on 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.

Getting exception while trying to run ffmpeg via command line in android

I want to use ffmpeg via command line arguments in android application.For this purpose:
I have cross-compiled the ffmpeg lib and got the libffmpeg.so
I have stored libffmpeg.so in files directory of the app.
This is the code i am using:
public class MainActivity 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 guess you are trying to run an .so file with this Linux command:
/data/data/com.example.ffmpegnew/files/libffmpeg.so -i mnt/sdcard/music/baba.mp4 mnt/sdcard/music/outfile.mp4
Did you actually mean running ffmpeg executable file (see man ffmpeg)?
ffmpeg -i mnt/sdcard/music/baba.mp4 mnt/sdcard/music/outfile.mp4
I think the first step might be making your command, then your code snippet run on regular Linux, then moving it to Android.
PS. In any event, the leading "/" is missing from "mnt/..."; should be "/mnt/..."
PPS. And other discussions might be helpful 1

Categories

Resources