Log in

View Full Version : [Delphi7] Unable to correctly capture x264 output after r2345


Atak_Snajpera
1st March 2014, 19:41
My current capturing code worked well until r2345. Everything above does not work.

Output from my ultra simple example
http://i.cubeupload.com/Kqo2eD.png

code in pastebin -> http://pastebin.com/Ez6QsPbZ

Delphi 7 source code -> https://mega.co.nz/#!FM8XzZ7b!W2ikQw_wxXkS5RK7mWO5o0OdZJT8210GzqZDtWc5pUk

I'm guessing that my issue must be related with this change
Henrik Gramner [Sun, 11 Aug 2013 19:50:42 +0200 (19:50 +0200)]
Windows Unicode support

Windows, unlike most other operating systems, uses UTF-16 for Unicode strings while x264 is designed for UTF-8.

This patch does the following in order to handle things like Unicode filenames:
* Keep strings internally as UTF-8.
* Retrieve the CLI command line as UTF-16 and convert it to UTF-8.
* Always use Unicode versions of Windows API functions and convert strings to UTF-16 when calling them.
* Attempt to use legacy 8.3 short filenames for external libraries without Unicode support.

Groucho2004
1st March 2014, 20:19
My current capturing code worked well until r2345. Everything above does not work.

Output from my ultra simple example
http://i.cubeupload.com/Kqo2eD.png

code in pastebin -> http://pastebin.com/Ez6QsPbZ

Delphi 7 source code -> https://mega.co.nz/#!FM8XzZ7b!W2ikQw_wxXkS5RK7mWO5o0OdZJT8210GzqZDtWc5pUk

I'm guessing that my issue must be related with this change
Henrik Gramner [Sun, 11 Aug 2013 19:50:42 +0200 (19:50 +0200)]
Windows Unicode support

Windows, unlike most other operating systems, uses UTF-16 for Unicode strings while x264 is designed for UTF-8.

This patch does the following in order to handle things like Unicode filenames:
* Keep strings internally as UTF-8.
* Retrieve the CLI command line as UTF-16 and convert it to UTF-8.
* Always use Unicode versions of Windows API functions and convert strings to UTF-16 when calling them.
* Attempt to use legacy 8.3 short filenames for external libraries without Unicode support.
Just a wild guess - Try changing the value in this line:
newLinePos:=Pos(#13, text);
#10 might work. I had a similar problem with Unicode and line breaks, I'll have to dig through some old code.

LoRd_MuldeR
1st March 2014, 20:36
As the commit message says, x264 supports Unicode on the Windows platform since r2345, finally!

This means it will now use Unicode, or more specifically UTF-8, all the way. At the same time, Delphi 7 doesn't support Unicode at all - at least as far as its built-in String type, all its string functions and its GUI widgets are concerned!

If you really which to stick with Delphi 7, I guess the best you can do is using MultiByteToWideChar(...) to convert x264's output from UTF-8 to UTF-16 and then further to the local ANSI code-page via WideCharToMultiByte(CP_ACP , ...).

Unnecessary to say that the last step, i.e. converting the UTF-16 chars to ANSI, will throw away all Unicode characters that cannot be represented in the user's local ANSI code-page - whatever that code-page may happen to be :rolleyes:

___

BTW: You should change you code like this:
if CreatePipe(readPipe, writePipe, @security, 0) then
begin
if not DuplicateHandle(GetCurrentProcess, writePipe, GetCurrentProcess, @errorPipe, 0, True, DUPLICATE_SAME_ACCESS) then
begin
//Error handling
end;

// Create a NON-inheritable duplicate of the "read" handle
if not DuplicateHandle(GetCurrentProcess, readPipe, GetCurrentProcess, @readPipeDup, 0, False, DUPLICATE_SAME_ACCESS) then
begin
//Error handling
end;

// Close inheritable "read" handle, so the new process won't inherit it!
CloseHandle(readPipe);

ZeroMemory(@info, sizeof(info));
with info do
begin
cb := sizeof( info );
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := 0;
hStdOutput := writePipe;
hStdError := errorPipe;
end;

// .......

end;

Atak_Snajpera
2nd March 2014, 15:19
With latest x264 no matter what would I do something is wrong. With my original #13 it seems to work but the main problem is that ENCODED ..... string at the end is not captured. My encoding server thinks that encoding was aborted.
See this -> https://mega.co.nz/#!lV8hwb6A!8nlwCFRI6kypheIFbSbhFhpUhT4D7itgcypEvCWSB6o

And as extra #10 vs #13 in my simple example
https://mega.co.nz/#!hAdzVQKZ!5OphDLoCKZsghLxYSiotFiV58pFZ0yjQf6NvgnOogzw
https://mega.co.nz/#!cJ90QSSQ!aeGL45uK6XIlv9cluVcLX3LgmX7qAGMytCljZYKYUv8

In second example encoded .... text does not appear.

MasterNobody
3rd March 2014, 18:10
Atak_Snajpera
As was already mentioned you should correctly parse both #13#10 and #10 line breaks in your code. With this modification (http://privatepaste.com/049bfc32f4) of your ExecuteConsole function you should get all strings from x264 output.

Atak_Snajpera
4th March 2014, 18:10
Thank you very much MasterNobody! Your improved version works like a charm :)