Android ffmpeg white space in input path causing “

2019-08-02 02:00发布

I'm using the latest version of WritingMinds/ffmpeg-android-java library.

I've tried single/double quoting the path with no success.

I Logged my command after execution, please look to the input path where a subDirectory contains whiteSpace, a comma has been added between the space:

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

I split and run my command like this:

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

storage/emulated/0/Telegram/Telegram: No such file or directory

Any idea on this?

4条回答
forever°为你锁心
2楼-- · 2019-08-02 02:13

Because you use command String[] cropCommand = crop.trim().split(" "); This will cut the file name contains whitespace " " and the input file will be fail

查看更多
男人必须洒脱
3楼-- · 2019-08-02 02:27

try to use double backslashes before the space: "storage/emulated/0/Telegram/Telegram,\\ Video/4_5828137322067002802.mp4"

查看更多
狗以群分
4楼-- · 2019-08-02 02:28

I believe adding commands as List and then converting it to array will solve this problem,

This way the commas should only add to the end of every single commands. I'll show you how:

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);

And this will be the output:

"[-ss, 00:00:00, -noautorotate, -i, storage/emulated/0/Telegram/Telegram Video/4_5828137322067002802.mp4, -vframes, 10, -vf, -cropdetect=24:16:0, ...]";
查看更多
Deceive 欺骗
5楼-- · 2019-08-02 02:39

first replace whitespace of filepath with some creepy string, then while running ffmpeg.execute() replace that creepy string with space.

like:

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"," ");
            }

}
查看更多
登录 后发表回答