From patchwork Thu Jan 16 04:49:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17382 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id ACB3544A932 for ; Thu, 16 Jan 2020 06:57:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8DA8368B0EE; Thu, 16 Jan 2020 06:57:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13F0468AD65 for ; Thu, 16 Jan 2020 06:57:09 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id g17so17765308wro.2 for ; Wed, 15 Jan 2020 20:57:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W92WrwUGX0pr4QuJQyPe2ZjUH62pD8SBMPaVsQB4aQQ=; b=sSH7ndo5BMqDJDY8ttptiWRWzb171zhEk54FjeuaXZn8ccdJb/2ZeQY9enXY689oAJ 4W9Sjp7PCKB23Z9brA6z2Ptg69ukfxTsOYoQ0DuryW3uo32Pmmd+e+psMnprdHx/a8Us sWiYUVRcBSVsEDbxJ6eb0AItJQSuOyewC980bvasWHDAqGzkuX/enzSSf7e+RO3Mnheg PCMC4Wskp+BSj0ruYFTSTdkB8ehZLRYpm3UnM+2T6CqOnyTvh+xsXE/CTY3BDQXky6no mo+bqd9u5E/RyaDxe9cVDRGAtUrvFPr/sy6/QqkEj0P0sx8eV7FFnd+RnPoA0IO5U0wU 3+5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W92WrwUGX0pr4QuJQyPe2ZjUH62pD8SBMPaVsQB4aQQ=; b=XorqI2+nwbSRH2vp/t7eEJ7jP6TmZKc/wmLNsIo4nqGd/T3h+GztcLaItziqWtMaKo 5uu1aoxkIii/RZaj48osYpsl3sBrYw1S7DnD153UZjK14cMKS7iYvPpLj/sZ/PUxhe6f aO28qoi9IEv7GisVsJGPiTjq9+HrOzFOPHUw2KmyabJ2P4J3nAeRsRWpDRVxyaRTTVO6 /MI+/UBoY+BbOhYe+HrHfLKstM3x5pgyaiEBJ6q8Sr9oWwzbTNlTFw1RW8qSAWbGE0lV MYVG1Jw5vAEkqzBSXCp8XWXa+s6leuADbhtcKSJbxpdc3sYo4nJV+QeJzmYcpjvWiIZN Udsw== X-Gm-Message-State: APjAAAUzAeCCRo6QKNDY7kBDSUWVPxEwnMlJ4xCyJsKfw4v+wLUupDnN DNQTWcTvxKjafjuY2X6xby9E4BA7 X-Google-Smtp-Source: APXvYqxKuIOjOTBuo4lYTpk8QScv8i20H5euI10WlYAEK1a9Vt0w9dgzdfEOKC2WMQNdmSxqjoyBuQ== X-Received: by 2002:adf:e550:: with SMTP id z16mr942433wrm.315.1579150628353; Wed, 15 Jan 2020 20:57:08 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id m7sm2289658wma.39.2020.01.15.20.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2020 20:57:07 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jan 2020 05:49:15 +0100 Message-Id: <20200116044915.13681-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116044915.13681-1-andreas.rheinhardt@gmail.com> References: <20200116044915.13681-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/flvenc: Avoid unnecessary seek 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When shifting the already written data in order to write the keyframe index, the flv muxer would first store the pre-shift size, then calculate how big the index will be eventually, then perform some seeks to update some size fields, then seek back to the end of the file to get the new position, followed by a seek to the position where writing will really start. Seeking back to the (already known) end position (that is actually used to perform this seek) to get the end position is of course unnecessary. It has been removed. Signed-off-by: Andreas Rheinhardt --- libavformat/flvenc.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 1aaf0333ca..5cf3ce8a1a 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -580,7 +580,7 @@ static int shift_data(AVFormatContext *s) int n = 0; int64_t metadata_size = 0; FLVContext *flv = s->priv_data; - int64_t pos, pos_end = avio_tell(s->pb); + 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]; @@ -608,7 +608,6 @@ static int shift_data(AVFormatContext *s) avio_seek(s->pb, flv->metadata_totalsize_pos, SEEK_SET); avio_wb32(s->pb, flv->metadata_totalsize + 11 + metadata_size); - avio_seek(s->pb, pos_end, SEEK_SET); /* 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 @@ -621,9 +620,7 @@ static int shift_data(AVFormatContext *s) goto end; } - /* mark the end of the shift to up to the last data we wrote, and get ready - * for writing */ - pos_end = avio_tell(s->pb); + /* 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 */