gpt4 book ai didi

java - 使用 ffmpeg 编辑后的视频未显示在手机图库中

转载 作者:行者123 更新时间:2023-12-02 09:16:13 27 4
gpt4 key购买 nike

我正在开发一个视频编辑器应用程序。该应用程序运行良好并可以编辑视频。但问题是编辑后的视频没有显示在手机图库中。我没这个问题我最后还添加了媒体扫描仪,但我没有成功。

这是我的视频编辑器方法

private void executeCutVideoCommand(int startMs, int endMs) {
File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES
);

String filePrefix = "cut_video";
String fileExtn = ".mp4";
String yourRealPath = getPath(VideoCutterActivity.this, selectedVideoUri);
File dest = new File(moviesDir, filePrefix + fileExtn);
int fileNo = 0;
while (dest.exists()) {
fileNo++;
dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
}

filePath = dest.getAbsolutePath();
String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", yourRealPath, "-t", "" + (endMs - startMs) / 1000,"-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};

execFFmpegBinary(complexCommand);
MediaScannerConnection.scanFile(VideoCutterActivity.this,
new String[] { Environment.getExternalStorageDirectory().toString() },
null,
new MediaScannerConnection.OnScanCompletedListener() {

public void onScanCompleted(String path, Uri uri) {

Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});

}

我只是为了在手机图库中显示编辑后的视频。我现在不知道该怎么办。非常感谢您的帮助

最佳答案

after complete your video editing you must call this method.

public void saveVideoToGallery(Activity activity, File videoFile) {
ContentValues values = new ContentValues();
values.put("title", videoFile.getName());
values.put("description", "video");
values.put("_data", videoFile.getPath());
values.put("mime_type", "video/mp4");
values.put("datetaken", System.currentTimeMillis());
values.put("bucket_id", videoFile.getPath().toLowerCase(Locale.US).hashCode());
values.put("bucket_display_name", videoFile.getName().toLowerCase(Locale.US));
values.put("_data", videoFile.getPath());
ContentResolver cr = activity.getContentResolver();
cr.insert(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
}

关于java - 使用 ffmpeg 编辑后的视频未显示在手机图库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58962572/

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