Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Timo Rothenpieler <timo@rothenpieler.org>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte
Date: Sun, 2 Mar 2025 13:32:17 +0100
Message-ID: <c85bd913-1c23-4cf5-ad40-399c88ce6ef5@rothenpieler.org> (raw)
In-Reply-To: <20250228224640.30747-1-timo@rothenpieler.org>

On 28.02.2025 23:46, Timo Rothenpieler wrote:
> ---
>   libavutil/timecode.c          | 27 +++----------------
>   libavutil/timecode_internal.c | 51 +++++++++++++++++++++++++++++++++++
>   libavutil/timecode_internal.h | 51 +++++++++++++++++++++++++++++++++++
>   3 files changed, 105 insertions(+), 24 deletions(-)
>   create mode 100644 libavutil/timecode_internal.c
>   create mode 100644 libavutil/timecode_internal.h
> 
> diff --git a/libavutil/timecode.c b/libavutil/timecode.c
> index f454466f97..bca16b6ac2 100644
> --- a/libavutil/timecode.c
> +++ b/libavutil/timecode.c
> @@ -29,6 +29,7 @@
>   #include <stdio.h>
>   #include "common.h"
>   #include "timecode.h"
> +#include "timecode_internal.h"
>   #include "log.h"
>   #include "error.h"
>   
> @@ -127,32 +128,10 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg)
>       return buf;
>   }
>   
> -static unsigned bcd2uint(uint8_t bcd)
> -{
> -   unsigned low  = bcd & 0xf;
> -   unsigned high = bcd >> 4;
> -   if (low > 9 || high > 9)
> -       return 0;
> -   return low + 10*high;
> -}
> -
>   char *av_timecode_make_smpte_tc_string2(char *buf, AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
>   {
> -    unsigned hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
> -    unsigned mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
> -    unsigned ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds
> -    unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
> -    unsigned drop = tcsmpte & 1<<30 && !prevent_df;  // 1-bit drop if not arbitrary bit
> -
> -    if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
> -        ff <<= 1;
> -        if (!skip_field) {
> -            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
> -                ff += !!(tcsmpte & 1 << 7);
> -            else
> -                ff += !!(tcsmpte & 1 << 23);
> -        }
> -    }
> +    unsigned hh, mm, ss, ff, drop;
> +    ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tcsmpte, prevent_df, skip_field);
>   
>       snprintf(buf, AV_TIMECODE_STR_SIZE, "%02u:%02u:%02u%c%02u",
>                hh, mm, ss, drop ? ';' : ':', ff);
> diff --git a/libavutil/timecode_internal.c b/libavutil/timecode_internal.c
> new file mode 100644
> index 0000000000..259ebf1664
> --- /dev/null
> +++ b/libavutil/timecode_internal.c
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
> + * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "timecode_internal.h"
> +
> +static unsigned bcd2uint(uint8_t bcd)
> +{
> +   unsigned low  = bcd & 0xf;
> +   unsigned high = bcd >> 4;
> +   if (low > 9 || high > 9)
> +       return 0;
> +   return low + 10*high;
> +}
> +
> +void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff,
> +                           AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field)
> +{
> +    *hh   = bcd2uint(tcsmpte     & 0x3f);    // 6-bit hours
> +    *mm   = bcd2uint(tcsmpte>>8  & 0x7f);    // 7-bit minutes
> +    *ss   = bcd2uint(tcsmpte>>16 & 0x7f);    // 7-bit seconds
> +    *ff   = bcd2uint(tcsmpte>>24 & 0x3f);    // 6-bit frames
> +    *drop = tcsmpte & 1<<30 && !prevent_df;  // 1-bit drop if not arbitrary bit
> +
> +    if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
> +        *ff <<= 1;
> +        if (!skip_field) {
> +            if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
> +                *ff += !!(tcsmpte & 1 << 7);
> +            else
> +                *ff += !!(tcsmpte & 1 << 23);
> +        }
> +    }
> +}
> diff --git a/libavutil/timecode_internal.h b/libavutil/timecode_internal.h
> new file mode 100644
> index 0000000000..8ef43d1f98
> --- /dev/null
> +++ b/libavutil/timecode_internal.h
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright (c) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
> + * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file
> + * Timecode helpers header
> + */
> +
> +#ifndef AVUTIL_TIMECODE_INTERNAL_H
> +#define AVUTIL_TIMECODE_INTERNAL_H
> +
> +#include <stdint.h>
> +#include "rational.h"
> +
> +/**
> + * Convert SMPTE 12M binary representation to sei info.
> + *
> + * @param drop       drop flag output
> + * @param hh         hour output
> + * @param mm         minute output
> + * @param ss         second output
> + * @param ff         frame number output
> + * @param rate       frame rate of the timecode
> + * @param tcsmpte    the 32-bit SMPTE timecode
> + * @param prevent_df prevent the use of a drop flag when it is known the DF bit
> + *                   is arbitrary
> + * @param skip_field prevent the use of a field flag when it is known the field
> + *                   bit is arbitrary (e.g. because it is used as PC flag)
> + */
> +void ff_timecode_set_smpte(unsigned *drop, unsigned *hh, unsigned *mm, unsigned *ss, unsigned *ff,
> +                           AVRational rate, uint32_t tcsmpte, int prevent_df, int skip_field);
> +
> +#endif /* AVUTIL_TIMECODE_INTERNAL_H */

will apply the series soon if nobody objects
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-03-02 12:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 22:46 Timo Rothenpieler
2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 2/3] avcodec/utils: use new ff_timecode_set_smpte function Timo Rothenpieler
2025-02-28 22:49   ` Timo Rothenpieler
2025-02-28 22:46 ` [FFmpeg-devel] [PATCH v2 3/3] avcodec/nvenc: add time code writing for h264 Timo Rothenpieler
2025-03-02 12:32 ` Timo Rothenpieler [this message]
2025-03-02 17:56   ` [FFmpeg-devel] [PATCH v2 1/3] avutil/timecode: add ff_timecode_set_smpte Timo Rothenpieler

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=c85bd913-1c23-4cf5-ad40-399c88ce6ef5@rothenpieler.org \
    --to=timo@rothenpieler.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /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