From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 761BB4C5F9 for ; Tue, 9 Sep 2025 12:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1757421661; h=message-id : date : mime-version : to : references : in-reply-to : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=9DUeiF15HIWPUT2XxpfDFd5vORcNqr+avn9PhdChYmM=; b=glj5TV7pHJKIQV7hj4LZrCg/Y4bhXFOYs4ikHWWTB1dTmhbsVE0v/NICanmGCMBObTyfg Xn3pAnOcNUo38IT8C74RlYJKBvB2Sqko6m+cgT1Z/LTbQy1dwGs2zTkk4n0QtUTypTXGbmv Us8NcaPbuFJgIwkNHGo5NOM2AtGxREf1cef8b6pIPo7CseDdP9c0tRCfufDkWKdWu7m8ews knoghrek7hCpm2SzsDm3wzghm7gByB4EfXe9ID07qhlEiL8bGye+qPDOrjzIXJ1hX5KqFgW VWeSsZMqAEExhx3sPPwBVKyc7j3AgUsKFe9UXmDc9sA/iw3BLIVDH64sZz2w== Received: from [172.19.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 7D03668E790; Tue, 9 Sep 2025 15:41:01 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1757421660; b=r65jiOqggjTtmgdOx1so7H890ExsPpY+B+0ej5pbY2gaP9OeSG1zSxXVKYQHk8rZVuabM mw/BW4d1OiVgvC9+RYJVBOP46m4EnlNI0xjpPF9cKNbyq4RtvtqR7hceDpxupuVZA6rcAMf Kp1DJAkmGiQXM0a3YXlPlluico3+99s7kXTpkmhwqcWOIiTp68subc0yA00KXe3eqRzezH0 hk0jugafvkRGX77P/tLayCO9Sv5Vj7e2ZuVL1rQ6m5Tg33orDtK8xxmBlOcj0AOVKdShHHf weNDYxO8ZQ/ZWVUo0luk5ziEBG8RHnQCGis5GxMqX4Uczw+NSCtZwh3BAsBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1757421660; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=pD1R4GQ/C+1d52pk7ULmrV6945WqNetM1fBcSCi5I0U=; b=IAfzAq1JpKCToWnL7+lvwTZhtKCg/rWMtIQK8vMhQSoSRXsLaxon/RyQY8Q71u4+6mNx9 ewJHVaZdXQnJt79DGwnCaiR2p4ILBlcE5Qc+wKlA6QATVu6mByOTrxxhl2y76OumJLMutY9 1jO7RMA9rN8dcxcj4hfyYujpCRV1mNrIbDRdSAZNRjjms9lwnDxjdQiMq1WHFWBaGwl9gaq 8dJdiLERuGkfhzwvNkRBPQ+kMH13LR4s7iUulrLC0FIXKSDFOYoDXZqE0VcFhLKYsZmXhHO xSxaufr8jdSvWrh/Srhbxs548lCvxXB/57Js9F8413asDnbzqE+yybMQYa9Q== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=fail; arc=none; dmarc=fail header.from=mediaarea.net policy.dmarc=none Authentication-Results: ffmpeg.org; dkim=fail; arc=none (Message is not ARC signed); dmarc=fail (Used From Domain Record) header.from=mediaarea.net policy.dmarc=none Received: from 1.mo584.mail-out.ovh.net (1.mo584.mail-out.ovh.net [178.33.248.196]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 9DA9E68E789 for ; Tue, 9 Sep 2025 15:40:53 +0300 (EEST) Received: from director2.ghost.mail-out.ovh.net (unknown [10.110.43.45]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 4cLk2D5mDzz8HPN for ; Tue, 9 Sep 2025 12:40:52 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-hmnsz (unknown [10.110.178.131]) by director2.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 73E54C0E01 for ; Tue, 9 Sep 2025 12:40:52 +0000 (UTC) Received: from mediaarea.net ([37.59.142.102]) by ghost-submission-5b5ff79f4f-hmnsz with ESMTPSA id zxgNEVQgwGgGvAAAkXM58w (envelope-from ) for ; Tue, 09 Sep 2025 12:40:52 +0000 X-OVh-ClientIp: 84.143.147.172 Message-ID: <9c3941f4-5b79-4a49-8842-f8eaecceee7a@mediaarea.net> Date: Tue, 9 Sep 2025 14:40:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: Content-Language: fr In-Reply-To: X-Ovh-Tracer-Id: 2329486908387330297 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvtdeggecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsehmtderredtvdejnecuhfhrohhmpeflvghrohhmvgcuofgrrhhtihhnvgiiuceojhgvrhhomhgvsehmvgguihgrrghrvggrrdhnvghtqeenucggtffrrghtthgvrhhnpeegveffhffgfeehkeffteffueevieehhfehjeeftdeglefgleetieejheffffduueenucfkphepuddvjedrtddrtddruddpkeegrddugeefrddugeejrddujedvpdefjedrheelrddugedvrddutddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehjvghrohhmvgesmhgvughirggrrhgvrgdrnhgvthdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhgpdfovfetjfhoshhtpehmohehkeegmgdpmhhouggvpehsmhhtphhouhht Message-ID-Hash: R3EHW455WXLTISOXZ567NPRS2XINMZ2V X-Message-ID-Hash: R3EHW455WXLTISOXZ567NPRS2XINMZ2V X-MailFrom: SRS0=HT8a=3U=mediaarea.net=jerome@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header Content-Disposition: attachment; filename*0="0004-32-bit-timecode-to-64-bit-RFC-5484-timecode-function.pa"; filename*1="tch" X-Content-Filtered-By: Mailman/MimeDel 3.3.10 X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH 4/7] 32-bit timecode to 64-bit RFC 5484 timecode functions List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jerome Martinez via ffmpeg-devel Cc: Jerome Martinez Content-Type: text/plain; charset="us-ascii"; name="0004-32-bit-timecode-to-64-bit-RFC-5484-timecode-function.patch" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: >>From 36cc44569a898c8401944bc16b791632fd4ac985 Mon Sep 17 00:00:00 2001 From: Dave Rice Date: Mon, 30 Jun 2025 00:00:00 +0200 Subject: [PATCH 4/7] 32-bit timecode to 64-bit RFC 5484 timecode functions --- libavutil/timecode.c | 104 +++++++++++++++++++++++++++++++++++++++++++ libavutil/timecode.h | 22 +++++++++ 2 files changed, 126 insertions(+) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index bca16b6ac2..81fb66a5e4 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -243,3 +243,107 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st return av_timecode_init_from_components(tc, rate, flags, hh, mm, ss, ff, log_ctx); } + +static int bcd_to_int(int bcd) { + return ((bcd >> 4) & 0xF) * 10 + (bcd & 0xF); +} + +uint64_t av_timecode_expand_to_64bit(uint32_t tc32) +{ + uint64_t tc64 = 0; + + int hours_bcd = tc32 & 0x3F; // bits 0-5 + int bgf1 = (tc32 >> 6) & 0x1; // bit 6 + int bgf2 = (tc32 >> 7) & 0x1; // bit 7 + int minutes_bcd = (tc32 >> 8) & 0x7F; // bits 8-14 + int bgf0 = (tc32 >> 15) & 0x1; // bit 15 + int seconds_bcd = (tc32 >> 16) & 0x7F; // bits 16-22 + int frames_bcd = (tc32 >> 24) & 0x3F; // bits 24-29 + int drop = (tc32 >> 30) & 0x1; // bit 30 + int color = (tc32 >> 31) & 0x1; // bit 31 + + int hours = bcd_to_int(hours_bcd); + int minutes = bcd_to_int(minutes_bcd); + int seconds = bcd_to_int(seconds_bcd); + int frames = bcd_to_int(frames_bcd); + + // Units and tens + int uh = hours % 10, th = hours / 10; + int um = minutes % 10, tm = minutes / 10; + int us = seconds % 10, ts = seconds / 10; + int uf = frames % 10, tf = frames / 10; + + // Assign bits as per RFC 5484 layout + tc64 |= (uint64_t)(uf & 0xF) << 0; // Units of frames + tc64 |= 0 << 4; // First binary group + tc64 |= (uint64_t)(tf & 0x3) << 8; // Tens of frames (2 bits) + tc64 |= (uint64_t)drop << 10; // Drop frame flag + tc64 |= (uint64_t)color << 11; // Color frame flag + tc64 |= 0 << 12; // Second binary group + + tc64 |= (uint64_t)(us & 0xF) << 16; // Units of seconds + tc64 |= 0 << 20; // Third binary group + tc64 |= (uint64_t)(ts & 0x7) << 24; // Tens of seconds + tc64 |= 0 << 27; // Polarity correction + tc64 |= 0 << 28; // Fourth binary group + + tc64 |= (uint64_t)(um & 0xF) << 32; // Units of minutes + tc64 |= (uint64_t)0 << 36; // Fifth binary group + tc64 |= (uint64_t)(tm & 0x7) << 40; // Tens of minutes + tc64 |= (uint64_t)bgf0 << 43; // BGF0 + tc64 |= (uint64_t)0 << 44; // Sixth binary group + + tc64 |= (uint64_t)(uh & 0xF) << 48; // Units of hours + tc64 |= (uint64_t)0 << 52; // Seventh binary group + tc64 |= (uint64_t)(th & 0x3) << 56; // Tens of hours + tc64 |= (uint64_t)bgf1 << 58; // BGF1 + tc64 |= (uint64_t)bgf2 << 59; // BGF2 + tc64 |= (uint64_t)0 << 60; // Eighth binary group + + return tc64; +} + +static int int_to_bcd(int val) { + return ((val / 10) << 4) | (val % 10); +} + +uint32_t av_timecode_parse_from_64bit(uint64_t tc64) +{ + uint32_t tc32 = 0; + + int uf = (tc64 >> 0) & 0xF; // Ones of frames + int tf = (tc64 >> 8) & 0x3; // Tens of frames + int drop = (tc64 >> 10) & 0x1; + int color= (tc64 >> 11) & 0x1; + + int us = (tc64 >> 16) & 0xF; // Ones of seconds + int ts = (tc64 >> 24) & 0x7; // Tens of seconds + + int um = (tc64 >> 32) & 0xF; // Ones of minutes + int tm = (tc64 >> 40) & 0x7; // Tens of minutes + int bgf0 = (tc64 >> 43) & 0x1; + + int uh = (tc64 >> 48) & 0xF; // Ones of hours + int th = (tc64 >> 56) & 0x3; // Tens of hours + int bgf1 = (tc64 >> 58) & 0x1; + int bgf2 = (tc64 >> 59) & 0x1; + + int hours = int_to_bcd(th * 10 + uh); + int minutes = int_to_bcd(tm * 10 + um); + int seconds = int_to_bcd(ts * 10 + us); + int frames = int_to_bcd(tf * 10 + uf); + + // Assemble tc32 using the FFmpeg SMPTE 32-bit format + tc32 |= (hours & 0x3F) << 0; // bits 0-5: hours (BCD) + tc32 |= (bgf1 & 0x1) << 6; // bit 6: BGF1 + tc32 |= (bgf2 & 0x1) << 7; // bit 7: BGF2 (or FIELD) + tc32 |= (minutes & 0x7F) << 8; // bits 8-14: minutes (BCD) + tc32 |= (bgf0 & 0x1) << 15; // bit 15: BGF0 + tc32 |= (seconds & 0x7F) << 16; // bits 16-22: seconds (BCD) + tc32 |= 0 << 23; // bit 23: FIELD (set to 0) + tc32 |= (frames & 0x3F) << 24; // bits 24-29: frames (BCD) + tc32 |= (drop & 0x1) << 30; // bit 30: drop frame flag + tc32 |= (color & 0x1) << 31; // bit 31: color frame flag + + return tc32; +} diff --git a/libavutil/timecode.h b/libavutil/timecode.h index fe0fc83576..81713a9adf 100644 --- a/libavutil/timecode.h +++ b/libavutil/timecode.h @@ -196,4 +196,26 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st */ int av_timecode_check_frame_rate(AVRational rate); +/** + * Convert a 32-bit SMPTE 12M timecode to 64-bit SMPTE 12M/RFC 5484 format. + * + * This maps the timecode as described in RFC 5484 Section 6.2, + * expanding BCD-encoded time values into bit fields without the sync word. + * + * @param tc32 The 32-bit SMPTE timecode (from DeckLink or av_timecode_get_smpte) + * @return The 64-bit SMPTE 12M timecode format (without sync word) + */ +uint64_t av_timecode_expand_to_64bit(uint32_t tc32); + +/** + * Convert a 64-bit SMPTE 12M/RFC 5484 timecode to 32-bit SMPTE format. + * + * This reconstructs the packed 32-bit SMPTE timecode (DeckLink-style or FFmpeg output) + * from a full 64-bit representation. + * + * @param tc64 The 64-bit timecode value in RFC 5484 / SMPTE 12M format (without sync word) + * @return A 32-bit SMPTE timecode + */ +uint32_t av_timecode_parse_from_64bit(uint64_t tc64); + #endif /* AVUTIL_TIMECODE_H */ -- 2.46.0.windows.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org