[FFmpeg-user] Subtitle filter and filename with quotes and spaces

Stefano Sabatini stefasab at gmail.com
Tue Jan 21 18:56:36 CET 2014


On date Sunday 2014-01-19 19:34:51 -0500, Ramit Bhalla wrote:
> I'm trying to use the subtitle filter to burn in the subtitles while
> encoding. My filename has a space and a quote in it. I've tried every
> possible combination of escaping, quoting, double quoting etc but I just
> can't get it to work.
> 
> This is what I 'want' to execute:
> 
> ffmpeg.exe -probesize 100M -analyzeduration 300M -threads 0 -drc_scale 0.8
> -y -i "D:\MCEBuddy\MCEBuddy
> 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts" -ss 3 -vf
> yadif=0:-1:1,hqdn3d,crop=1920:1072:0:4,scale=720:400,subtitles="D:\MCEBuddy\MCEBuddy
> 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.srt" -vcodec
> libx264 -b 1400000 -x264opts
> me=hex:trellis=1:subq=8:partitions=all:8x8dct=1:ref=3:rc-lookahead=50:keyint=25:min-keyint=20:bframes=1:weightb=1:level=4.0:b-pyramid=normal:direct=auto:mixed-refs=1:deblock=-1,-1:no-fast-pskip=1:no-dct-decimate=1:b-adapt=0:threads=auto
>  -sn -acodec libfdk_aac -ab 256k -cutoff 18000  -ac 2 "D:\MCEBuddy\MCEBuddy
> 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'-converted.mp4"
> 

> the SRT filepath is 

D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.srt

So this string contains : which is special according to the filter
description syntax, and the \ and ' special escaping characters.

So, first level escaping:
D\:\\MCEBuddy\\MCEBuddy 2.x\\MCEBuddy.ServiceCMD\\bin\\x86\\Debug\\working0\\HD Small\'.srt

Now you embed the filter description string in the filtergraph
description, so you add another escaping level, and you need to escape
the special \ and ' characters. One way of doing this is as:

subtitles=D\\:\\\\MCEBuddy\\\\MCEBuddy 2.x\\\\MCEBuddy.ServiceCMD\\\\bin\\\\x86\\\\Debug\\\\working0\\\\HD Small\\\'.srt

Alternatively you use quoting:
subtitles='D\:\\MCEBuddy\\MCEBuddy 2.x\\MCEBuddy.ServiceCMD\\bin\\x86\\Debug\\working0\\HD Small'\'.srt

At this point you need a third level escaping which depends on the
shell. With bash you need to escape again the \ and ' characters, so
you get:

ffmpeg ... -vf subtitles=D\\\\:\\\\\\\\MCEBuddy\\\\\\\\MCEBuddy 2.x\\\\\\\\MCEBuddy.ServiceCMD\\\\\\\\bin\\\\\\\\x86\\\\\\\\Debug\\\\\\\\working0\\\\\\\\HD Small\\\\\\\'.srt

Alternatively with " quoting (only \ needs to be escaped):
ffmpeg ... -vf "subtitles='D\\:\\\\MCEBuddy\\\\MCEBuddy 2.x\\\\MCEBuddy.ServiceCMD\\\\bin\\\\x86\\\\Debug\\\\working0\\\\HD Small'\\'.srt"

I don't know how escaping works with the Windows shell.

See:
http://ffmpeg.org/ffmpeg-filters.html#Notes-on-filtergraph-escaping

Unfortunately there is no easy way to escape the escaping hell. You
can avoid the shell third level expansion by reading the filtergraph
from a file, or you can try hard to avoid to have special characters
in your input filename, or you can use tools/ffescape with scripts.

[...] 

> What is the right way to use this with subtitles or is it not possible at
> all?


More information about the ffmpeg-user mailing list