From patchwork Fri Nov 25 09:18:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 1560 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp238014vsb; Fri, 25 Nov 2016 01:19:29 -0800 (PST) X-Received: by 10.28.166.20 with SMTP id p20mr6703571wme.87.1480065569581; Fri, 25 Nov 2016 01:19:29 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fg2si41361895wjb.134.2016.11.25.01.19.27; Fri, 25 Nov 2016 01:19:29 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06DF9689C1A; Fri, 25 Nov 2016 11:19:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2F7F6898F6 for ; Fri, 25 Nov 2016 11:19:12 +0200 (EET) X-QQ-mid: bizesmtp7t1480065527tww6j02io Received: from localhost (unknown [58.96.181.81]) by esmtp4.qq.com (ESMTP) with id ; Fri, 25 Nov 2016 17:18:46 +0800 (CST) X-QQ-SSF: 01100000002000F0F610B00A0000000 X-QQ-FEAT: oP8qruwI8aXitxc/lvkUXvmn996ZgH+fgWNA7aFnrY8GDsyi4YjP3lhnXra+p sdVN+KOao4JWcut73r5HRqx/ox+7afEk2opNZgbH10Fm0XKvrl9Xijglnoq6NdkoVHZyugA H5+ukuX3Q5fobtOdCPvzhP8rE05CQP7okY5cCSLjO0PJPRYSeJXi+FBJuYJAcLXiNtdvAfN OGeullnw98X7OMtHawC4QZtBcsC1ioZP3UTDw8PiHUAumspqAospBV9nojjcyXRjirSNtNW q/ig== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Nov 2016 17:18:43 +0800 Message-Id: <20161125091843.30594-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/flvdec: move set bit_rate from parse AMF OBJECT to create_stream X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" before patch: Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x714 [SAR 1:1 DAR 640:357], 25 fps, 25 tbr, 1k tbn, 50 tbc after patch: Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x714 [SAR 1:1 DAR 640:357], 2576 kb/s, 25 fps, 25 tbr, 1k tbn, 50 tbc Signed-off-by: Steven Liu --- libavformat/flvdec.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 3812994..a04280d 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -64,6 +64,8 @@ typedef struct FLVContext { int last_keyframe_stream_index; int keyframe_count; + int64_t video_bit_rate; + int64_t audio_bit_rate; int64_t *keyframe_times; int64_t *keyframe_filepositions; int missing_streams; @@ -140,11 +142,14 @@ static AVStream *create_stream(AVFormatContext *s, int codec_type) && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)) s->ctx_flags &= ~AVFMTCTX_NOHEADER; - if (codec_type == AVMEDIA_TYPE_AUDIO) + if (codec_type == AVMEDIA_TYPE_AUDIO) { + st->codecpar->bit_rate = flv->audio_bit_rate; flv->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO; - if (codec_type == AVMEDIA_TYPE_VIDEO) + } + if (codec_type == AVMEDIA_TYPE_VIDEO) { + st->codecpar->bit_rate = flv->video_bit_rate; flv->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO; - + } avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ flv->last_keyframe_stream_index = s->nb_streams - 1; @@ -534,12 +539,12 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, amf_type == AMF_DATA_TYPE_BOOL) { if (!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE; - else if (!strcmp(key, "videodatarate") && vpar && + else if (!strcmp(key, "videodatarate") && 0 <= (int)(num_val * 1024.0)) - vpar->bit_rate = num_val * 1024.0; - else if (!strcmp(key, "audiodatarate") && apar && + flv->video_bit_rate = num_val * 1024.0; + else if (!strcmp(key, "audiodatarate") && 0 <= (int)(num_val * 1024.0)) - apar->bit_rate = num_val * 1024.0; + flv->audio_bit_rate = num_val * 1024.0; else if (!strcmp(key, "datastream")) { AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE); if (!st)