summaryrefslogtreecommitdiff
blob: 2515b3ae7ee9f21a88f1151aa5254af7bd303830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
commit 5c1fe2a4f3e559a0c6a010e48b0c225d01c1cd0a
Author: wm4 <wm4@nowhere>
Date:   Sat Mar 5 12:48:58 2016 +0100

    demux: delay bitrate calculation on packets with unknown timestamps
    
    Commit 503c6f7f essentially removed timestamps from "laces" (Block sub-
    divisions), which means many audio packets will have no timestamp.
    There's no reason why bitrate calculation can't just delayed to a point
    when the next timestamp is known.
    
    Fixes #2903 (no audio bitrate with mkv files).

diff --git a/demux/demux.c b/demux/demux.c
index bd3211a..a7241d9 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -681,11 +681,11 @@ static struct demux_packet *dequeue_packet(struct demux_stream *ds)
     if (ts != MP_NOPTS_VALUE)
         ds->base_ts = ts;

-    if (pkt->keyframe) {
+    if (pkt->keyframe && ts != MP_NOPTS_VALUE) {
         // Update bitrate - only at keyframe points, because we use the
         // (possibly) reordered packet timestamps instead of realtime.
         double d = ts - ds->last_br_ts;
-        if (ts == MP_NOPTS_VALUE || ds->last_br_ts == MP_NOPTS_VALUE || d < 0) {
+        if (ds->last_br_ts == MP_NOPTS_VALUE || d < 0) {
             ds->bitrate = -1;
             ds->last_br_ts = ts;
             ds->last_br_bytes = 0;