Closed WizzerWorks closed 3 years ago
I watched your video on https://www.geeksforgeeks.org/how-to-use-ffmpeg-in-android-with-example/. It shows a pop-up "Complete action using" and you select the File Manager. However, that does not happen in my build of your source. Instead I get a blank screen with "Select a video" titel.
Please provide some documentation on how to use your example. I built this app in Android Studio and the "SELECT VIDEO" button brings up an empty Intent in the Emulator. I'm assuming that I need to stage an uploaded video file (i.e. mp4). I did this and it is in the "/sdcard/Download" folder. However the file does not show up in the Intent. So I think the file needs to be staged somewhere else. Where in the file system should the file be?
I would recommend using the Storage Access Framework. The method implemented in this project might not work in Android 11. The best way to support all devices and all android version is using the SAF. You can use the below code to select video from device, which will return a content uri.
ActivityResultLauncher<Intent> onActivityResult=registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if(result.getResultCode()== Activity.RESULT_OK){
Intent intent=result.getData();
if(intent!=null){
ClipData clipData=intent.getClipData();
if(clipData!=null) {
ArrayList<String> contentUris=new ArrayList<>();
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item=clipData.getItemAt(i);
getActivity().getContentResolver().takePersistableUriPermission(item.getUri(), Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
contentUris.add(item.getUri().toString());
}
}
}
}
}
}
);
Intent intent=new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("video/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
onActivityResult.launch(intent);
The content uri can not be directly used as ffmpeg input. You need to migrate the mobile-ffmpeg to ffmpeg-kit. Here you will find a function,
Uri uri = intent.getData();
String inputPath = FFmpegKitConfig.getSafParameterForRead(requireContext(), uri);
FFmpegKit.execute("-i " + inputPath + " ... output.mp4");
you can use this, to make things work.
Thank you.
Please provide some documentation on how to use your example. I built this app in Android Studio and the "SELECT VIDEO" button brings up an empty Intent in the Emulator. I'm assuming that I need to stage an uploaded video file (i.e. mp4). I did this and it is in the "/sdcard/Download" folder. However the file does not show up in the Intent. So I think the file needs to be staged somewhere else. Where in the file system should the file be?