diff mbox

[FFmpeg-devel,07/10] avformat/mpegtsenc: count packets instead of using avio_tell

Message ID 20191112212906.18539-7-cus@passwd.hu
State New
Headers show

Commit Message

Marton Balint Nov. 12, 2019, 9:29 p.m. UTC
Next patch needs this.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mpegtsenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index be41311bf7..a4b28f7d74 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -112,6 +112,7 @@  typedef struct MpegTSWrite {
     int64_t sdt_period_us;
     int64_t last_pat_ts;
     int64_t last_sdt_ts;
+    int64_t nb_packets;
 
     int omit_video_pes_length;
 } MpegTSWrite;
@@ -719,7 +720,7 @@  invalid:
 
 static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
 {
-    return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
+    return av_rescale(ts->nb_packets * TS_PACKET_SIZE + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
            ts->first_pcr;
 }
 
@@ -734,6 +735,7 @@  static void write_packet(AVFormatContext *s, const uint8_t *packet)
                    sizeof(tp_extra_header));
     }
     avio_write(s->pb, packet, TS_PACKET_SIZE);
+    ts->nb_packets++;
 }
 
 static void section_write_packet(MpegTSSection *s, const uint8_t *packet)