[英]Properly loading large image from drawable/assets folder in Android
[英]Android ffmpeg : Use image for Watermark from drawable or assets folder
如何使用Android中drawable文件夾或assets文件夾中的圖像作為水印。
我發現了很多帶有命令的示例,但所有示例都使用內部存儲的靜態圖像路徑。
我已經完成了以下代碼來制作帶水印的視頻。
try {
FFmpeg ffmpeg = FFmpeg.getInstance(mContext);
// to execute "ffmpeg -version" command you just need to pass "-version"
String mSelectedPath = PathUtils.getPathFromUri(mContext, selectedUri);
String mFileName = PathUtils.getFileName(mSelectedPath);
final String mDestinationPath = "/storage/emulated/0/" + mFileName;
String[] array = new String[]{"-i", mSelectedPath , "-i", "/storage/emulated/0/logo.png", "-filter_complex", "[0:v][1:v]overlay=main_w-overlay_w-10:10", "-codec:a", "copy", mDestinationPath};
ffmpeg.execute(array, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
Log.d(TAG, "onStart: ");
Toast.makeText(mContext, "Preparing video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onProgress(String message) {
Log.d(TAG, "onProgress: " + message);
Toast.makeText(mContext, "Processing for compression...", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(String message) {
Log.d(TAG, "onFailure: " + message);
Toast.makeText(mContext, "Failed to upload, Try Again.", Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess(String message) {
Log.d(TAG, "onSuccess: " + message);
Toast.makeText(mContext, "Uploading started", Toast.LENGTH_SHORT).show();
mFinalUploadUri = PathUtils.getUriFromPath(mContext, new File(mDestinationPath));
uploadVideo();
}
@Override
public void onFinish() {
Log.d(TAG, "onFinish: ");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
e.printStackTrace();
}
有人知道如何使用 drawable 或 assets 文件夾中的圖像作為水印嗎? 任何人都可以幫忙嗎?
FFMpeg 不是 Android Environment 。 Drawable 和 Assets 目錄僅用於 Android 環境所以如果您希望將圖像添加為水印,您應該只選擇文件存儲路徑
我創建了saveImage()
來將 drawable 保存到外部存儲中。
private void saveImage() {
//TODO Change logo.png in drawable folder for watermark
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File file = new File(extStorageDirectory, "logo.png");
if (!file.exists()) {
try {
FileOutputStream outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
你的命令將是:
String[] array = new String[]{"-y", "-i", mSelectedPath, "-i", Environment.getExternalStorageDirectory() + "logo.png", "-filter_complex", "[0:v][1:v]overlay=main_w-overlay_w-10:10", "-codec:a", "copy", mDestinationPath};
注意:您必須獲得以下許可:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
謝謝你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.