簡體   English   中英

輸入路徑中的Android ffmpeg空白導致“沒有此類文件或目錄”

[英]Android ffmpeg white space in input path causing “no such file or directory”

我正在使用最新版本的WritingMinds / ffmpeg-android-java庫。

我嘗試單引號/雙引號沒有成功。

我在執行后記錄了命令,請查看子目錄包含whiteSpace的輸入路徑,在空格之間添加了逗號:

ffmpeg, -i, "storage/emulated/0/Telegram/Telegram, Video/4_5828137322067002802.mp4", -vf...

我這樣分割並運行命令:

String crop = "-ss " + skipTimeForCrop + " -noautorotate -i " + newPath + " -vframes 10 -vf cropdetect=24:16:0 -f null -";
String[] cropCommand = crop.trim().split(" ");
execFFmpegForCrop(cropCommand);

存儲/模擬/ 0 /電報/電報:無此類文件或目錄

有什么想法嗎?

我相信將命令添加為List ,然后將其轉換為數組將解決此問題,

這樣,逗號僅應添加到每個命令的末尾。 我將向您展示如何:

List<String> commandList = new LinkedList<>();
commandList.add("-ss");
commandList.add("00:00:00");
commandList.add("-noautorotate");
commandList.add("-i");
commandList.add("storage/emulated/0/Telegram/Telegram Video/4_5828137322067002802.mp4");
commandList.add("-vframes");
commandList.add("10");
commandList.add("-vf");
commandList.add("-cropdetect=24:16:0");
.
.
.

 String[] cropCommand  = commandList.toArray(new String[commandList.size()]);
 execFFmpegForCrop(cropCommand);

這將是輸出:

"[-ss, 00:00:00, -noautorotate, -i, storage/emulated/0/Telegram/Telegram Video/4_5828137322067002802.mp4, -vframes, 10, -vf, -cropdetect=24:16:0, ...]";

因為您使用命令String[] cropCommand = crop.trim().split(" "); 這將剪切包含空格“”的文件名,並且輸入文件將失敗

嘗試在空格前使用雙反斜杠: "storage/emulated/0/Telegram/Telegram,\\\\ Video/4_5828137322067002802.mp4"

首先用一些令人毛骨悚然的字符串替換文件路徑的空白,然后在運行ffmpeg.execute()時用空格替換該令人毛骨悚然的字符串。

喜歡:

String input_path = txt_selected_file.getText().toString().replace(" ","%20");

String cmd = "-i "+ input_path+" -vn -ab 320 -preset ultrafast /storage/emulated/0/Movies/Messenger/test.mp3";
                executeCmd(cmd);

in executecmd() method

private void executeCmd(final String command) {

        try {
            String[] cmd = command.split(" ");
            for(int i = 0; i<cmd.length;i++){
                cmd[i] = cmd[i].replace("%20"," ");
            }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM