delphi - CreateProcess : escape spaces in the application path -


we need execute ffmpeg in command window in delphi application.

we found solution protect path function "extractshortpathname".

but on computers can't 8.3 path (hklm\system\currentcontrolset\control\filesystem\ntfsdisable8dot3namecreation 2) , want find way escape spaces.

here code :

sparameters := '"c:\users\[...]\input.wav" -r 12.03 -f image2 -i "c:\users\[...]\delphilm%d.png" -vf "scale=1024:704" -ab 96k -r 24 -b 2000k  -pass 1 -vcodec libx264 -fpre "c:\[...]\libx264-normal.ffpreset" "c:\users\[...]\export.mp4"'; scommand := 'c:\program files\my application\utils\bin\ffmpeg.exe'; handle := createprocess(nil, pchar('cmd.exe /c '+protectpath(scommand)+' '+sparameters),nil, nil, true, 0, nil, nil, si, pi); 

with protectpath function :

function protectpath(scommand:widestring):widestring; begin   result := scommand;   // 8.3 path   result := extractshortpathname(scommand);   // if 8.3 path not accessible   if(pos(' ', result)>0)then begin     //result := '"'+scommand+'"';    --> not work     //result := strreplace(scommand, ' ','" "');  --> not work     //result := strreplace(scommand, ' ','^ ');  --> not work     //result := strreplace(scommand, ' ','\ ');  --> not work     //result := strreplace(scommand, ' ','\\ ');   --> not work     //result := strreplace(scommand, ' ','/ ');  --> not work     //result := strreplace(scommand, ' ','// ');  --> not work   end; end; 

any ideas ?

you not need retrieve 8.3 filename. have wrap long path single pair of quotation marks if contains space characters in (like doing of ffmpeg parameters). then, rid of cmd.exe altogether , call ffmpeg.exe directly instead.

scommand := '"c:\program files\my application\utils\bin\ffmpeg.exe"';  sparameters := '"c:\users\[...]\input.wav" -r 12.03 -f image2 -i "c:\users\[...]\delphilm%d.png" -vf "scale=1024:704" -ab 96k -r 24 -b 2000k  -pass 1 -vcodec libx264 -fpre "c:\[...]\libx264-normal.ffpreset" "c:\users\[...]\export.mp4"';  handle := createprocess(nil, pchar(scommand + ' ' + sparameters), nil, nil, true, 0, nil, nil, si, pi); 

if want quoting dynamically, use (ansi)quotedstr() that, eg:

function protectparam(sparam: string): string; begin   if lastdelimiter(' "', sparam) <> 0     result := quotedstr(sparam)   else     result := sparam; end; 

ffmpeg := 'c:\program files\my application\utils\bin\ffmpeg.exe'; inputfile := 'c:\users\[...]\input.wav'; pngfile := 'c:\users\[...]\delphilm%d.png'; presetfile := 'c:\[...]\libx264-normal.ffpreset'; exportfile := 'c:\users\[...]\export.mp4';  scommand := protectparam(ffmpeg) + ' ' + protectparam(inputfile) + ' -r 12.03 -f image2 -i ' + protectparam(pngfile) + ' -vf "scale=1024:704" -ab 96k -r 24 -b 2000k  -pass 1 -vcodec libx264 -fpre ' + protectparam(presetfile) + ' ' + protectparam(exportfile);  handle := createprocess(nil, pchar(scommand), nil, nil, true, 0, nil, nil, si, pi); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -