Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
933 views
in Technique[技术] by (71.8m points)

bash - ffmpeg not working with filenames that have whitespace

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
                             ^^^     ^^^

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...