Difference between revisions of "MicroDVD"

From MultimediaWiki
Jump to navigation Jump to search
(New page)
 
(Add .txt => .srt conversion code)
Line 12: Line 12:
 
</pre>
 
</pre>
  
 +
== Conversion ==
 +
The following [https://en.wikipedia.org/wiki/AWK#Versions_and_implementations gawk] script will convert MicroDVD to [[SubRip]] format
 +
<code><pre>
 +
BEGIN { FpS=23.976 ; NL="\n" }
 +
function timestamp(f,  s) {
 +
s=int(f/FpS)
 +
return sprintf("%02d:%02d:%02d,%03d", int(s/3600), int(s%3600/60), int(s%60), int((f-s*FpS)*1000/FpS))
 +
}
 +
{ if ( match($0, /^\{([0-9]+)\}\{([0-9]+)\}(.+)/, Frame) == 0 || gsub(/\|/,NL,Frame[3])>1 )
 +
{ print "Rejecting:" $0 > "/dev/stderr" ; next }
 +
print NR NL timestamp(Frame[1]) " --> " timestamp(Frame[2]) NL Frame[3] NL
 +
}
 +
</pre></code>
  
 
[[Category:Subtitle Formats]]
 
[[Category:Subtitle Formats]]

Revision as of 18:32, 11 April 2019

  • Extensions: .txt, .sub


MicroDVD is a very simple subtitle format based on frame numbers instead of time codes. The format for every line is:

{START_FRAME}{END_FRAME}Dialog line|Second line of dialog

Example

{25}{125}-First line|-Second line
{25}{125}Just one line

Conversion

The following gawk script will convert MicroDVD to SubRip format

BEGIN {	FpS=23.976 ; NL="\n" }
function timestamp(f,  s) {
	s=int(f/FpS)
	return sprintf("%02d:%02d:%02d,%03d", int(s/3600), int(s%3600/60), int(s%60), int((f-s*FpS)*1000/FpS))
}
{	if ( match($0, /^\{([0-9]+)\}\{([0-9]+)\}(.+)/, Frame) == 0 || gsub(/\|/,NL,Frame[3])>1 )
		{ print "Rejecting:" $0 > "/dev/stderr" ; next }
	print NR NL timestamp(Frame[1]) " --> " timestamp(Frame[2]) NL Frame[3] NL
}