gpt4 book ai didi

java - 尝试编写一个可以使用 yovenny/VideoCompress 将视频压缩为小尺寸的代码

转载 作者:行者123 更新时间:2023-12-01 23:44:14 40 4
gpt4 key购买 nike

自从我尝试获取代码以将视频压缩为小尺寸视频文件(如 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!");
}
}

}

最佳答案

使用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;
}

关于java - 尝试编写一个可以使用 yovenny/VideoCompress 将视频压缩为小尺寸的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58246596/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com