Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg not working with filenames that have whitespace

Tags:

bash

ffmpeg

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.

like image 907
cmw Avatar asked Mar 31 '14 15:03

cmw


2 Answers

If you happen to have spaces in your file name, just quote them:

ffmpeg -i "my video file.mov"

In a URL, a space cannot be there. Most probably you have to replace every single space with a %20, so that you get:

ffmpeg -i http://myurl.com/my%20video%20file.mov
                             ^^^     ^^^
like image 125
fedorqui 'SO stop harming' Avatar answered Oct 28 '22 17:10

fedorqui 'SO stop harming'


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:

ffmpeg -pattern_type none -i file%20name.mp4
like image 34
Rodrigo Fava Avatar answered Oct 28 '22 18:10

Rodrigo Fava