2 ----------------------------------------------------------------------------------------------------------------------
3 ----------------------------------------------------------------------------------------------------------------------
4 -- NHMLFixup v9 by Ilari (2011-04-01).
5 -- Update timecodes in NHML Audio/Video track timing to conform to given MKV v2 timecodes file.
6 -- Syntax: NHMLFixup <video-nhml-file> <audio-nhml-file> <mkv-timecodes-file> [delay=<delay>] [tvaspect|widescreen]
7 -- <delay> is number of milliseconds to delay the video (in order to compensate for audio codec delay, reportedly
8 -- does not work right with some demuxers).
9 -- The 'tvaspect' option makes video track to be automatically adjusted to '4:3' aspect ratio.
10 -- The 'widescreen' option makes video track to be automatically adjusted to '16:9' aspect ratio.
12 -- Version v9 by Ilari (2011-04-01):
13 -- - Support widescreen mode ("widescreen").
15 -- Version v8 by Ilari (2010-12-06):
16 -- - Support Special timecode file "@CFR" that fixes up audio for CFR encode.
18 -- Version v7 by Ilari (2010-10-24):
19 -- - Fix bug in time division (use integer timestamps, not decimal ones).
21 -- Version v6 by Ilari (2010-10-24):
22 -- - Make it work on Lua 5.2 (work 4).
24 -- Version v5 by Ilari (2010-09-18):
25 -- - Move the files first out of way, since rename-over fails on Windows.
27 -- Version v4 by Ilari (2010-09-17):
28 -- - Change audio track ID if it collides with video track..
30 -- Version v3 by Ilari (2010-09-17):
31 -- - Support setting aspect ratio correction.
33 -- Version v2 by Ilari (2010-09-16):
34 -- - If sound and video NHMLs are wrong way around, automatically swap them.
35 -- - Check that one of the NHMLs is sound and other is video.
37 ----------------------------------------------------------------------------------------------------------------------
38 ----------------------------------------------------------------------------------------------------------------------
41 unpack
= unpack
or table.unpack
;
43 ----------------------------------------------------------------------------------------------------------------------
44 -- Function reduce_fraction(number numerator, number denumerator)
45 -- Returns reduced fraction.
46 ----------------------------------------------------------------------------------------------------------------------
47 reduce_fraction
= function(numerator
, denumerator
)
48 local x
, y
= numerator
, denumerator
;
52 return numerator
/ x
, denumerator
/ x
;
55 ----------------------------------------------------------------------------------------------------------------------
56 -- Function load_timecode_file(FILE file, number timescale)
57 -- Loads timecode data from file @file, using timescale of @timescale frames per second. Returns array of scaled
59 ----------------------------------------------------------------------------------------------------------------------
60 load_timecode_file
= function(file
, timescale
)
62 line
= file
:read("*l");
63 if line
~= "# timecode format v2" then
64 error("Timecode file is not in MKV timecodes v2 format");
68 line
= file
:read("*l");
72 local timecode
= tonumber(line
);
74 error("Can't parse timecode '" .. line
.. "'.");
76 table.insert(ret
, math
.floor(0.5 + timecode
/ 1000 * timescale
));
81 ----------------------------------------------------------------------------------------------------------------------
82 -- Function make_reverse_index_table(Array array)
83 -- Returns table, that has entry for each entry in given array @array with value being rank of value, 1 being smallest
84 -- and #array the largest. If @lookup is non-nil, values are looked up from that array.
85 ----------------------------------------------------------------------------------------------------------------------
86 make_reverse_index_table
= function(array
, lookup
)
96 ret
[sorted
[i]]
= (lookup
and lookup
[i
]) or i
;
101 ----------------------------------------------------------------------------------------------------------------------
102 -- Function max_causality_violaton(Array CTS, Array DTS)
103 -- Return the maximum number of time units CTS and DTS values violate causality. #CTS must equal #DTS.
104 ----------------------------------------------------------------------------------------------------------------------
105 max_causality_violation
= function(CTS
, DTS
)
109 max_cv
= math
.max(max_cv
, DTS
[i
] - CTS
[i
]);
114 ----------------------------------------------------------------------------------------------------------------------
115 -- Function fixup_video_times(Array sampledata, Array timecodes, Number spec_delay)
116 -- Fixes video timing of @sampledata (fields CTS and DTS) to be consistent with timecodes in @timecodes. Returns the
117 -- CTS offset of first sample (for fixing audio). @spec_delay is special delay to add (to fix A/V sync).
118 ----------------------------------------------------------------------------------------------------------------------
119 fixup_video_times
= function(sampledata
, timecodes
, spec_delay
)
124 if not timecodes
then
125 local min_cts
= 999999999999999999999;
126 for i
= 1,#sampledata
do
127 --Maximum causality violation is always zero in valid HHML.
128 sampledata
[i
].CTS
= sampledata
[i
].CTS
+ spec_delay
;
129 --Spec_delay should not apply to audio.
130 min_cts
= math
.min(min_cts
, sampledata
[i
].CTS
- spec_delay
);
135 if #sampledata
~= #timecodes
then
136 error("Number of samples (" .. #sampledata
.. ") does not match number of timecodes (" .. #timecodes
139 for i
= 1,#sampledata
do
140 cts_tab
[i
] = sampledata
[i
].CTS
;
141 dts_tab
[i
] = sampledata
[i
].DTS
;
143 cts_lookup
= make_reverse_index_table(cts_tab
, timecodes
);
144 dts_lookup
= make_reverse_index_table(dts_tab
, timecodes
);
146 -- Perform time translation and find max causality violation.
148 for i
= 1,#sampledata
do
149 sampledata
[i
].CTS
= cts_lookup
[sampledata
[i
].CTS
];
150 sampledata
[i
].DTS
= dts_lookup
[sampledata
[i
].DTS
];
151 max_cv
= math
.max(max_cv
, sampledata
[i
].DTS
- sampledata
[i
].CTS
);
153 -- Add maximum causality violation to CTS to eliminate the causality violations.
154 -- Also find the minimum CTS.
155 local min_cts
= 999999999999999999999;
156 for i
= 1,#sampledata
do
157 sampledata
[i
].CTS
= sampledata
[i
].CTS
+ max_cv
+ spec_delay
;
158 --Spec_delay should not apply to audio.
159 min_cts
= math
.min(min_cts
, sampledata
[i
].CTS
- spec_delay
);
164 ----------------------------------------------------------------------------------------------------------------------
165 -- Function fixup_video_times(Array sampledata, Number min_video_cts, Number video_timescale, Number audio_timescale)
166 -- Fixes video timing of @sampledata (field CTS) to be consistent with video minimum CTS of @cts. Video timescale
167 -- is assumed to be @video_timescale and audio timescale @audio_timescale.
168 ----------------------------------------------------------------------------------------------------------------------
169 fixup_audio_times
= function(sampledata
, min_video_cts
, video_timescale
, audio_timescale
)
170 local fixup
= math
.floor(0.5 + min_video_cts
* audio_timescale
/ video_timescale
);
171 for i
= 1,#sampledata
do
172 sampledata
[i
].CTS
= sampledata
[i
].CTS
+ fixup
;
176 ----------------------------------------------------------------------------------------------------------------------
177 -- Function translate_NHML_TS_in(Array sampledata);
178 -- Translate NHML CTSOffset fields in @sampledata into CTS fields.
179 ----------------------------------------------------------------------------------------------------------------------
180 translate_NHML_TS_in
= function(sampledata
, default_dDTS
)
183 for i
= 1,#sampledata
do
184 if not sampledata
[i
].DTS
then
185 sampledata
[i
].DTS
= dts
+ default_dDTS
;
187 dts
= sampledata
[i
].DTS
;
188 if sampledata
[i
].CTSOffset
then
189 sampledata
[i
].CTS
= sampledata
[i
].CTSOffset
+ sampledata
[i
].DTS
;
191 sampledata
[i
].CTS
= sampledata
[i
].DTS
;
196 ----------------------------------------------------------------------------------------------------------------------
197 -- Function translate_NHML_TS_out(Array sampledata);
198 -- Translate CTS fields in @sampledata into NHML CTSOffset fields.
199 ----------------------------------------------------------------------------------------------------------------------
200 translate_NHML_TS_out
= function(sampledata
)
202 for i
= 1,#sampledata
do
203 sampledata
[i
].CTSOffset
= sampledata
[i
].CTS
- sampledata
[i
].DTS
;
204 if sampledata
[i
].CTSOffset
< 0 then
205 error("INTERNAL ERROR: translate_NHML_TS_out: Causality violation: CTS=" .. tostring(
206 sampledata
[i
].CTS
) .. " DTS=" .. tostring(sampledata
[i
].DTS
) .. ".");
208 sampledata
[i
].CTS
= nil;
212 ----------------------------------------------------------------------------------------------------------------------
213 -- Function map_table_to_number(Table tab);
214 -- Translate all numeric fields in table @tab into numbers.
215 ----------------------------------------------------------------------------------------------------------------------
216 map_table_to_number
= function(tab
)
218 for k
, v
in pairs(tab
) do
219 local n
= tonumber(v
);
226 ----------------------------------------------------------------------------------------------------------------------
227 -- Function map_fields_to_number(Array sampledata);
228 -- Translate all numeric fields in array @sampledata into numbers.
229 ----------------------------------------------------------------------------------------------------------------------
230 map_fields_to_number
= function(sampledata
)
232 for i
= 1,#sampledata
do
233 map_table_to_number(sampledata
[i
]);
237 ----------------------------------------------------------------------------------------------------------------------
238 -- Function escape_xml_text(String str)
239 -- Return XML escaping of text str.
240 ----------------------------------------------------------------------------------------------------------------------
241 escape_xml_text
= function(str
)
242 str
= string.gsub(str
, "&", "&");
243 str
= string.gsub(str
, "<", "<");
244 str
= string.gsub(str
, ">", ">");
245 str
= string.gsub(str
, "\"", """);
246 str
= string.gsub(str
, "\'", "'");
250 ----------------------------------------------------------------------------------------------------------------------
251 -- Function escape_xml_text(String str)
252 -- Return XML unescaping of text str.
253 ----------------------------------------------------------------------------------------------------------------------
254 unescape_xml_text
= function(str
)
255 str
= string.gsub(str
, "'", "\'");
256 str
= string.gsub(str
, """, "\"");
257 str
= string.gsub(str
, ">", ">");
258 str
= string.gsub(str
, "<", "<");
259 str
= string.gsub(str
, "&", "&");
263 ----------------------------------------------------------------------------------------------------------------------
264 -- Function serialize_table_to_xml_entity(File file, String tag, Table data, bool noclose);
265 -- Write @data as XML start tag of type @tag into @file. If noclose is true, then tag will not be closed.
266 ----------------------------------------------------------------------------------------------------------------------
267 serialize_table_to_xml_entity
= function(file
, tag, data
, noclose
)
269 file
:write("<" .. tag .. " ");
270 for k
, v
in pairs(data
) do
271 file
:write(k
.. "=\"" .. escape_xml_text(tostring(v
)) .. "\" ");
280 ----------------------------------------------------------------------------------------------------------------------
281 -- Function serialize_array_to_xml_entity(File file, String tag, Array data);
282 -- Write each element of @data as empty XML tag of type @tag into @file.
283 ----------------------------------------------------------------------------------------------------------------------
284 serialize_array_to_xml_entity
= function(file
, tag, data
)
287 serialize_table_to_xml_entity(file
, tag, data
[i
]);
291 ----------------------------------------------------------------------------------------------------------------------
292 -- Function write_NHML_data(File file, Table header, Table sampledata)
293 -- Write entiere NHML file.
294 ----------------------------------------------------------------------------------------------------------------------
295 write_NHML_data
= function(file
, header
, sampledata
)
296 file
:write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
297 serialize_table_to_xml_entity(file
, "NHNTStream", header
, true);
298 serialize_array_to_xml_entity(file
, "NHNTSample", sampledata
);
299 file
:write("</NHNTStream>\n");
302 ----------------------------------------------------------------------------------------------------------------------
303 -- Function open_file_checked(String file, String mode, bool for_write)
304 -- Return file handle to file (checking that open succeeds).
305 ----------------------------------------------------------------------------------------------------------------------
306 open_file_checked
= function(file
, mode
, for_write
)
308 a
, b
= io
.open(file
, mode
);
310 error("Can't open '" .. file
.. "': " .. b
);
315 ----------------------------------------------------------------------------------------------------------------------
316 -- Function call_with_file(fun, string file, String mode, ...);
317 -- Call fun with opened file handle to @file (in mode @mode) as first parameter.
318 ----------------------------------------------------------------------------------------------------------------------
319 call_with_file
= function(fun
, file
, mode
, ...)
320 -- FIXME: Handle nils returned from function.
321 local handle
= open_file_checked(file
, mode
);
322 local ret
= {fun(handle
, ...)};
327 ----------------------------------------------------------------------------------------------------------------------
328 -- Function xml_parse_tag(String line);
329 -- Returns the xml tag type for @line plus table of attributes.
330 ----------------------------------------------------------------------------------------------------------------------
331 xml_parse_tag
= function(line
)
335 tagname
= string.match(line
, "<(%S+).*>");
337 error("'" .. line
.. "': Parse error.");
340 for k
, v
in string.gmatch(line
, "([^ =]+)=\"([^\"]*)\"") do
341 attr
[k
] = unescape_xml_text(v
);
343 return tagname
, attr
;
346 ----------------------------------------------------------------------------------------------------------------------
347 -- Function load_NHML(File file)
348 -- Loads NHML file @file. Returns header table and samples array.
349 ----------------------------------------------------------------------------------------------------------------------
350 load_NHML
= function(file
)
351 -- Let's regexp this shit...
355 local line
= file
:read();
357 error("Unexpected end of NHML file.");
359 local xtag
, attributes
;
360 xtag
, attributes
= xml_parse_tag(line
);
361 if xtag
== "NHNTStream" then
363 elseif xtag
== "NHNTSample" then
364 table.insert(samples
, attributes
);
365 elseif xtag
== "/NHNTStream" then
367 elseif xtag
== "?xml" then
369 print("WARNING: Unrecognized tag '" .. xtag
.. "'.");
372 return header
, samples
;
375 ----------------------------------------------------------------------------------------------------------------------
376 -- Function reame_errcheck(String old, String new)
377 -- Rename old to new. With error checking.
378 ----------------------------------------------------------------------------------------------------------------------
379 rename_errcheck
= function(old
, new
, backup
)
382 a
, b
= os
.rename(new
, backup
);
384 error("Can't rename '" .. new
.. "' -> '" .. backup
.. "': " .. b
);
386 a
, b
= os
.rename(old
, new
);
388 error("Can't rename '" .. old
.. "' -> '" .. new
.. "': " .. b
);
392 ----------------------------------------------------------------------------------------------------------------------
393 -- Function compute_max_div(Integer ctsBound, Integer timescale, Integer maxCode, pictureOffset)
394 -- Compute maximum allowable timescale.
395 ----------------------------------------------------------------------------------------------------------------------
396 compute_max_div
= function(ctsBound
, timeScale
, maxCode
, pictureOffset
)
397 -- Compute the logical number of frames.
398 local logicalFrames
= ctsBound
/ pictureOffset
;
399 local maxNumerator
= math
.floor(maxCode
/ logicalFrames
);
400 -- Be conservative and assume numerator is rounded up. That is, solve the biggest maxdiv such that for all
401 -- 1 <= x <= maxdiv, maxNumerator >= ceil(x * pictureOffset / timeScale) is true.
402 -- Since maxNumerator is integer, this is equivalent to:
403 -- maxNumerator >= x * pictureOffset / timeScale
404 -- => maxNumerator * timeScale / pictureOffset >= x, thus
405 -- maxDiv = math.floor(maxNumerator * timeScale / pictureOffset);
406 return math
.floor(maxNumerator
* timeScale
/ pictureOffset
);
409 ----------------------------------------------------------------------------------------------------------------------
410 -- Function rational_approximate(Integer origNum, Integer origDenum, Integer maxDenum)
411 -- Approximate origNum / origDenum using rational with maximum denumerator of maxDenum
412 ----------------------------------------------------------------------------------------------------------------------
413 rational_approximate
= function(origNum
, origDenum
, maxDenum
)
414 -- FIXME: Better approximations are possible.
415 local div
= math
.ceil(origDenum
/ maxDenum
);
416 return math
.floor(0.5 + origNum
/ div
), math
.floor(0.5 + origDenum
/ div
);
419 ----------------------------------------------------------------------------------------------------------------------
420 -- Function fixup_mp4box_bug_cfr(Table header, Table samples, Integer pictureOffset, Integer maxdiv)
421 -- Fix MP4Box timecode bug for CFR video by approximating the framerate a bit.
422 ----------------------------------------------------------------------------------------------------------------------
423 fixup_mp4box_bug_cfr
= function(header
, samples
, pictureOffset
, maxdiv
)
427 oNum
, oDenum
= pictureOffset
, header
.timeScale
;
428 nNum
, nDenum
= rational_approximate(oNum
, oDenum
, maxdiv
);
429 header
.timeScale
= nDenum
;
430 for i
= 1, #samples
do
431 samples
[i
].DTS
= math
.floor(0.5 + samples
[i
].DTS
/ oNum
* nNum
);
432 samples
[i
].CTS
= math
.floor(0.5 + samples
[i
].CTS
/ oNum
* nNum
);
438 error("Syntax: NHMLFixup.lua <video.nhml> <audio.nhml> <timecodes.txt> [delay=<delay>] [tvaspect|widescreen]");
441 -- Load the NHML files.
442 io
.stdout
:write("Loading '" .. arg
[1] .. "'..."); io
.stdout
:flush();
443 video_header
, video_samples
= call_with_file(load_NHML
, arg
[1], "r");
444 io
.stdout
:write("Done.\n");
445 io
.stdout
:write("Loading '" .. arg
[2] .. "'..."); io
.stdout
:flush();
446 audio_header
, audio_samples
= call_with_file(load_NHML
, arg
[2], "r");
447 io
.stdout
:write("Done.\n");
448 io
.stdout
:write("String to number conversion on video header..."); io
.stdout
:flush();
449 map_table_to_number(video_header
);
450 io
.stdout
:write("Done.\n");
451 io
.stdout
:write("String to number conversion on video samples..."); io
.stdout
:flush();
452 map_fields_to_number(video_samples
);
453 io
.stdout
:write("Done.\n");
454 io
.stdout
:write("String to number conversion on audio header..."); io
.stdout
:flush();
455 map_table_to_number(audio_header
);
456 io
.stdout
:write("Done.\n");
457 io
.stdout
:write("String to number conversion on audio samples..."); io
.stdout
:flush();
458 map_fields_to_number(audio_samples
);
459 io
.stdout
:write("Done.\n");
460 if video_header
.streamType
== 4 and audio_header
.streamType
== 5 then
462 elseif video_header
.streamType
== 5 and audio_header
.streamType
== 4 then
463 print("WARNING: You got audio and video wrong way around. Swapping them for you...");
464 audio_header
,audio_samples
,arg
[2],video_header
,video_samples
,arg
[1] =
465 video_header
,video_samples
,arg
[1],audio_header
,audio_samples
,arg
[2];
467 error("Expected one video track and one audio track");
470 if video_header
.trackID
== audio_header
.trackID
then
471 print("WARNING: Audio and video have the same track id. Assigning new track id to audio track...");
472 audio_header
.trackID
= audio_header
.trackID
+ 1;
475 io
.stdout
:write("Computing CTS for video samples..."); io
.stdout
:flush();
476 translate_NHML_TS_in(video_samples
, video_header
.DTS_increment
or 0);
477 io
.stdout
:write("Done.\n");
478 io
.stdout
:write("Computing CTS for audio samples..."); io
.stdout
:flush();
479 translate_NHML_TS_in(audio_samples
, audio_header
.DTS_increment
or 0);
480 io
.stdout
:write("Done.\n");
482 -- Alter timescale if needed and load the timecode data.
486 if arg
[i
] == "tvaspect" then
488 elseif arg
[i
] == "widescreen" then
490 elseif string.sub(arg
[i
], 1, 6) == "delay=" then
491 local n
= tonumber(string.sub(arg
[i
], 7, #(arg
[i
])));
496 delay
= math
.floor(0.5 + rdelay
/ 1000 * video_header
.timeScale
);
501 MAX_MP4BOX_TIMECODE
= 0x7FFFFFF;
502 if arg
[3] ~= "@CFR" then
503 timecode_data
= call_with_file(load_timecode_file
, arg
[3], "r", video_header
.timeScale
);
504 if timecode_data
[#timecode_data
] > MAX_MP4BOX_TIMECODE
then
505 -- Workaround MP4Box bug.
506 divider
= math
.ceil(timecode_data
[#timecode_data
] / MAX_MP4BOX_TIMECODE
);
507 print("Notice: Dividing timecodes by " .. divider
.. " to workaround MP4Box timecode bug.");
508 io
.stdout
:write("Performing division..."); io
.stdout
:flush();
509 video_header
.timeScale
= math
.floor(0.5 + video_header
.timeScale
/ divider
);
510 for i
= 1,#timecode_data
do
511 timecode_data
[i
] = math
.floor(0.5 + timecode_data
[i
] / divider
);
514 delay
= math
.floor(0.5 + rdelay
/ 1000 * video_header
.timeScale
);
515 io
.stdout
:write("Done.\n");
521 local DTSOffset
= (video_samples
[2] or video_samples
[1]).DTS
- video_samples
[1].DTS
;
522 if DTSOffset
== 0 then
525 for i
= 1,#video_samples
do
526 if video_samples
[i
].CTS
> maxCTS
then
527 maxCTS
= video_samples
[i
].CTS
;
529 if video_samples
[i
].DTS
% DTSOffset
~= 0 then
530 error("Video is not CFR");
532 if (video_samples
[i
].CTS
- video_samples
[1].CTS
) % DTSOffset
~= 0 then
533 error("Video is not CFR");
536 if video_samples
[#video_samples
].CTS
> MAX_MP4BOX_TIMECODE
then
537 --Workaround MP4Box bug.
538 local maxdiv
= compute_max_div(maxCTS
, video_header
.timeScale
, MAX_MP4BOX_TIMECODE
, DTSOffset
);
539 print("Notice: Restricting denumerator to " .. maxdiv
.. " to workaround MP4Box timecode bug.");
540 io
.stdout
:write("Fixing timecodes..."); io
.stdout
:flush();
541 fixup_mp4box_bug_cfr(video_header
, video_samples
, DTSOffset
, maxdiv
);
543 delay
= math
.floor(0.5 + rdelay
/ 1000 * video_header
.timeScale
);
544 io
.stdout
:write("Done.\n");
548 -- Do the actual fixup.
549 io
.stdout
:write("Fixing up video timecodes..."); io
.stdout
:flush();
550 audio_fixup
= fixup_video_times(video_samples
, timecode_data
, delay
);
551 io
.stdout
:write("Done.\n");
552 io
.stdout
:write("Fixing up audio timecodes..."); io
.stdout
:flush();
553 fixup_audio_times(audio_samples
, audio_fixup
, video_header
.timeScale
, audio_header
.timeScale
);
554 io
.stdout
:write("Done.\n");
556 if do_aspect_fixup
== 1 then
557 video_header
.parNum
, video_header
.parDen
= reduce_fraction(4 * video_header
.height
, 3 * video_header
.width
);
559 if do_aspect_fixup
== 2 then
560 video_header
.parNum
, video_header
.parDen
= reduce_fraction(16 * video_header
.height
, 9 * video_header
.width
);
563 -- Save the NHML files.
564 io
.stdout
:write("Computing CTSOffset for video samples..."); io
.stdout
:flush();
565 translate_NHML_TS_out(video_samples
);
566 io
.stdout
:write("Done.\n");
567 io
.stdout
:write("Computing CTSOffset for audio samples..."); io
.stdout
:flush();
568 translate_NHML_TS_out(audio_samples
);
569 io
.stdout
:write("Done.\n");
570 io
.stdout
:write("Saving '" .. arg
[1] .. ".tmp'..."); io
.stdout
:flush();
571 call_with_file(write_NHML_data
, arg
[1] .. ".tmp", "w", video_header
, video_samples
);
572 io
.stdout
:write("Done.\n");
573 io
.stdout
:write("Saving '" .. arg
[2] .. ".tmp'..."); io
.stdout
:flush();
574 call_with_file(write_NHML_data
, arg
[2] .. ".tmp", "w", audio_header
, audio_samples
);
575 io
.stdout
:write("Done.\n");
576 io
.stdout
:write("Renaming '" .. arg
[1] .. ".tmp' -> '" .. arg
[1] .. "'..."); io
.stdout
:flush();
577 rename_errcheck(arg
[1] .. ".tmp", arg
[1], arg
[1] .. ".bak");
578 io
.stdout
:write("Done.\n");
579 io
.stdout
:write("Renaming '" .. arg
[2] .. ".tmp' -> '" .. arg
[2] .. "'..."); io
.stdout
:flush();
580 rename_errcheck(arg
[2] .. ".tmp", arg
[2], arg
[2] .. ".bak");
581 io
.stdout
:write("Done.\n");
582 io
.stdout
:write("All done.\n");