Opened 11 years ago

Closed 11 years ago

#3334 closed defect (fixed)

Escaping and quoting not working with subtitles video filter

Reported by: ramitb Owned by:
Priority: minor Component: documentation
Version: git-master Keywords: escaping
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: I have a filename and path which includes spaces, colons and single quotes. When trying to pass the file to the subtitle filter I followed the rules on this page:

https://ffmpeg.org/ffmpeg-utils.html#Quoting-and-escaping

Quoting:
All characters enclosed between ” are included literally in the parsed string. The quote character ' itself cannot be quoted, so you may need to close the quote and escape it.

It doesn't work.

How to reproduce:

ffmpeg -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD S
mall'.ts" -vf subtitles="D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small"\'".srt" -vcodec m
peg4 -b:v 1500k -acodec copy test.ts -y
ffmpeg version N-59362-ge079661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 25 2013 17:42:26 with gcc 4.8.0 (GCC)
  configuration: --arch=x86 --target-os=mingw32 --cross-prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/bin
/i686-w64-mingw32- --pkg-config=pkg-config --enable-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-lib
mp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enabl
e-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --disable-w32threads --enable-frei0r
 --enable-filter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflags=-DPTW32_STATIC_LIB --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-
libilbc --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libmodplug --extra-libs=-lstdc++
--enable-libzvbi --enable-libcaca --prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/i686-w64-mingw32 --enab
le-static --disable-shared --enable-libsoxr --enable-fontconfig --enable-libass --enable-libutvideo --enable-libbluray -
-extra-cflags= --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 46.100 / 55. 46.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.102 /  4.  0.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts':
  Duration: 00:01:52.06, start: 1.400000, bitrate: 13152 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:
9], max. 38810 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
[subtitles @ 048d3420] Unable to parse option value "MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugworking0HD Small.
srt" as image size
    Last message repeated 1 times
[subtitles @ 048d3420] Error setting option original_size to value MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugwor
king0HD Small.srt.
[Parsed_subtitles_0 @ 048d33a0] Error applying options to the filter.
[AVFilterGraph @ 0243e2a0] Error initializing filter 'subtitles' with args 'D:MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbin
x86Debugworking0HD Small'.srt'
Error opening filters!

I referred to the advice on ticket #2067 and escaped the colon. It still doesn't work:

ffmpeg -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD S
mall'.ts" -vf subtitles="D"\:"\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small"\'".srt" -vcode
c mpeg4 -b:v 1500k -acodec copy test.ts -y
ffmpeg version N-59362-ge079661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 25 2013 17:42:26 with gcc 4.8.0 (GCC)
  configuration: --arch=x86 --target-os=mingw32 --cross-prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/bin
/i686-w64-mingw32- --pkg-config=pkg-config --enable-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-lib
mp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enabl
e-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --disable-w32threads --enable-frei0r
 --enable-filter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflags=-DPTW32_STATIC_LIB --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-
libilbc --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libmodplug --extra-libs=-lstdc++
--enable-libzvbi --enable-libcaca --prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/i686-w64-mingw32 --enab
le-static --disable-shared --enable-libsoxr --enable-fontconfig --enable-libass --enable-libutvideo --enable-libbluray -
-extra-cflags= --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 46.100 / 55. 46.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.102 /  4.  0.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts':
  Duration: 00:01:52.06, start: 1.400000, bitrate: 13152 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:
9], max. 38810 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
[subtitles @ 04973240] Unable to parse option value "MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugworking0HD Small.
srt" as image size
    Last message repeated 1 times
[subtitles @ 04973240] Error setting option original_size to value MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugwor
king0HD Small.srt.
[Parsed_subtitles_0 @ 049735c0] Error applying options to the filter.
[AVFilterGraph @ 0283e180] Error initializing filter 'subtitles' with args 'D:MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbin
x86Debugworking0HD Small'.srt'
Error opening filters!

The subtitle filter parsing is broken.

Change History (13)

comment:1 by ramitb, 11 years ago

FYI I even tried escaping the slashes:

ffmpeg -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD S
mall'.ts" -vf subtitles="D:\\MCEBuddy\\MCEBuddy 2.x\\MCEBuddy.ServiceCMD\\bin\\x86\\Debug\\working0\\HD Small"\'".srt" -
vcodec mpeg4 -b:v 1500k -acodec copy test.ts -y
ffmpeg version N-59362-ge079661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 25 2013 17:42:26 with gcc 4.8.0 (GCC)
  configuration: --arch=x86 --target-os=mingw32 --cross-prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/bin
/i686-w64-mingw32- --pkg-config=pkg-config --enable-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-lib
mp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enabl
e-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --disable-w32threads --enable-frei0r
 --enable-filter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflags=-DPTW32_STATIC_LIB --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-
libilbc --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libmodplug --extra-libs=-lstdc++
--enable-libzvbi --enable-libcaca --prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/i686-w64-mingw32 --enab
le-static --disable-shared --enable-libsoxr --enable-fontconfig --enable-libass --enable-libutvideo --enable-libbluray -
-extra-cflags= --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 46.100 / 55. 46.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.102 /  4.  0.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts':
  Duration: 00:01:52.06, start: 1.400000, bitrate: 13152 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:
9], max. 38810 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
[subtitles @ 02773120] Unable to parse option value "MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugworking0HD Small.
srt" as image size
    Last message repeated 1 times
[subtitles @ 02773120] Error setting option original_size to value MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugwor
king0HD Small.srt.
[Parsed_subtitles_0 @ 027730a0] Error applying options to the filter.
[AVFilterGraph @ 03c95b40] Error initializing filter 'subtitles' with args 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD
\bin\x86\Debug\working0\HD Small'.srt'
Error opening filters!

comment:2 by Kieran Kunhya, 11 years ago

You probably need to escape the spaces.

comment:3 by Carl Eugen Hoyos, 11 years ago

Resolution: invalid
Status: newclosed

This was apparently answered on the mailing list.

comment:4 by ramitb, 11 years ago

If I need to escape the spaces (which aren't special characters), what is is the point of the quotes? The inputs works fine, why the special treatment for the filter?

BTW it still doesn't work.

ffmpeg -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD S
mall'.ts" -vf subtitles="D:\\MCEBuddy\\MCEBuddy\ 2.x\\MCEBuddy.ServiceCMD\\bin\\x86\\Debug\\working0\\HD\ Small"\'".srt"
 -vcodec mpeg4 -b:v 1500k -acodec copy test.ts -y
ffmpeg version N-59362-ge079661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 25 2013 17:42:26 with gcc 4.8.0 (GCC)
  configuration: --arch=x86 --target-os=mingw32 --cross-prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/bin
/i686-w64-mingw32- --pkg-config=pkg-config --enable-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-lib
mp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex --enabl
e-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --disable-w32threads --enable-frei0r
 --enable-filter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflags=-DPTW32_STATIC_LIB --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-
libilbc --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libmodplug --extra-libs=-lstdc++
--enable-libzvbi --enable-libcaca --prefix=/home/mcebuddy/Software/ffmpeg/sandbox/mingw-w64-i686/i686-w64-mingw32 --enab
le-static --disable-shared --enable-libsoxr --enable-fontconfig --enable-libass --enable-libutvideo --enable-libbluray -
-extra-cflags= --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 46.100 / 55. 46.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.102 /  4.  0.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts':
  Duration: 00:01:52.06, start: 1.400000, bitrate: 13152 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:
9], max. 38810 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
[subtitles @ 03491f60] Unable to parse option value "MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugworking0HD Small.
srt" as image size
    Last message repeated 1 times
[subtitles @ 03491f60] Error setting option original_size to value MCEBuddyMCEBuddy 2.xMCEBuddy.ServiceCMDbinx86Debugwor
king0HD Small.srt.
[Parsed_subtitles_0 @ 03491ee0] Error applying options to the filter.
[AVFilterGraph @ 0271e160] Error initializing filter 'subtitles' with args 'D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD
\bin\x86\Debug\working0\HD Small'.srt'
Error opening filters!

comment:5 by ramitb, 11 years ago

I'm reopening the ticket, if the input is working fine and subtitle filter isn't, to me it's obviously broken

comment:6 by ramitb, 11 years ago

Resolution: invalid
Status: closedreopened

comment:7 by ramitb, 11 years ago

Okay taking a comment from another user (@james) below, the issue is that the documentation is incorrect. Each special character needs to be escapted within the quotes and then each escape needs to be reescaped! This is really silly but either way either the documentation needs to be updated or ffmpeg needs to be fixed.

Sorry to invalidate everyone's previous work here but this problem is is
the fault of ffmpeg and libavfilter's escaping hell!

Windows correctly passes your command line to ffmpeg. The problem comes
when ffmpeg tries to parse the filename. ':' separates options
for filters so you need to escape that. '\' (backslash) in the filename
also need to be escaped. ffmpeg's escape character is '\' (backslash).

This means that the filename for the subtitle filter needs to be, with

the quotes:

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

And the full command line:

ffmpeg.exe -i "D:\MCEBuddy\MCEBuddy 2.x\MCEBuddy.ServiceCMD\bin\x86\Debug\working0\HD Small'.ts" -vf subtitles="D\\:\\\\MCEBuddy\\\\MCEBuddy 2.x\\\\MCEBuddy.ServiceCMD\\\\bin\\\\x86\\\\Debug\\\\working0\\\\HD Small\\\'.srt" -vcodec mpeg4 -b 1400k -acodec copy test.ts -y

MAkes me wonder - are there any more characters to be escaped by beyond the three given in the documentation \ and ' (: isn't event mention and needs to be escaped)

comment:8 by Carl Eugen Hoyos, 11 years ago

Resolution: invalid
Status: reopenedclosed

For future questions: Allow more time for developers to answer your questions!

comment:9 by ramitb, 11 years ago

I'm not entirely sure the ticket should be closed just yet. The documentation at best is incomplete, at worst incorrect. There may be scope for code improvement, atleast the documentation needs to be corrected for the above.

Last edited 11 years ago by ramitb (previous) (diff)

in reply to:  9 comment:10 by Stefano Sabatini, 11 years ago

Resolution: invalid
Status: closedreopened

Replying to ramitbhalla:

I'm not entirely sure the ticket should be closed just yet. The documentation at best is incomplete, at worst incorrect. There may be scope for code improvement, atleast the documentation needs to be corrected for the above.

I agree, reopened.

comment:11 by Stefano Sabatini, 11 years ago

Component: undetermineddocumentation
Keywords: escaping hell added

comment:12 by Carl Eugen Hoyos, 11 years ago

Keywords: hell removed
Priority: normalminor
Version: unspecifiedgit-master

comment:13 by Stefano Sabatini, 11 years ago

Resolution: fixed
Status: reopenedclosed

Possibly fixed in:

commit 68c5ba1f052f4d8e4fbff0d78d3c0d6a7a8fa7f1
Author: Stefano Sabatini <stefasab@gmail.com>
Date:   Fri Jan 24 11:31:25 2014 +0100

    doc/filters: re-edit notes on filtergraph escaping
    
    State the escaping rules more explicitly, reword various sentences and
    drop confusing quoting example.
    
    Should fix trac issue #3334.
Note: See TracTickets for help on using tickets.