0

I'm using a pretty simple ffmpeg batch script, but it can't convert videos with single quotes in their titles. If the title is Boogiepop Phantom - 1x11 - Under The Gravity's Rainbow for example, I'll get the error [Parsed_subtitles_0 @ 000000670ea89ec0] Unable to open Boogiepop Phantom - 1x11 - Under The Gravitys Rainbow.mkv Note the removed single quote.

I know ^ is the escape character, but the single quote is in a different spot every time. Do I need regex or is there a simpler way?

for %%a in ("*.mkv") do ^
ffmpeg -i "%%a" ^
-vf subtitles="%%a" ^
"NEW\%%~na.mkv"
pause
unident77
  • 35
  • 4
  • @Shep That's what I've been doing but it's tedious. – unident77 Dec 21 '15 at 04:42
  • 1
    Can you open the file outside of the batch script? This post suggests your single quotes should be ok. http://stackoverflow.com/questions/24173825/what-does-single-quote-do-in-windows-batch-files – Shep Dec 21 '15 at 04:45
  • Any particular reason you're using `^` to split the command onto multiple lines instead of having it all on one line? – SomethingDark Dec 21 '15 at 04:48
  • Also, read this: http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace – SomethingDark Dec 21 '15 at 04:52
  • @Shep I can. Strange. So `%%a` is the title with single quotes removed for some reason. – unident77 Dec 21 '15 at 04:55
  • @SomethingDark Readability mainly. Okay I'll play w/ that. – unident77 Dec 21 '15 at 04:58
  • Perhaps this is caused by `ffmpeg` when it parses its arguments... anyway, put your `for` loop in a single line or use parentheses like `do (...)` rather than the `^` to see if the used multi-syntax is the cause of the problems... – aschipfl Dec 21 '15 at 05:01
  • Use `%%~a` rather than `%%a` within the loop body... – aschipfl Dec 21 '15 at 05:56

2 Answers2

0
for %%a in ("*.mkv") do (
ffmpeg -i "%%a" -vf subtitles="%%a" "NEW\%%~na.mkv"
)

worked fine for me with target filenames containing single-quotes

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Giving me the same error. Are you using Windows 10 and ffmpeg git-2dba040? – unident77 Dec 21 '15 at 05:26
  • No - win7 and ffmpeg 2.1 What happens if you enter the ffmpeg line at the prompt with `%%a` replaced verbatim by your filename? I received (for an empty source file) `Boogiepop Phantom - 1x11 - Under The Gravity's Rainbow.mkv: Invalid data found when processing input` (verbatim screen paste) - which seemed reasonable. – Magoo Dec 21 '15 at 05:32
  • 1
    You could use always `%%~a`, so you get `ffmpeg -i "%%~a" -vf subtitles="%%~a" "NEW\%%~na.mkv" – jeb Dec 21 '15 at 08:29
0
char converted[1000]="";

strcpy(converted,subsname);

while (replace_str(converted,"\'","[single_quote]"));

while (replace_str(converted,"[single_quote]","\\'\\'\\\\'"));

sprintf(q_subs, "\"f='%s'\"",converted);

fprintf(file,"ffmpeg.exe -hide_banner -i %s -i %s -map 0:v:0 -map 1:a:0 -strict -2 -vf subtitles=%s -c:s mov_text -c:v libx264 -preset veryfast -crf 23 -c:a aac -b:a 96k -pix_fmt yuv420p %s", q_video,q_audio,q_subs,outputfile);

int replace_str(char *str, char *orig, char *rep)
{
    char buffer[10000];
    char *p;
    if(!(p = strstr(str, orig)))  // Is 'orig' even in 'str'?
        return false;
    strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$
    buffer[p-str] = '\0';
    sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));
    strcpy(str,buffer);
    return true;
}

Result:

ffmpeg.exe -hide_banner -i "'Impossible' Pulsar Breaks the Rules _ Space News-GrW_xcHUUmU.f135.mp4" -i "'Impossible' Pulsar Breaks the Rules _ Space News-GrW_xcHUUmU.f140.m4a" -map 0:v:0 -map 1:a:0 -strict -2 -vf subtitles="f='\'\'\'Impossible\'\'\' Pulsar Breaks the Rules _ Space News-GrW_xcHUUmU.nl.vtt'" -c:s mov_text -c:v libx264 -preset veryfast -crf 23 -c:a aac -b:a 96k -pix_fmt yuv420p "out/'Impossible' Pulsar Breaks the Rules _ Space News-GrW_xcHUUmU.nl.mp4"

Ok? Maybe this helps programmers and constructing the subtile filename for single quotes....

;)

  • https://www.facebook.com/Pacman-Graphics-1601114056700700/ https://github.com/crazybytes/DOWNLOAD_AND_BURN https://drive.google.com/open?id=1fwHMqZoyORXqekGW0kebdZaThsK4PjJe https://stackoverflow.com/questions/34389027/automate-single-quote-escape-in-batch-file/55802390#55802390 –  Apr 23 '19 at 01:04