1

I have this code:

var
  sciezkaDysk : string;
begin
  sciezkaDysk :='/c  ffmpeg.exe MORE_COMMANDS_HERE -f flv "E:\ół test\test.flv"'
  ShellExecute(0, nil, 'cmd.exe', PWideChar(sciezkaDysk), '', SW_HIDE);
end;

Problem is with directory name "ół test", when directory name doesnt contains non english characters all works well. Please help. Thank You.

Arioch 'The
  • 15,799
  • 35
  • 62
  • This [post](http://stackoverflow.com/questions/2951785/how-can-i-convert-a-unicode-path-to-a-c-string) maybe helpful. – Merlin W. Dec 20 '13 at 14:18
  • What are the values of `GetACP()` and `GetOEMCP()` windows functions ? – Arioch 'The Dec 20 '13 at 14:30
  • why do you need to route it through CMD ? try `ShellExecute(0, nil, 'ffmpeg.exe', PWideChar('MORE_COMMANDS_HERE -f flv "E:\ół test\test.flv"'), '', SW_HIDE);` – Arioch 'The Dec 20 '13 at 14:32
  • In Windows console programs (especially those ported from Linux) seldom are Unicode-aware. So i think your best option would be to download DLL, built with Unicode support, and use DLL API directly without spawning extra processes. http://libav.org/documentation.html – Arioch 'The Dec 20 '13 at 14:36
  • GetACP =1250, GetOEMCP = 852. I have Polish OS, but this problems also happens on Russian or Korean OS. "why do you need to route it through CMD ?" cause i also use command like this "-f flv pipe:1 | ffmpeg -i pipe:0" For DLL, maybe in future. I just wanna fix this current problem right now. – user3075132 Dec 20 '13 at 15:38
  • Well, Linux people did never imagined that Windows insanity with two codepages in the same user account, especially westerners who are majority of programmers. These reasons multiply each other and result in utmost fragility of cli-based Linux programs on Windows. You can target it with ad hoc workarounds but that approach alas has its limits – Arioch 'The Dec 21 '13 at 18:30

1 Answers1

4

The problem is not in the Delphi code. Quite possibly your ffmpeg executable uses GetCommandLineA rather than GetCommandLineW to read the command line and the conversion from UTF-16 to ANSI fails.

There are various options but I rather suspect that the easiest will be to specify the working directory for the new process to the directory containing the file. That way ffmpeg does not need to see the troublesome characters – ShellExecuteW deals with them:

ShellExecute(
    0, 
    nil, 
    'ffmpeg.exe', 
    'MORE_COMMANDS_HERE -f flv test.flv', 
    'E:\ół test', 
    SW_HIDE
);

That said, I would suggest that CreateProcess is a better way to start an external process. You get more control that way. You can more cleanly make sure that the console window is not shown.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • "specify the working directory" - and fail when non-Latin characters would be in the filename not only in foldername :-) That assumed that topicstarter does not have ANSI CP <> OEM CP trap. Or that Linux-based ffmpeg does not assume any input in UTF-8... or whatever. – Arioch 'The Dec 20 '13 at 15:06
  • @Arioch'The Yes, if the filename contains non ASCII characters then that would fail. – David Heffernan Dec 20 '13 at 15:07
  • Thank You David Heffernan. Its working now. Filename will be only with english charcaters, just direcory can be changed. – user3075132 Dec 20 '13 at 15:37
  • Great. I think you are all set then! – David Heffernan Dec 20 '13 at 15:38