ffmpeg-mythtv/ffmpeg-to-mkv-marks.awk

39 lines
849 B
Awk
Raw Normal View History

BEGIN {
RS="\n"
ORS="\n"
FS="[=/]"
mark["width"]=30
mark["height"]=31
mark["avg_frame_rate"]=32
mark["duration"]=33
mark["total_frames"]=34
}
# A typical record looks like: (I don't know how to remove duplicates)
# width=1280
# height=720
# avg_frame_rate=60000/1001
# duration=719.385322
# width=1280
# height=720
# avg_frame_rate=60000/1001
# duration=719.385322
# --
/width|height|avg_frame_rate|duration/{
if($1 ~ /avg_frame_rate|duration/) {
if (NF == 3 && $2 ~ /[0-9]+/ && $3 ~ /[1-9][0-9.]*/) {
#print $2 " " $3
a[$1] = int($2/$3*1000+0.5)
} else {
a[$1] = int($2*1000+0.5)
}
} else {
a[$1] = $2
}
}
END {
a["total_frames"]=int(a["duration"]*a["avg_frame_rate"]/1000/1000+0.5)
for (k in a) {
printf "<mark data=\"%s\" frame=\"0\" type=\"%s\"/>\n", a[k], mark[k]
}
}