FFmpeg is not working with the media file path containing whitespace in name

Viewed 658

I am using react-native-ffmpeg with react native for basic video editing, however I am facing this issue if a media file uri contain whitespace then ffmpeg task failed with error message "No such file or directory".

I have tried:

  1. RNFmeg.executeWithArguments but app crashes without any error message. Here is my command array.

    RNFFmpeg.executeWithArguments(["-i", videoPath, "-i", songPath, "-c:v", "copy", "-c:a", "aac", "-map", "0:v:0", "-map", "1:a:0", "-t", duration, ${path}${timeStamp}.mp4])

  2. One other solution I do'nt want to go with is to copy the media file which I have picked from device local storage to cache directory with new name eliminating whitespaces.

1 Answers

Working solution

The parameters apparently needs to be strings to guarantee that they work correctly. The -t parameter (duration) had to be converted to a string, as discovered by Kamran Ashiq

Alternate suggestion (shouldn't be the case with this framwork, but useful general solution)

What's most likely happening is that ffmpeg sees the space as a separator for more parameters, such as multiple files.

You should be able to either quote or escape the path, so ffmpeg sees it as just one parameter instead of multiple.

E.g., when calling it on the command line one would either do:

$ ffmpeg -some -parameters "foo bar.mp4"
# or
$ ffmpeg -some -parameters foo\ bar.mp4

Similar in your code you should probably do:

RNFFmpeg.executeWithArguments(["-i", videoPath, "-i", songPath, "-c:v", "copy", "-c:a", "aac", "-map", "0:v:0", "-map", "1:a:0", "-t", duration, `"${path}${timeStamp}.mp4"`])
Related