summaryrefslogtreecommitdiff
path: root/libavformat/mpegtsenc.c
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-01-14 23:49:13 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-01-14 23:49:13 +0000
commit3d0a94f699a6d1615aac6aa0158d6b16bbbfd32b (patch)
treea0fe158fc8cc86e4861f998a02d06054fa17c9d9 /libavformat/mpegtsenc.c
parent620b9df7a76e6937bce8484316ce3c01083098e2 (diff)
calculate pat, pmt and sdt exact size and adjust total bitrate
Originally committed as revision 16610 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r--libavformat/mpegtsenc.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 9713bd9d84..8f15f5b5b5 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -385,6 +385,7 @@ static int mpegts_write_header(AVFormatContext *s)
AVStream *st;
int i, total_bit_rate;
const char *service_name;
+ uint64_t sdt_size, pat_pmt_size, pos;
ts->tsid = DEFAULT_TSID;
ts->onid = DEFAULT_ONID;
@@ -440,23 +441,39 @@ static int mpegts_write_header(AVFormatContext *s)
(TS_PACKET_SIZE * 8 * 1000);
ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
(TS_PACKET_SIZE * 8 * 1000);
-#if 0
- printf("%d %d %d\n",
- total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
-#endif
- if (s->mux_rate)
- ts->mux_rate = s->mux_rate;
- else
- ts->mux_rate = total_bit_rate;
+ ts->mux_rate = 1; // avoid div by 0
/* write info at the start of the file, so that it will be fast to
find them */
+ pos = url_ftell(s->pb);
mpegts_write_sdt(s);
+ sdt_size = url_ftell(s->pb) - pos;
+ pos = url_ftell(s->pb);
mpegts_write_pat(s);
for(i = 0; i < ts->nb_services; i++) {
mpegts_write_pmt(s, ts->services[i]);
}
+ pat_pmt_size = url_ftell(s->pb) - pos;
+
+ total_bit_rate +=
+ total_bit_rate * 25 / (8 * DEFAULT_PES_PAYLOAD_SIZE) + /* PES header size */
+ total_bit_rate * 4 / (8 * TS_PACKET_SIZE) + /* TS header size */
+ SDT_RETRANS_TIME * sdt_size + /* SDT size */
+ PAT_RETRANS_TIME * pat_pmt_size + /* PAT+PMT size */
+ PCR_RETRANS_TIME * 8; /* PCR size */
+
+ av_log(s, AV_LOG_DEBUG, "muxrate %d freq sdt %d pat %d\n",
+ total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
+
+ if (s->mux_rate)
+ ts->mux_rate = s->mux_rate;
+ else
+ ts->mux_rate = total_bit_rate;
+
+ // adjust pcr
+ ts->cur_pcr /= ts->mux_rate;
+
put_flush_packet(s->pb);
return 0;