From patchwork Wed Oct 12 10:11:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 970 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp230377vsd; Wed, 12 Oct 2016 03:12:01 -0700 (PDT) X-Received: by 10.194.78.227 with SMTP id e3mr257404wjx.195.1476267121150; Wed, 12 Oct 2016 03:12:01 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 129si45965wmj.49.2016.10.12.03.12.00; Wed, 12 Oct 2016 03:12:01 -0700 (PDT) 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 8BA24689980; Wed, 12 Oct 2016 13:11:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8211D687EC4 for ; Wed, 12 Oct 2016 13:11:50 +0300 (EEST) X-QQ-mid: bizesmtp13t1476267103tqrdf8yl Received: from localhost (unknown [58.96.181.81]) by esmtp4.qq.com (ESMTP) with id ; Wed, 12 Oct 2016 18:11:41 +0800 (CST) X-QQ-SSF: 01100000008000F0F511C00A0000000 X-QQ-FEAT: 3GtnPQ8BMmYESRrguoTXUkANdAHHK22gpB7nwQcgZqOIVoUvV+/Kz/s5k7uBK c5mHwlYk3B9+CUithbKdZaktAUh2E8pEsIFHZrjbBvZPl7FaoYSE3cogIviCDGftHBI6N5r g9PLlxWQAa9EqlqGZm7ZiegDwczjpEzcD2h86deFQcw1qHdaTJLKqUTzT0gfEm2WLf7LX+0 kH8SSboYijcwUygO4gizFXW3OJXqoU9DbRGs0/eQchVLS7Hjihx3mKvnc9bGURBmxz4F5Zz FH3w== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Oct 2016 18:11:41 +0800 Message-Id: <20161012101141.9933-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/flvenc: do not write duration and filesize when cannot seekable 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" when living stream cannot seekable, don't write duration and filesize in metadata, and donnot seek at the flv_write_trailer Signed-off-by: Steven Liu --- libavformat/flvenc.c | 49 ++++++++++++++++++++++++++++--------------------- 1 files changed, 28 insertions(+), 21 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 99903f5..e50f8e4 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -234,16 +234,18 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) metadata_count_pos = avio_tell(pb); metadata_count = 4 * !!flv->video_par + 5 * !!flv->audio_par + - 1 * !!flv->data_par + - 2; // +2 for duration and file size - + 1 * !!flv->data_par; + if (pb->seekable) { + metadata_count += 2; // +2 for duration and file size + } avio_wb32(pb, metadata_count); - put_amf_string(pb, "duration"); - flv->duration_offset = avio_tell(pb); - - // fill in the guessed duration, it'll be corrected later if incorrect - put_amf_double(pb, s->duration / AV_TIME_BASE); + if (pb->seekable) { + put_amf_string(pb, "duration"); + flv->duration_offset = avio_tell(pb); + // fill in the guessed duration, it'll be corrected later if incorrect + put_amf_double(pb, s->duration / AV_TIME_BASE); + } if (flv->video_par) { put_amf_string(pb, "width"); @@ -319,9 +321,11 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) metadata_count++; } - put_amf_string(pb, "filesize"); - flv->filesize_offset = avio_tell(pb); - put_amf_double(pb, 0); // delayed write + if (pb->seekable) { + put_amf_string(pb, "filesize"); + flv->filesize_offset = avio_tell(pb); + put_amf_double(pb, 0); // delayed write + } put_amf_string(pb, ""); avio_w8(pb, AMF_END_OF_OBJECT); @@ -543,16 +547,19 @@ static int flv_write_trailer(AVFormatContext *s) file_size = avio_tell(pb); - /* update information */ - if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0) - av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n"); - else - put_amf_double(pb, flv->duration / (double)1000); - if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0) - av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n"); - else - put_amf_double(pb, file_size); - + if (pb->seekable) { + /* update information */ + if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0) { + av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n"); + } else { + put_amf_double(pb, flv->duration / (double)1000); + } + if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0) { + av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n"); + } else { + put_amf_double(pb, file_size); + } + } avio_seek(pb, file_size, SEEK_SET); return 0; }