I'm using FFMPEG to measure the duration of videos stored in an Amazon S3 Bucket.
I've read the FFMPEG docs, and they explicitly state that all whitespace and special characters need to be escaped, in order for FFMPEG to handle them properly:
See docs 2.1 and 2.1.1: https://ffmpeg.org/ffmpeg-utils.html
However, when dealing with files whose filenames contain whitespace, ffmpeg fails to render a result.
I've tried the following, with no success
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my video file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my'\' video'\' file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
However, if I strip out the whitespace in the filename – all is well, and the duration of the video is returned.
Any help is appreciated!
ffmpeg uses % to define a pattern and handle multiple files. For instance if your filename is URI encoded you must use "-pattern_type none" to avoid misinterpretation from ffmpeg:
`just rename the file for the conversion :)
If you happen to have spaces in your file name, just quote them:
In a URL, a space cannot be there. Most probably you have to replace every single space with a
%20
, so that you get:As many have pointed out, the best option is to quote the string. It works for all other special characters. I am attaching a snapshot from Here are some examples I found of the ffmpeg documentation page. I am attaching a screen shot just in in case it is unavailable in the future.
To make ffmeg works with filename/path that have whitespaces, you should:
1) set the working directory with
Pushd
2) put your filename inside quote
""
here is a working example:
I solved it by "enquoting" the arg that contain the file path. In my case, the path was stored in the %1 argument (which was written in the registry under quote that are escaped: \"%1\" ). I retrieve it (with a PowerShell script), simply using $arg (inbuilt argument). I then used it get some file information such as:
Don't forget the quote around
$FilePath
.Then you can use it to divide audio filesin 5min parts simply like this: