Using FFmpeg without NDK in android

I go to many sites and searches regarding the implementation of FFMPEG for the android project.

Most solutions are based on the use of NDK.

but I want to use FFmpeg without using the NDK , as I found in this link

0
android ffmpeg android-ndk shared-libraries
source share
2 answers

I used this project https://github.com/guardianproject/android-ffmpeg-java

It has already been compiled for the version of the FFMPEG library for Android and this file will be located in the res / raw folder (you can update this file if you need a newer version). You need to add this project as a library for yours. And after you can write your own function in java, for example, like this:

public Clip convert (Clip mediaIn, String outPath, ShellCallback sc) throws Exception { ArrayList<String> cmd = new ArrayList<String>(); cmd.add(mFfmpegBin); cmd.add("-y"); cmd.add("-i"); cmd.add(new File(mediaIn.path).getCanonicalPath()); if (mediaIn.startTime != null) { cmd.add("-ss"); cmd.add(mediaIn.startTime); } if (mediaIn.duration != -1) { cmd.add("-t"); cmd.add(String.format(Locale.US,"%f",mediaIn.duration)); } Clip mediaOut = new Clip(); File fileOut = new File(outPath); mediaOut.path = fileOut.getCanonicalPath(); cmd.add(mediaOut.path); execFFMPEG(cmd, sc); return mediaOut; } 

and execute it using the FfmpegController object. Please note if you have any questions or if that is what you want.

EDIT: Hope you put together this github code as a library for your project. There is a class FfmpegController.java in the src folder. This is the shell for using the ffmpeg exe command line file. If you want, for example, to execute a command like this,

 ffmpeg -i source.wav -b:a 128k output.mp3 

you need to add the function to the FfmpegController.java class. Something like that:

  public Clip convert(Clip mediaIn, String outPath, ShellCallback sc) throws Exception { ArrayList<String> cmd = new ArrayList<String>(); Clip mediaOut = new Clip(); String mediaPath = mediaIn.path; cmd = new ArrayList<String>(); cmd.add(mFfmpegBin); cmd.add("-i"); cmd.add(mediaPath); cmd.add("-b:a"); cmd.add("128k"); mediaOut.path = outPath; cmd.add(mediaOut.path); execFFMPEG(cmd, sc); return mediaOut; // this is not importatnt because file will be put in outPath } 

Now in your project, initialize the FfmpegController object and run your function.

+2
source share

I used this sample FFmpeg, which is a library that is used without the NDK

First boot example example FFmpeg example

Download FFmpeg Library FFmpeg Library

Extract both to one folder and import the project from Android Studio

Now call ffmpeg command

This command is designed to rotate (/sdcard/videokit/in.mp4) video in 90 degrees and generate out.mp4 in a specific place on the SD card

 ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k /sdcard/videokit/out.mp4 

Now run this command using the predefined method in the library and add the GeneralUtils listeners

 GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(this, workFolder); GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(this, demoVideoFolder); //demoVideoFolder where your Input file path //workFolder Absolute path // workFolder = getApplicationContext().getFilesDir().getAbsolutePath() + "/"; LoadJNI vk = new LoadJNI(); try { vk.run(GeneralUtils.utilConvertToComplex(commandStr), workFolder, getApplicationContext()); // copying vk.log (internal native log) to the videokit folder GeneralUtils.copyFileToFolder(vkLogPath, demoVideoFolder); } catch (Throwable e) { Log.e(Prefs.TAG, "vk run exeption.", e); } 

Run this and check in the File Manager for output. I hope it works. Good :) Enjoy.

+1
source share

All Articles