From patchwork Thu Nov 24 03:49:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 1543 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp3099902vsb; Wed, 23 Nov 2016 19:50:19 -0800 (PST) X-Received: by 10.194.103.5 with SMTP id fs5mr181795wjb.227.1479959419562; Wed, 23 Nov 2016 19:50:19 -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 l66si6024106wma.114.2016.11.23.19.50.17; Wed, 23 Nov 2016 19:50:19 -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 60A25689220; Thu, 24 Nov 2016 05:50:10 +0200 (EET) 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 E46A36806CE for ; Thu, 24 Nov 2016 05:50:02 +0200 (EET) X-QQ-mid: bizesmtp2t1479959379ti7aqqhds Received: from localhost (unknown [58.96.181.81]) by esmtp4.qq.com (ESMTP) with id ; Thu, 24 Nov 2016 11:49:39 +0800 (CST) X-QQ-SSF: 01100000000000F0F610000A0000000 X-QQ-FEAT: WluEz68a3gHOIJlSV+52DIVegnIvBCo6J4Pda6BnHTynQKQkPYno+ri94lkPZ gVQu6E6RxR9tJ5XCVEDM+gNCcLhn0NFIXxa+tPEoLcJqsiKCLeD4WD7jatv1+Mzt+1NTIf7 gNTzOrI514SxeUgatdoZv1+GY9NkLDVuCgZQzQl38tJBSsvkWPM+G+eZEVgRIBK9NYyZ9TI L61r/326fo0IM2MAGzFOdY60bfDW6mCTrXtLNtsomhOcVyv7NWvHu+1Yp1nXvL6TKgkNcNw CPrA== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Nov 2016 11:49:36 +0800 Message-Id: <20161124034936.16178-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: fix ticket 5976 and use old commit 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" mythtv have problem with non-seekable dont write duration and filesize and there have problem with some other server and player with 0 value duation and filesize. So add a flv flags to fix the ticket and make a choose for users. Signed-off-by: Steven Liu --- doc/muxers.texi | 4 ++++ libavformat/flvenc.c | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 8689341..1c14adf 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -151,6 +151,10 @@ Disable sequence end tag. @item no_metadata Disable metadata tag. +@item no_duration_filesize +Disable duration and filesize in metadata when they are equal to zero +at the end of stream. (Be used to non-seekable living stream). + @item add_keyframe_index Used to facilitate seeking; particularly for HTTP pseudo streaming. @end table diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 177052a..62d406a 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -68,6 +68,7 @@ typedef enum { FLV_NO_SEQUENCE_END = (1 << 1), FLV_ADD_KEYFRAME_INDEX = (1 << 2), FLV_NO_METADATA = (1 << 3), + FLV_NO_DURATION_FILESIZE = (1 << 4), } FLVFlags; typedef struct FLVFileposition { @@ -269,6 +270,7 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) { AVIOContext *pb = s->pb; FLVContext *flv = s->priv_data; + int write_duration_filesize = !(flv->flags & FLV_NO_DURATION_FILESIZE); int metadata_count = 0; int64_t metadata_count_pos; AVDictionaryEntry *tag = NULL; @@ -292,12 +294,12 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) metadata_count = 4 * !!flv->video_par + 5 * !!flv->audio_par + 1 * !!flv->data_par; - if (pb->seekable) { + if (write_duration_filesize) { metadata_count += 2; // +2 for duration and file size } avio_wb32(pb, metadata_count); - if (pb->seekable) { + if (write_duration_filesize) { put_amf_string(pb, "duration"); flv->duration_offset = avio_tell(pb); // fill in the guessed duration, it'll be corrected later if incorrect @@ -378,7 +380,7 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) metadata_count++; } - if (pb->seekable) { + if (write_duration_filesize) { put_amf_string(pb, "filesize"); flv->filesize_offset = avio_tell(pb); put_amf_double(pb, 0); // delayed write @@ -844,7 +846,7 @@ end: avio_seek(pb, flv->datasize_offset, SEEK_SET); put_amf_double(pb, flv->datasize); } - if (pb->seekable) { + if (!(flv->flags & FLV_NO_DURATION_FILESIZE)) { /* 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"); @@ -1061,6 +1063,7 @@ static const AVOption options[] = { { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, { "no_sequence_end", "disable sequence end for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_SEQUENCE_END}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, { "no_metadata", "disable metadata for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_METADATA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, + { "no_duration_filesize", "disable duration and filesize zero value metadata for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_DURATION_FILESIZE}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, { "add_keyframe_index", "Add keyframe index metadata", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_ADD_KEYFRAME_INDEX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, { NULL }, };