gpt4 book ai didi

java - ffmpeg命令不适用于Android中目录路径的空白

转载 作者:行者123 更新时间:2023-12-04 23:26:43 25 4
gpt4 key购买 nike

我正在使用 FFMPEG我想在其中使用这个库来旋转视频的库,如果我是 file path,它可以正常工作没有任何white space .但是在我的情况下,我有视频目录的空白(您可以在 String commandStr onPreExecute()asynctask 方法中看到完整路径)路径,那么它根本不起作用。我也看到过类似的问题 this还有一些但不知道如何正确解决它。下面是我的 MainActivity.class 代码

    public class MainActivity extends AppCompatActivity implements View.OnClickListener{

String workFolder = null;
String demoVideoFolder = null;
String vkLogPath = null;
private boolean commandValidationFailedFlag = false;

private Button btnRun;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, true);


setIds();
setListner();


demoVideoFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/videokit/";

Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(getApplicationContext()) );
workFolder = getApplicationContext().getFilesDir().getAbsolutePath() + "/";
vkLogPath = workFolder + "vk.log";

GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(this, workFolder);
GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(this, demoVideoFolder);


int rc = GeneralUtils.isLicenseValid(getApplicationContext(), workFolder);
Log.i(Prefs.TAG, "License check RC: " + rc);
}

private void setListner() {
btnRun.setOnClickListener(this);
}

private void setIds() {
try {
btnRun = (Button)findViewById(R.id.btnRun);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnRun:

Log.i(Prefs.TAG, "run clicked.");
if (GeneralUtils.checkIfFileExistAndNotEmpty(workFolder)) {
new TranscdingBackground(MainActivity.this).execute();
}
else {
Toast.makeText(getApplicationContext(), workFolder + " not found", Toast.LENGTH_LONG).show();
}
break;
}
}

public class TranscdingBackground extends AsyncTask<String, Integer, Integer>
{

ProgressDialog progressDialog;
Activity _act;
String commandStr;

public TranscdingBackground (Activity act) {
_act = act;
}



@Override
protected void onPreExecute() {

// commandStr = "ffmpeg -y -i /storage/emulated/0/WhatsApp/Media/in.mp4 -vf rotate=270*(PI/180) /sdcard/videokit/out.mp4";
commandStr = "ffmpeg -y -i /storage/emulated/0/WhatsApp/Media/WhatsApp Video/in.mp4 -vf rotate=270*(PI/180) /sdcard/videokit/out.mp4";


progressDialog = new ProgressDialog(_act);
progressDialog.setMessage("FFmpeg4Android Transcoding in progress...");
progressDialog.show();

}

protected Integer doInBackground(String... paths) {
Log.i(Prefs.TAG, "doInBackground started...");

// delete previous log
boolean isDeleted = GeneralUtils.deleteFileUtil(workFolder + "/vk.log");
Log.i(Prefs.TAG, "vk deleted: " + isDeleted);

PowerManager powerManager = (PowerManager)_act.getSystemService(Activity.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VK_LOCK");
Log.d(Prefs.TAG, "Acquire wake lock");
wakeLock.acquire();



LoadJNI vk = new LoadJNI();
try {

vk.run(GeneralUtils.utilConvertToComplex(commandStr), workFolder, getApplicationContext());

// copying vk.log (internal native log) to the videokit folder
GeneralUtils.copyFileToFolder(vkLogPath, demoVideoFolder);

} catch (CommandValidationException e) {
Log.e(Prefs.TAG, "vk run exeption.", e);
commandValidationFailedFlag = true;

} catch (Throwable e) {
Log.e(Prefs.TAG, "vk run exeption.", e);
}
finally {
if (wakeLock.isHeld())
wakeLock.release();
else{
Log.i(Prefs.TAG, "Wake lock is already released, doing nothing");
}
}
Log.i(Prefs.TAG, "doInBackground finished");
return Integer.valueOf(0);
}

protected void onProgressUpdate(Integer... progress) {
}

@Override
protected void onCancelled() {
Log.i(Prefs.TAG, "onCancelled");
//progressDialog.dismiss();
super.onCancelled();
}


@Override
protected void onPostExecute(Integer result) {
Log.i(Prefs.TAG, "onPostExecute");
progressDialog.dismiss();
super.onPostExecute(result);

// finished Toast
String rc = null;
if (commandValidationFailedFlag) {
rc = "Command Vaidation Failed";
}
else {
rc = GeneralUtils.getReturnCodeFromLog(vkLogPath);
}
final String status = rc;
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MainActivity.this, status, Toast.LENGTH_LONG).show();
if (status.equals("Transcoding Status: Failed")) {
Toast.makeText(MainActivity.this, "Check: " + vkLogPath + " for more information.", Toast.LENGTH_LONG).show();
}
}
});
}
}

}

这里 onPreExecute()方法我已经给出了视频文件路径。

最佳答案

我的事情,因为你做了一个命令行调用,你需要这些:

  • 转义一些特殊字符 (就像你在命令行上也需要)
  • 引用文件名 (比你需要在文件名中转义引号)
  • 关于java - ffmpeg命令不适用于Android中目录路径的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43365415/

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