Skip to content

Commit 42fb320

Browse files
joshstaigerlisamelton
authored andcommitted
Buffer characters that seem to be part of a multibyte UTF-8 sequence when copying output from HandBrakeCLI to the console or .log file to avoid a crash on Windows.
1 parent f9a5feb commit 42fb320

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

bin/transcode-video

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,27 @@ HERE
13911391
Process.kill 'INT', io.pid
13921392
end
13931393

1394+
buf = ""
13941395
io.each_char do |char|
1395-
print char
1396+
# Printing a single UTF-8 continuation byte to the Console
1397+
# on Windows causes a crash, therefore we buffer characters
1398+
# as long as they seem to be part of a multi-byte UTF-8 sequence
1399+
1400+
if (char.bytes[0] & 0x80) != 0
1401+
buf << char
1402+
else
1403+
if not buf.empty?
1404+
print buf
1405+
buf = ""
1406+
end
1407+
print char
1408+
end
13961409
log_file.print char unless log_file.nil?
13971410
end
1411+
1412+
if not buf.empty?
1413+
print buf
1414+
end
13981415
end
13991416
rescue SystemCallError => e
14001417
raise "transcoding failed: #{e}"

0 commit comments

Comments
 (0)