gpt4 book ai didi

android - 我可以以编程方式重命名可移动 SD 卡上的文件吗

转载 作者:行者123 更新时间:2023-11-30 01:59:00 24 4
gpt4 key购买 nike

我尝试了以下重命名文件的代码。它适用于内部存储但不适用于可移动 SD 卡文件。我需要重命名可移动 SD 卡上的文件以删除文件名中的空格和特殊字符,因为我正在使用 fmpeg 命令剪切视频。

File from = new File(originalpath);
String rename=originalpath.replace(" ", "").replace("-","").replace(",","").trim();
File to = new File(rename);
Boolean result= from.renameTo(to);

File from = new File(originalpath);
File to=new File((Environment.getExternalStorageDirectory()),"gvideo.mp4");
Boolean result2= from.renameTo(to);

他们都给出了错误的结果

添加有关命令的详细信息-

execFFmpegBinary("-i " + from.getAbsolutePath() + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath());
private void execFFmpegBinary(final String command) {
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.e("Previewragment", "FAILED with output : " + s);
}

@Override
public void onSuccess(String s) {
Log.e("Previewragment", "SUCCESS with output : " + s);
}

@Override
public void onProgress(String s) {
Log.e("Previewragment", "Started command : ffmpeg " + command);
Log.e("Previewragment", "progress : " + s);
}

@Override
public void onStart() {
Log.e("Previewragment", "Started command : ffmpeg " + command);

}

@Override
public void onFinish() {
Log.e("Previewragment", "Finished command : ffmpeg " + command);



}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
}

失败信息-

FAILED with output : WARNING: linker: /data/data/xyz/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 7 2014 15:11:41 with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/i686-linux-android- --arch=x86 --cpu=i686 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/x86 --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
"/storage/emulated/0/Movies/m_ASUS_Display_Demo.mp4": No such file or directory

添加了完整的方法-

private void executeTrimCommand(int startMs, int endMs) {

File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES
);

String filePrefix = "guggu";
String fileExtn = ".mp4";
String fileName = filePrefix + fileExtn;

File from = new File(path);

try {


dest = new File(moviesDir, filePrefix + "_1" + fileExtn);

if (dest.exists()) {
dest.delete();
}



String command = String.format("-i \"%s\" -ss %d -to %d -strict -2 -async 1 \"%s\" ",path,startMs / 1000 , endMs / 1000, dest.getAbsolutePath());
execFFmpegBinary(command);
} catch (Exception e) {
Log.e("Previewragment", e.toString());
e.printStackTrace();
}
}

最佳答案

对于问题中的评论,字符串格式化程序的用法:

String command = String.format("-i \"%s\" -ss %d -to %d -strict -2 -async 1 \"%s\" ",to.getAbsolutePath(),startMs / 1000 , endMs / 1000, dest.getAbsolutePath());

关于android - 我可以以编程方式重命名可移动 SD 卡上的文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31773819/

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