How to use latest FFMPEG in Android Studio project?
There's a very easy solution for this, There's a precompiled library for android, as below https://github.com/WritingMinds/ffmpeg-android-java
Simply include this as a gradle project in your code and add few methods as per their documentation and you are done with FFMPEG commands in android.
This library is not very updated and have some missing features but still its good to use for many simple tasks.
How to use ffmpeg command for Android
Since you are doing the ffmpeg
library porting to android, not the ffmpeg
binary format. You need to reference the ffmpeg
library documents to call APIs exported in the library instead invoking the ffmpeg
command.
You could use system()
or exec()
Linux C api to call the command ffmpeg
in JNI, but i don't think this is the way you are looking for.
The article link you posted already provide the examples, have you checked?
Why Video not saving given path using ffmpeg in android?
First step is to add permissions to manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Then add "Permission asking" code to java file
call
hasPermission();
from your activity'sonCreate()
and here's your method :private void hasPermission() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
final String[] s = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
PermissionsDialog(s);
} else {
// do something when you got permission
}
} else {
// do something when you got permission
}
}
Android app requires user permission on devices with api >= 23
This will ask for permission if your device's api
version is >= 23
, if it is below 23
or permission is already granted then next task will be performed.
if user deny
permission then PermissionsDialog(s);
will be called for asking permission.
private void PermissionsDialog(final String[] s) {
ActivityCompat.requestPermissions(MainActivity.this, s, Helper.REQUEST_PERMISSION);
}
Then if user allow
or deny
permission it comes in this method :
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == Helper.REQUEST_PERMISSION) {
if (grantResults.length > 0) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
!ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, permissions[0])) {
startActivityForResult(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:" + BuildConfig.APPLICATION_ID)), Helper.SETTINGS_CODE);
} else {
hasPermission();
}
} else {
// do something when you got permission
}
}
}
}
}
This method checks if permission is granted or not and it continues to ask for permission until you allow
and if you deny
for permission with don't ask again
then we have to navigate user to App Setting Screen for allowing permission manually.
Now,when user comes from setting screen onActivityResult(...)
of activity will be called, here call hasPermission();
for recheck if user granted permission from setting screen or not which is as below :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Helper.SETTINGS_CODE) {
hasPermission();
}
}
Related Topics
Is Proguard.Cfg Needed for Library Projects
Could Not Find Com.Android.Tools.Build:Gradle:4.0.1 ( or Any Version )
Limit Scrolling and Zooming Google Maps Android API V2
How to Hide System Bar on Android Ics
How to Add Crosswalk Webview in My Own Android Library Module
How to Shutdown an Android Mobile Programmatically
Can't Apply System Screen Brightness Programmatically in Android
How to Add a Gesture Detector to a View in Android
Android Xml VS Java Layouts Performance
How to Upload File Using Volley Library in Android
How to Play an Mp3 in the Res/Raw Folder of My Android App
Android Opengl Es 2.0 Emulator
Resource Linking Fails on Lstar
Difference Between Finish() and System.Exit(0)
How to Set Google Map Fragment Inside Scroll View
How to Analyze Memory Using Android Studio
Gradle Error:Execution Failed for Task ':App:Processdebuggoogleservices'