From patchwork Fri Oct 7 06:05:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 904 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp1262092vsd; Thu, 6 Oct 2016 23:24:33 -0700 (PDT) X-Received: by 10.194.93.38 with SMTP id cr6mr14981207wjb.79.1475821473428; Thu, 06 Oct 2016 23:24:33 -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 r184si1636516wmf.109.2016.10.06.23.24.33; Thu, 06 Oct 2016 23:24:33 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 66581689D29; Fri, 7 Oct 2016 09:24:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89231687EC6 for ; Fri, 7 Oct 2016 09:24:08 +0300 (EEST) Received: by mail-qk0-f195.google.com with SMTP id v138so956747qka.2 for ; Thu, 06 Oct 2016 23:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=JLyf8j/926OuM3QF6GTjEWzw8tSHQ+C6sKRMwmstbQg=; b=bHGkt8gfON7LENcGQnfrtIMuuiaMtuxScrFIxY98dlyL4U+kQjf/TgeNIjawtKFOQc rQ5z4yeU1udNFZPH73K2qFyIjRE3dcmbgJwKkNncpUhs91vaO2fnp0JuCiQ6OXwS2csk rpg82D00wZ+AIwxTmacmuNQ6nvJoMVWvCzep9Rqaxvjt0mjlgohyDLbETc974AwEge2c DCKoxaRN8fcZ5iexDHspb+0h2RpcGS07s6FbTd2p7NvYlTDNxQgSpHSbXjFtrAZXnIM4 IjSdz1ByTDPIL3ZRGCE0XKtIAC7qQUIu1fbA602/Tr6RvEdmrSwjakfr2qpJzMh6emdM TsSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=JLyf8j/926OuM3QF6GTjEWzw8tSHQ+C6sKRMwmstbQg=; b=L5qL3Auh4iffWQeW5pMXVKc8zwR/TE4cmOYG9Tve6qm+FmJEa7vKPl0dvcG+COLQHg qAZrQEcsAAQ17RqPWE2+edVduHk5v6fCp2cDtIAWLlPDZFFwz6afmsovyuzIrA0EcZmG 3KrVqztYbNpAppPOIUpT5wzdppAdQermivxvEDKrOPxE6sVtNj5IP+616rOD11LUcl5r Kd5dDtqaqqodBgDjzqptTtPLMqPmqswBopY/G9Q6VTrOjz+p2fkXMcqd75mH//mzpNIR cnWpd0PVowwMOFSsPPU0F+1ZdD2pivsLx1xi+SR7K+GCzWUhFVdMTm5o6yBsKPzdz1hu eUrg== X-Gm-Message-State: AA6/9RkmZsAeN8Ks0hIEow4yktvegC7yF/xNSjP0XlE+dnqWESbrbMscpMm5FTh4vVT8uQ== X-Received: by 10.55.124.198 with SMTP id x189mr17476880qkc.315.1475820398345; Thu, 06 Oct 2016 23:06:38 -0700 (PDT) Received: from localhost.localdomain ([181.22.68.3]) by smtp.gmail.com with ESMTPSA id p22sm736358qka.43.2016.10.06.23.06.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Oct 2016 23:06:37 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2016 03:05:35 -0300 Message-Id: <20161007060536.8136-1-jamrial@gmail.com> X-Mailer: git-send-email 2.9.1 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/matroskaenc: fix Tags master on seekable output if there are tags after the last stream duration 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The dynamic AVIOContext would get closed pointing to the wrong position in the buffer. This is a regression since 650e17d88b63b5aca6e0a43483e89e64b0f7d2dd. Signed-off-by: James Almer --- Example: ./ffmpeg -i fate-samples/vorbis/vorbis_chapter_extension_demo.ogg -c:a copy -metadata:c key=value out.mka The output is corrupt before this patch. The refactoring isn't necessary per se, but it comes in handy for the next patch, where attachments will not be treated as tracks anymore when writting tags. libavformat/matroskaenc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 0878cb5..286b8b4 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2264,17 +2264,19 @@ static int mkv_write_trailer(AVFormatContext *s) end_ebml_master_crc32(pb, &mkv->info_bc, mkv, mkv->info); // update stream durations - if (mkv->stream_durations) { + if (!mkv->is_live && mkv->stream_durations) { int i; + int64_t curr = avio_tell(mkv->tags_bc); for (i = 0; i < s->nb_streams; ++i) { AVStream *st = s->streams[i]; - double duration_sec = mkv->stream_durations[i] * av_q2d(st->time_base); - char duration_string[20] = ""; - av_log(s, AV_LOG_DEBUG, "stream %d end duration = %" PRIu64 "\n", i, - mkv->stream_durations[i]); + if (mkv->stream_duration_offsets[i] > 0) { + double duration_sec = mkv->stream_durations[i] * av_q2d(st->time_base); + char duration_string[20] = ""; + + av_log(s, AV_LOG_DEBUG, "stream %d end duration = %" PRIu64 "\n", i, + mkv->stream_durations[i]); - if (!mkv->is_live && mkv->stream_duration_offsets[i] > 0) { avio_seek(mkv->tags_bc, mkv->stream_duration_offsets[i], SEEK_SET); snprintf(duration_string, 20, "%02d:%02d:%012.9f", @@ -2284,6 +2286,7 @@ static int mkv_write_trailer(AVFormatContext *s) put_ebml_binary(mkv->tags_bc, MATROSKA_ID_TAGSTRING, duration_string, 20); } } + avio_seek(mkv->tags_bc, curr, SEEK_SET); } if (mkv->tags.pos && !mkv->is_live) { avio_seek(pb, mkv->tags.pos, SEEK_SET);