From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8A65040AD1 for ; Mon, 27 Dec 2021 00:26:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D62A868B0D6; Mon, 27 Dec 2021 02:26:32 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81A4768B0BB for ; Mon, 27 Dec 2021 02:26:26 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 0F9B8E663E; Mon, 27 Dec 2021 01:26:26 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NBmd4P_PZOTu; Mon, 27 Dec 2021 01:26:25 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DD7A8E6631; Mon, 27 Dec 2021 01:26:24 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Dec 2021 01:26:11 +0100 Message-Id: <20211227002613.25069-3-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211227002613.25069-1-cus@passwd.hu> References: <20211227002613.25069-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/flvenc: use ff_format_shift_data for data shifting X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Marton Balint Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: add_keyframe_index seems to generate a corrupted index even before this change. Signed-off-by: Marton Balint --- libavformat/flvenc.c | 59 +++++--------------------------------------- 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 5130d429ad..31d1d93c23 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -576,15 +576,9 @@ static int flv_append_keyframe_info(AVFormatContext *s, FLVContext *flv, double static int shift_data(AVFormatContext *s) { - int ret = 0; - int n = 0; + int ret; int64_t metadata_size = 0; FLVContext *flv = s->priv_data; - int64_t pos, pos_end = avio_tell(s->pb); /* Save the pre-shift size. */ - uint8_t *buf, *read_buf[2]; - int read_buf_id = 0; - int read_size[2]; - AVIOContext *read_pb; metadata_size = flv->filepositions_count * 9 * 2 + 10; /* filepositions and times value */ metadata_size += 2 + 13; /* filepositions String */ @@ -596,58 +590,17 @@ static int shift_data(AVFormatContext *s) if (metadata_size < 0) return metadata_size; - buf = av_malloc_array(metadata_size, 2); - if (!buf) { - return AVERROR(ENOMEM); - } - read_buf[0] = buf; - read_buf[1] = buf + metadata_size; + ret = ff_format_shift_data(s, flv->keyframes_info_offset, metadata_size); + if (ret < 0) + return ret; avio_seek(s->pb, flv->metadata_size_pos, SEEK_SET); avio_wb24(s->pb, flv->metadata_totalsize + metadata_size); - avio_seek(s->pb, flv->metadata_totalsize_pos, SEEK_SET); + avio_seek(s->pb, flv->metadata_totalsize_pos + metadata_size, SEEK_SET); avio_wb32(s->pb, flv->metadata_totalsize + 11 + metadata_size); - /* Shift the data: the AVIO context of the output can only be used for - * writing, so we re-open the same output, but for reading. It also avoids - * a read/seek/write/seek back and forth. */ - avio_flush(s->pb); - ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for " - "the second pass (add_keyframe_index)\n", s->url); - goto end; - } - - /* Get ready for writing. */ - avio_seek(s->pb, flv->keyframes_info_offset + metadata_size, SEEK_SET); - - /* start reading at where the keyframe index information will be placed */ - avio_seek(read_pb, flv->keyframes_info_offset, SEEK_SET); - pos = avio_tell(read_pb); - -#define READ_BLOCK do { \ - read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], metadata_size); \ - read_buf_id ^= 1; \ -} while (0) - - /* shift data by chunk of at most keyframe *filepositions* and *times* size */ - READ_BLOCK; - do { - READ_BLOCK; - n = read_size[read_buf_id]; - if (n < 0) - break; - avio_write(s->pb, read_buf[read_buf_id], n); - pos += n; - } while (pos <= pos_end); - - ff_format_io_close(s, &read_pb); - -end: - av_free(buf); - return ret; + return 0; } static int flv_init(struct AVFormatContext *s) -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".