пытаюсь написать код, который может сжать видео в небольшой размер, используя yovenny / VideoCompress - PullRequest
0 голосов
/ 05 октября 2019

Прошло два дня с тех пор, как я пытаюсь создать код для операции, в которой видео можно сжать в видеофайлы небольшого размера, такие как WhatsApp. Я перепробовал все решения, которые нашел в Интернете, но никто из этих работников, возможно, в настоящее время использовал их неправильно, у меня есть решение в https://github.com/yovenny/VideoCompress, поэтому я пытался работать с этим, но яполучить ошибкуОшибка говорит о том, что

   java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.nanb.alpha-2/base.apk"],nativeLibraryDirectories=[/data/app/com.nanb.alpha-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libcompress.so"

, если у вас есть какое-то другое решение, пожалуйста, поделитесь со мной и скажите мне, как реализовать решение в моей заявке. код указан ниже.

 public class videocompress extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
    return MediaController.getInstance().convertVideo(params[0],params[1]);
}
@Override
protected void onPostExecute(Boolean compressed) {
    super.onPostExecute(compressed);
    if(compressed){
        Log.d("video compress","Compression successfully!");
    }
}

}

1 Ответ

0 голосов
/ 05 октября 2019

Использование SiliCompressor

Вот пример кода:

Класс сжатия видео

class VideoCompressAsyncTask extends AsyncTask<String, String, String> {

Context mContext;
String thumbnail;

public VideoCompressAsyncTask(Context context, String thumbnail){
mContext = context;
this.thumbnail = thumbnail;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
pd.setMessage("Uploading Video...");
pd.show();

}

@Override
protected String doInBackground(String... paths) {
String filePath = null;
try {

filePath = SiliCompressor.with(mContext).compressVideo(paths[0], paths[1]);

} catch (URISyntaxException e) {
e.printStackTrace();
}
return filePath;

}


@Override
protected void onPostExecute(String compressedFilePath) {
super.onPostExecute(compressedFilePath);
UploadMedia(compressedFilePath, thumbnail,"video");
Log.i("Silicompressor", "Path: "+compressedFilePath);
}
}

и в onActivityResult вы называете этот класс

if(requestCode == SELECT_VIDEO && resultCode == RESULT_OK)
{
Uri uri = data.getData();
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if(cursor!=null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + getPackageName() + "/media/videos");
if (f.mkdirs() || f.isDirectory())
//compress and output new video specs
new VideoCompressAsyncTask(this,getThumbnailPathForLocalFile(this,uri)).execute(cursor.getString(column_index), f.getPath());
cursor.close();
}else
Toast.makeText(ChatScreen.this, "No Video Found", Toast.LENGTH_SHORT).show();
}

также вы можете получить миниатюру видео с помощью этого метода

public static String getThumbnailPathForLocalFile(ChatScreen context, Uri fileUri ) {
    long fileId = getFileId(context, fileUri);
    Log.e("ID",fileId+"");
    MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),
            fileId, MediaStore.Video.Thumbnails.MICRO_KIND, null);
    Cursor thumbCursor = null;
    try {
        thumbCursor = context.managedQuery(
                MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + " = " + fileId, null, null);
        if (thumbCursor.moveToFirst()) {
            String thumbPath = thumbCursor.getString(thumbCursor
                    .getColumnIndex(MediaStore.Video.Thumbnails.DATA));
            Log.e("ThumbPath",thumbPath);
            return thumbPath;
        }

    } finally {
    }
    return null;
}
...