From: Michael Niedermayer via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Michael Niedermayer <michael@niedermayer.cc> Subject: [FFmpeg-devel] Re: [PATCH 4/7] 32-bit timecode to 64-bit RFC 5484 timecode functions Date: Sat, 13 Sep 2025 13:11:44 +0200 Message-ID: <20250913111144.GF29660@pb2> (raw) In-Reply-To: <9c3941f4-5b79-4a49-8842-f8eaecceee7a@mediaarea.net> [-- Attachment #1.1: Type: text/plain, Size: 6308 bytes --] On Tue, Sep 09, 2025 at 02:40:50PM +0200, Jerome Martinez via ffmpeg-devel wrote: > timecode.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > timecode.h | 22 ++++++++++++ > 2 files changed, 126 insertions(+) > 8969dd4cc3cc1d77acde18a6eae065e9413757b2 0004-32-bit-timecode-to-64-bit-RFC-5484-timecode-function.patch > >From 36cc44569a898c8401944bc16b791632fd4ac985 Mon Sep 17 00:00:00 2001 > From: Dave Rice <dave at dericed.com> > 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 uf is limited to 0..9 it doesnt need &0xf > + 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 us is limited to 0..9 it doesnt need &0xf > + 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 same > + 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 same > + 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; > +} should some of these functions have checks on the input being valid ? or is such a check harmfull ? or already done elsewhere ? thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt. [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 163 bytes --] _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next prev parent reply other threads:[~2025-09-13 11:12 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-09-09 12:37 [FFmpeg-devel] [PATCH 0/7] matroska: support of timecode Jerome Martinez via ffmpeg-devel 2025-09-09 12:38 ` [FFmpeg-devel] [PATCH 1/7] matroskaenc: remove unused MaxBlockAdditionID Jerome Martinez via ffmpeg-devel 2025-09-12 14:52 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel 2025-09-12 14:57 ` James Almer via ffmpeg-devel 2025-09-09 12:39 ` [FFmpeg-devel] [PATCH 2/7] matroskaenc: reserve_video_track_space option Jerome Martinez via ffmpeg-devel 2025-09-09 12:39 ` [FFmpeg-devel] [PATCH 3/7] matroskaenc: increase default for reserved bytes in video Jerome Martinez via ffmpeg-devel 2025-09-09 12:40 ` [FFmpeg-devel] [PATCH 4/7] 32-bit timecode to 64-bit RFC 5484 timecode functions Jerome Martinez via ffmpeg-devel 2025-09-13 11:11 ` Michael Niedermayer via ffmpeg-devel [this message] 2025-09-09 12:41 ` [FFmpeg-devel] [PATCH 5/7] decklink_dec: store timecode in 64-bit RFC 5484 format Jerome Martinez via ffmpeg-devel 2025-09-09 12:41 ` [FFmpeg-devel] [PATCH 6/7] matroskadec: read timecode in BlockAddition Jerome Martinez via ffmpeg-devel 2025-09-13 11:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel 2025-09-09 12:41 ` [FFmpeg-devel] [PATCH 7/7] matroskaenc: write " Jerome Martinez via ffmpeg-devel 2025-09-11 15:52 ` [FFmpeg-devel] Re: [PATCH 0/7] matroska: support of timecode Dave Rice via ffmpeg-devel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250913111144.GF29660@pb2 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=michael@niedermayer.cc \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git