From patchwork Sun Nov 29 04:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 24146 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 3CD7344A7D1 for ; Sun, 29 Nov 2020 06:15:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DE3B688131; Sun, 29 Nov 2020 06:15:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB4266880D7 for ; Sun, 29 Nov 2020 06:14:59 +0200 (EET) Received: by mail-oi1-f173.google.com with SMTP id y74so10508466oia.11 for ; Sat, 28 Nov 2020 20:14:59 -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:mime-version :content-transfer-encoding; bh=+trv4x4lA1fSGrKhH54hvaA7mDVLYh4OZQVP5nDmMcc=; b=XgFyoYVuqlhc0tUjvF7M/LUQjjlM/CfHg23RTgU5JPxZPmb/FkGBy+sm6KDFM4HXuo o8nekHFT227kM2erpxpHQEeaZv8t3HJ8xgRM0nni56GjO1GpBzujgcTayNV5/OlLEtMP BRhEVwZ5RCnn8vcVZpAydRoqzjOp1T0k0c8V/v6maT1LNh9xHMR0tXQhYIMrz7+JD7D6 yyFdV+bvwAPniKywTZaqILA5O7JNcTJoM29N8mEQbCfWR62p2jptIADc3P+94hgOhuWG tbwX3LPMUuOGTUI5rIowLIzBPMtGyu4pD0N38wmCiUVMEkGOu4U+6T6Bzb3P8JrZblsz zv4Q== 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:mime-version :content-transfer-encoding; bh=+trv4x4lA1fSGrKhH54hvaA7mDVLYh4OZQVP5nDmMcc=; b=di/+PM3ovQ5NNVKNlkR5F2sCZtW0uGRAffEMhMfkaszS4IsZoO5pfnedT7UAaKpx+B Xpm2609UAkbH3uh1JUqPn7HZLhV3Iw8DVnXcJCCR6SngI3GD6HPiAyKsrp/NguAAuaYC 4ISeiJf6ZamzVnFvB1rUxy8o0o2ooiVeyCzjwex4PzFvZSh8/YWhqH5b6qbb6Mvppdli MoIcXbVVlYDoq+oKfyWLjwQh5jTdbuQDNaZ9cT8g2s2XHmGY9H1bwMTJT/+iuTDXZumT grSFzxlciRpyQk3bZW4Xa1qM1ejI/GlOLER9F/GjbajsVCwjfZCRilQSM0Uf4Drbj0vz b/Pw== X-Gm-Message-State: AOAM533PWtGshP4qsLhM8f0yQJTp6FA1h2eocm5dutSkrUqaYnxGOps/ wC43x6ofTmIrDtngl8lQ+2rJ6Vi9xYs= X-Google-Smtp-Source: ABdhPJyDrSvPmsr3I/OXneKsaN4jciE4CVdBczz8saVO+YbHJ79g4RnGV3zSlgp/ds/tMkuFizb7Ng== X-Received: by 2002:a17:90a:8b8b:: with SMTP id z11mr15411049pjn.117.1606622921029; Sat, 28 Nov 2020 20:08:41 -0800 (PST) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id q18sm11971891pfs.150.2020.11.28.20.08.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Nov 2020 20:08:40 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Nov 2020 20:08:38 -0800 Message-Id: <20201129040838.86636-1-mindmark@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] avformat/mov: fix timecode with counter mode flag set 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: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Mark Reid The current behaviour ends up squaring the avg_frame_rate if the conter mode flag is set. This messes up the timecode calculation, and looks to me as a regression that seems to have been introduced 428b4aac. The new behaviour is use the "Number of frames" field for avg_frame_rate from the timecode atom as describe here: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-69831 Number of frames An 8-bit integer that contains the number of frames per second for the timecode format. If the time is a counter, this is the number of frames for each counter tick. Here is a sample mov file with the counter flag set https://www.dropbox.com/s/5l4fucb9lhq523s/timecode_counter_mode.mov before the patch ffmpeg will report the timecode as: 00:37:11:97 and warns that the timecode framerate is 576000000/1002001 after patch: 14:50:55:02 --- libavformat/mov.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 2b90e31170..76c1ceb82a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2336,24 +2336,17 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, tmcd_ctx->tmcd_flags = val; st->avg_frame_rate.num = AV_RB32(st->codecpar->extradata + 8); /* timescale */ st->avg_frame_rate.den = AV_RB32(st->codecpar->extradata + 12); /* frameDuration */ -#if FF_API_LAVF_AVCTX -FF_DISABLE_DEPRECATION_WARNINGS - st->codec->time_base = av_inv_q(st->avg_frame_rate); -FF_ENABLE_DEPRECATION_WARNINGS -#endif + /* adjust for per frame dur in counter mode */ if (tmcd_ctx->tmcd_flags & 0x0008) { - int timescale = AV_RB32(st->codecpar->extradata + 8); - int framedur = AV_RB32(st->codecpar->extradata + 12); - st->avg_frame_rate.num *= timescale; - st->avg_frame_rate.den *= framedur; + st->avg_frame_rate.num = st->codecpar->extradata[16] /* fps, frames per counter tick in counter mode */; + st->avg_frame_rate.den = 1; + } #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS - st->codec->time_base.den *= timescale; - st->codec->time_base.num *= framedur; + st->codec->time_base = av_inv_q(st->avg_frame_rate); FF_ENABLE_DEPRECATION_WARNINGS #endif - } if (size > 30) { uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name atom length */ uint32_t format = AV_RB32(st->codecpar->extradata + 22);