ffmpeg | branch: master | Timo Rothenpieler <t...@rothenpieler.org> | Sun Feb 23 00:53:09 2025 +0100| [9d5d51bd129cfb7cdb085aa4b474711d4a777735] | committer: Timo Rothenpieler
avutil/timecode: add ff_timecode_set_smpte > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9d5d51bd129cfb7cdb085aa4b474711d4a777735 --- libavutil/Makefile | 1 + libavutil/timecode.c | 27 +++-------------------- libavutil/timecode_internal.c | 51 +++++++++++++++++++++++++++++++++++++++++++ libavutil/timecode_internal.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 24 deletions(-) diff --git a/libavutil/Makefile b/libavutil/Makefile index b2b3b9c156..aea10ba635 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -180,6 +180,7 @@ OBJS = adler32.o \ threadmessage.o \ time.o \ timecode.o \ + timecode_internal.o \ timestamp.o \ tree.o \ twofish.o \ 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.coudur...@gmail.com> + * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boe...@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.coudur...@gmail.com> + * Copyright (c) 2011-2012 Smartjog S.A.S, Clément Bœsch <clement.boe...@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 */ _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".