From 663e0acee52b99982293bb5a2a2fe5004051b1bc Mon Sep 17 00:00:00 2001
From: bcoudurier <bcoudurier@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Date: Wed, 13 Jan 2010 22:23:29 +0000
Subject: [PATCH] use codec rc_max_rate if set and warn if bit rate is not set

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@21204 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
---
 libavformat/mpegtsenc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index be30e68a8..9b12af7ec 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -425,7 +425,16 @@ static int mpegts_write_header(AVFormatContext *s)
         if (st->codec->codec_type == CODEC_TYPE_VIDEO &&
             service->pcr_pid == 0x1fff)
             service->pcr_pid = ts_st->pid;
-        total_bit_rate += st->codec->bit_rate;
+        if (st->codec->rc_max_rate)
+            total_bit_rate += st->codec->rc_max_rate;
+        else {
+            if (!st->codec->bit_rate) {
+                av_log(s, AV_LOG_WARNING,
+                       "stream %d, bit rate is not set, this will cause problems\n",
+                       st->index);
+            }
+            total_bit_rate += st->codec->bit_rate;
+        }
         /* PES header size */
         if (st->codec->codec_type == CODEC_TYPE_VIDEO ||
             st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
-- 
2.25.4