【发布时间】:2014-03-10 16:40:33
【问题描述】:
我们需要在我的 delphi 应用程序的命令窗口中执行 ffmpeg。
我们找到了使用“ExtractShortPathName”函数保护路径的解决方案。
但在某些计算机上我们无法获得 8.3 路径(HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation 为 2),我们想找到另一种方法来逃避空格。
代码如下:
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);
使用 ProtectPath 功能:
function ProtectPath(sCommand:Widestring):Widestring;
begin
Result := sCommand;
// get the 8.3 path
Result := ExtractShortPathName(sCommand);
// if 8.3 path is not accessible
if(Pos(' ', Result)>0)then begin
//Result := '"'+sCommand+'"'; --> do not work
//Result := StrReplace(sCommand, ' ','" "'); --> do not work
//Result := StrReplace(sCommand, ' ','^ '); --> do not work
//Result := StrReplace(sCommand, ' ','\ '); --> do not work
//Result := StrReplace(sCommand, ' ','\\ '); --> do not work
//Result := StrReplace(sCommand, ' ','/ '); --> do not work
//Result := StrReplace(sCommand, ' ','// '); --> do not work
end;
end;
有什么想法吗?
【问题讨论】:
-
用正斜杠替换反斜杠。我通常在 C++ 中使用它。仅适用于路径。没有其他的。希望它在这里工作。
-
OT:我仍然想知道为什么人们倾向于使用
cmd.exe /C。直接执行应用程序不是更容易吗? -
正斜杠不起作用。
-
我们使用cmd.exe来分析ffmpeg过程中的输出。
-
msdn.microsoft.com/en-us/library/windows/desktop/… cmets 部分指出,如果文件没有短名称,它将失败。好像有不少
gotchas在使用这个功能。某些系统没有某些路径的短名称。
标签: delphi createprocess