From patchwork Sun Apr 10 18:11:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 35244 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp686667pzh; Sun, 10 Apr 2022 11:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzDywDD5jQjswdFZvMT5JMNoQ/ov9B/+dG2pZyssNGGv4UollHtwGKGJi393poJxHxdeV0 X-Received: by 2002:a17:906:d552:b0:6e8:4ee4:748 with SMTP id cr18-20020a170906d55200b006e84ee40748mr11899005ejc.58.1649614334363; Sun, 10 Apr 2022 11:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649614334; cv=none; d=google.com; s=arc-20160816; b=cPmGSKxmGM+W7NIbtQczKyUmFsX5YKwp6tS3QHYho3+NCH07HLdVgfUWfAMNAnzoFD JZ4Xwwv+DzUA0oQf5ft2wyOfy+1PqwsVQknEJWz2abfbcMDesKcgkGP5dXayC9mrC8iP Mbme/G4ou3ecZH9nM43iTr0IGOl+gncy3DrXfm3nLuq/ZourVzmvQEVI3t/LYWGHAarF eKfkXmQwCLStsPP+vUIgvFzO9tV5NmItaHTI/UK+YDPA2MIxaBCz0mH9odobd8SoiMvY sRj6cHRuQxM2T6dl7YRyWByO9VZwh3K6li31an8SnSnM8RlWA9Eh0+VSomoH8G2eYT9S FsWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=d19hU5soqrAURqH9lNaVMkdnbagV7fEN+iFSj6PMd98=; b=pEUXGAh/vyITTBMLpACkwfjHN3rdvVVTXrB6CsUt8atm0XtsO2UhBjQbtKUozoZGr6 GrFUHr8ZrNQdqmX1T/POYLfvCJD/6LbFFQe0+yXeF3GkEXTb5nsIvL0Z2+BdFeiDMmJr NlPfYzXdOZ6dBNn6hdO6SX5TIIajNYGC8pnl6nqEpx3towlgZ232otF25UmWLEoRPSpD k5IEWBJgD2cuSfm3/8dKugH2fZAE9oCQ708AikZof5lek6EE9Laa5BRpX6PKYmHIlMxB 0bs+km2zsuvcX/dBbilPqzbQA9R4avjjaVhbPt41+4gfiCkHlRRNiWujrCqLRr6KObSa 63jg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr4-20020a1709073f8400b006dfc6f53845si6863408ejc.455.2022.04.10.11.12.13; Sun, 10 Apr 2022 11:12:14 -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; 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 25C6868B34A; Sun, 10 Apr 2022 21:12:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37CB568B204 for ; Sun, 10 Apr 2022 21:12:03 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C927BE69E4; Sun, 10 Apr 2022 20:12:03 +0200 (CEST) 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 jH9BuadOA-YF; Sun, 10 Apr 2022 20:12:02 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 14EE3E67CF; Sun, 10 Apr 2022 20:12:02 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Apr 2022 20:11:59 +0200 Message-Id: <20220410181200.3181-1-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YlGNnWxeVDDK 60 fps content have "Number of Frames" set to 30 in the tmcd atom, but the frame duration / timescale reflects the original video frame rate. Therefore we multiply the frame count with the quotient of the rounded timecode frame rate and the "Number of Frames" per second to get a frame count in the original (higher) frame rate. Note that the frames part in the timecode will be in high frame rate which will make the timecode different to e.g. MediaInfo which seems to show the 30 fps timecode even for 120 fps content. Regression since 428b4aacb1a91a267650de644519882a5f700388. Fixes ticket #9710. Fixes ticket #9492. Signed-off-by: Marton Balint --- libavformat/isom.h | 1 + libavformat/mov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 5caf42b15d..99408a42d1 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -214,6 +214,7 @@ typedef struct MOVStreamContext { int has_palette; int64_t data_size; uint32_t tmcd_flags; ///< tmcd track flags + uint8_t tmcd_nb_frames; ///< tmcd number of frames per tick / second int64_t track_end; ///< used for dts generation in fragmented movie files int start_pad; ///< amount of samples to skip due to enc-dec delay unsigned int rap_group_count; diff --git a/libavformat/mov.c b/libavformat/mov.c index 6c847de164..8527591ff3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2364,6 +2364,7 @@ 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 */ + tmcd_ctx->tmcd_nb_frames = st->codecpar->extradata[16]; /* number of frames */ if (size > 30) { uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name atom length */ uint32_t format = AV_RB32(st->codecpar->extradata + 22); @@ -7893,11 +7894,16 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) FFStream *const sti = ffstream(st); int flags = 0; int64_t cur_pos = avio_tell(sc->pb); - uint32_t value; + int64_t value; + AVRational tc_rate = st->avg_frame_rate; + int rounded_tc_rate; if (!sti->nb_index_entries) return -1; + if (!tc_rate.num || !tc_rate.den || !sc->tmcd_nb_frames) + return -1; + avio_seek(sc->pb, sti->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); @@ -7910,6 +7916,12 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) * No sample with tmcd track can be found with a QT timecode at the moment, * despite what the tmcd track "suggests" (Counter flag set to 0 means QT * format). */ + + /* 60 fps content have tmcd_nb_frames set to 30 but tc_rate set to 60, so + * we multiply the frame number with the quotient. */ + rounded_tc_rate = (tc_rate.num + tc_rate.den / 2) / tc_rate.den; + value = av_rescale(value, rounded_tc_rate, sc->tmcd_nb_frames); + parse_timecode_in_framenum_format(s, st, value, flags); avio_seek(sc->pb, cur_pos, SEEK_SET); From patchwork Sun Apr 10 18:12:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 35245 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp686724pzh; Sun, 10 Apr 2022 11:12:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlyc9bdwr+k+Ht7f1I7mwGSHuQVw7GNrtdReqE+dKCJssK0iEoMzn+px0s90oz0CC5vNLz X-Received: by 2002:a17:906:58d2:b0:6da:b635:fbf3 with SMTP id e18-20020a17090658d200b006dab635fbf3mr26266107ejs.40.1649614343962; Sun, 10 Apr 2022 11:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649614343; cv=none; d=google.com; s=arc-20160816; b=JAb31zU/mJnGWvzYMVfPk27mHnu0/Cys8587evbYf/dq8Z0y5i7l1dJ7rsoHRKKhSP vycdE8NvE6QO9rTCc9LS2q39BJRbg02TsZ2NIc0ip3GB+urTEw0yhQoWx4Q2lIYl/VEy LCwbPM79DpKKzT8qRM5I6AMSAczG/9CQJJlwU12b2VzJtBnHmPCjFgefDok1gj7yXD4W MIVCcd4Mp7dcOn91VlHEqQP7MqboAnWuwf7t4ued26GS5IkJ889k+6/qhMGkV3nQtGgx AzaOERXDQ/LMluXz+eqmoSmdc7fCvsG4q1+HpDh+FUltx/RYewXC5zNE6TRM3su8LT6Q BTnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=VP2Ac4jXj3TKOpfWQ4xPZBn8OmqQQBJUajs3MXnu6jg=; b=cCddwxY/IJw2rpAOJJAwqCOO8VdYNkUjH7nUmeHrmLkXMKwtnReQKKs752tTE4t3v3 cEr1F4HKnrE+iT7XKKrFWVdGKvsJSgj6QNcbmJ630TJCbvaSJC8Cj0QnL17rj30Jvkiq ums0wjB0nLoMqAUPmthTk3mUfUio92LYddBIf1lbUzsgFiEAyNbPOszlBqeGimKFiYBd MB3LWGEJ95EQ5w2e/+hYnVVJrA3BKbDhPrZADTtOi9X649vuNXyM5hYGhzrVRtsdlK5Y E9EO4SQS2GQtxhLKruoz8YkbBmNjloWtdRUBLng3FCeOe7Sj5A6UtwDUY/cadVt5itrs JwkQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h9-20020a50cf89000000b00418c2b5be8fsi5185398edk.369.2022.04.10.11.12.23; Sun, 10 Apr 2022 11:12:23 -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; 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 2148768B34E; Sun, 10 Apr 2022 21:12:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB8E668B204 for ; Sun, 10 Apr 2022 21:12:03 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5C629E67CF; Sun, 10 Apr 2022 20:12:04 +0200 (CEST) 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 UUC-Lzntc9zF; Sun, 10 Apr 2022 20:12:03 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 1B56EE6937; Sun, 10 Apr 2022 20:12:03 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Apr 2022 20:12:00 +0200 Message-Id: <20220410181200.3181-2-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220410181200.3181-1-cus@passwd.hu> References: <20220410181200.3181-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avutil/timecode: use timecode fps for number of frame digits 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /9eKrH3qNxqi Signed-off-by: Marton Balint --- libavutil/timecode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index a37d725fc7..b93f05b4b8 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -104,7 +104,7 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum) { int fps = tc->fps; int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME; - int hh, mm, ss, ff, neg = 0; + int hh, mm, ss, ff, ff_len, neg = 0; framenum += tc->start; if (drop) @@ -119,9 +119,10 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum) hh = framenum / (fps*3600LL); if (tc->flags & AV_TIMECODE_FLAG_24HOURSMAX) hh = hh % 24; - snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d", + ff_len = fps > 10000 ? 5 : fps > 1000 ? 4 : fps > 100 ? 3 : fps > 10 ? 2 : 1; + snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%0*d", neg ? "-" : "", - hh, mm, ss, drop ? ';' : ':', ff); + hh, mm, ss, drop ? ';' : ':', ff_len, ff); return buf; }