/* FIXME, should not be called with NULL */
if (chain != NULL) {
- gint bitrate;
+ gint bitrate, idx_bitrate;
GST_DEBUG_OBJECT (ogg, "activating chain %p", chain);
- bitrate = 0;
+ bitrate = idx_bitrate = 0;
/* first add the pads */
for (i = 0; i < chain->streams->len; i++) {
pad = g_array_index (chain->streams, GstOggPad *, i);
+ if (pad->map.idx_bitrate)
+ idx_bitrate = MAX (idx_bitrate, pad->map.idx_bitrate);
+
bitrate += pad->map.bitrate;
/* mark discont */
gst_element_add_pad (GST_ELEMENT (ogg), GST_PAD_CAST (pad));
pad->added = TRUE;
}
- ogg->bitrate = bitrate;
+ /* prefer the index bitrate over the ones encoded in the streams */
+ ogg->bitrate = (idx_bitrate ? idx_bitrate : bitrate);
}
/* after adding the new pads, remove the old pads */
G_GUINT64_FORMAT, n_keypoints, isize);
}
pad->n_index = isize;
+ /* try to use the index to estimate the bitrate */
+ if (isize > 2) {
+ guint64 so, eo, st, et, b, t;
+
+ /* get start and end offset and timestamps */
+ so = pad->index[0].offset;
+ st = pad->index[0].timestamp;
+ eo = pad->index[isize - 1].offset;
+ et = pad->index[isize - 1].timestamp;
+
+ b = eo - so;
+ t = et - st;
+
+ GST_DEBUG ("bytes/time %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, b, t);
+
+ /* this is the total stream bitrate according to this index */
+ pad->idx_bitrate = gst_util_uint64_scale (8 * b, pad->kp_denom, t);
+
+ GST_DEBUG ("bitrate %" G_GUINT64_FORMAT, pad->idx_bitrate);
+ }
return TRUE;
}