Search code examples
androidffmpeg

Android ffmpeg white space in input path causing "no such file or directory"


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?


Solution

  • 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, ...]";