ffmpeg-mythtv/ffmpeg-to-mkv-seektable.awk
2020-07-27 17:33:47 -05:00

34 lines
831 B
Awk

BEGIN {
RS="--\n"
ORS="\n"
FS="[=\n]"
frm=0
offset=0
}
# A typical record looks like:
# pkt_pts_time=166.725833
# pkt_pos=596336
# pict_type=I
# coded_picture_number=13
# interlaced_frame=0
# --
{
pkt_pts_time=int($2*1000+0.5)
pkt_pos=$4
frame=$8+offset
if (frm==0) {
startpts=pkt_pts_time
# a bug? in ffprobe makes the frame numbers deficient by 2 after frame 0
# but this does not seem to affect mkv containers made by ffmpeg?
if (ending != "mkv") {
offset=2
}
}
frm=1
pkt_pts_time=pkt_pts_time-startpts
# <seek data="381841724" frame="9570" type="9"/>
# <seek data="159660" frame="9570" type="33"/>
print "<seek type=\"9\" data=\"" pkt_pos "\" frame=\"" frame "\"/>"
print "<seek type=\"33\" data=\"" pkt_pts_time "\" frame=\"" frame "\"/>"
}