New timecode API attempt
Hi, The main changes since last time: - use of av_timecode_ prefix for all the functions - use of AV_TIMECODE_ for cpp related - regression tests; at the beginning of the patchset so we can check if the patchset doesn't break anything. The most sensible patches are the first one, and mpeg12enc, dv and mxf patches. Since this is somehow a bit too much changes, I can wait until we release 0.10. Any comment on the API is still appreciate. Baptiste, anything to add?
From: Clément Bœsch <clement.boesch@smartjog.com> --- tests/lavf-regression.sh | 34 ++++++++++++++++++++++++++++++---- tests/ref/lavf/dv_fmt | 4 ++++ tests/ref/lavf/gxf | 4 ++++ tests/ref/lavf/mov | 4 ++++ tests/ref/lavf/mpg | 4 ++++ tests/ref/lavf/mxf | 6 +++++- 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index af34e86..56029a4 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -13,13 +13,35 @@ eval do_$test=y ENC_OPTS="$ENC_OPTS -metadata title=lavftest" -do_lavf() +do_lavf_nocrc() { file=${outfile}lavf.$1 do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 +} + +do_lavf() +{ + do_lavf_nocrc "$@" do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 } +do_lavf_timecode_nodrop() +{ + do_lavf_nocrc $1 "$2 -timecode 02:56:14:13" "$3" +} + +do_lavf_timecode_drop() +{ + do_lavf_nocrc $1 "$2 -timecode 02:56:14;13 -r 30000/1001" "$3" +} + +do_lavf_timecode() +{ + do_lavf "$@" + do_lavf_timecode_nodrop "$@" + do_lavf_timecode_drop "$@" +} + do_streamed_images() { file=${outfile}${1}pipe.$1 @@ -61,11 +83,11 @@ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 441 fi if [ -n "$do_mpg" ] ; then -do_lavf mpg "-ab 64k" +do_lavf_timecode mpg "-ab 64k" fi if [ -n "$do_mxf" ] ; then -do_lavf mxf "-ar 48000 -bf 2 -timecode 02:56:14:13" +do_lavf_timecode mxf "-ar 48000 -bf 2" fi if [ -n "$do_mxf_d10" ]; then @@ -89,15 +111,19 @@ do_lavf flv -an fi if [ -n "$do_mov" ] ; then -do_lavf mov "-acodec pcm_alaw -vcodec mpeg4" +do_lavf_timecode mov "-acodec pcm_alaw -vcodec mpeg4" fi if [ -n "$do_dv_fmt" ] ; then do_lavf dv "-ar 48000 -r 25 -s pal -ac 2" +do_lavf_timecode_nodrop dv "-ar 48000 -r 25 -s pal -ac 2" +do_lavf_timecode_drop dv "-ar 48000 -pix_fmt yuv411p -s ntsc -ac 2" fi if [ -n "$do_gxf" ] ; then do_lavf gxf "-ar 48000 -r 25 -s pal -ac 1" +do_lavf_timecode_nodrop gxf "-ar 48000 -r 25 -s pal -ac 1" +do_lavf_timecode_drop gxf "-ar 48000 -s ntsc -ac 1" fi if [ -n "$do_nut" ] ; then diff --git a/tests/ref/lavf/dv_fmt b/tests/ref/lavf/dv_fmt index ded1cee..b8a5926 100644 --- a/tests/ref/lavf/dv_fmt +++ b/tests/ref/lavf/dv_fmt @@ -1,3 +1,7 @@ 3a6a9163a67b729b4a6b5d972ccceb97 *./tests/data/lavf/lavf.dv 3600000 ./tests/data/lavf/lavf.dv ./tests/data/lavf/lavf.dv CRC=0x5ce4e5e4 +6f9cfff48f536fa727696f2f9fb3ac08 *./tests/data/lavf/lavf.dv +3600000 ./tests/data/lavf/lavf.dv +cc33ae4f9e6828914dea0f09d1241b7e *./tests/data/lavf/lavf.dv +3480000 ./tests/data/lavf/lavf.dv diff --git a/tests/ref/lavf/gxf b/tests/ref/lavf/gxf index 57839c9..0357cdc 100644 --- a/tests/ref/lavf/gxf +++ b/tests/ref/lavf/gxf @@ -1,3 +1,7 @@ 1c1693cf2358025f1e37ac76e1da925a *./tests/data/lavf/lavf.gxf 796392 ./tests/data/lavf/lavf.gxf ./tests/data/lavf/lavf.gxf CRC=0x102918fd +befc1a39c37a4ecd9264942a3e34b3f6 *./tests/data/lavf/lavf.gxf +796392 ./tests/data/lavf/lavf.gxf +267d2b2b6e357209d76c366302cf35c3 *./tests/data/lavf/lavf.gxf +794572 ./tests/data/lavf/lavf.gxf diff --git a/tests/ref/lavf/mov b/tests/ref/lavf/mov index 619489c..9cac1fb 100644 --- a/tests/ref/lavf/mov +++ b/tests/ref/lavf/mov @@ -1,3 +1,7 @@ 9a0b239ff596da58debcf210dece3985 *./tests/data/lavf/lavf.mov 357821 ./tests/data/lavf/lavf.mov ./tests/data/lavf/lavf.mov CRC=0x2f6a9b26 +9a0b239ff596da58debcf210dece3985 *./tests/data/lavf/lavf.mov +357821 ./tests/data/lavf/lavf.mov +cea874222a6d40b1761d75ea11ebe681 *./tests/data/lavf/lavf.mov +367251 ./tests/data/lavf/lavf.mov diff --git a/tests/ref/lavf/mpg b/tests/ref/lavf/mpg index b81cb8a..ebca0cc 100644 --- a/tests/ref/lavf/mpg +++ b/tests/ref/lavf/mpg @@ -1,3 +1,7 @@ dd60652c2193670abffb8c2a123a820e *./tests/data/lavf/lavf.mpg 372736 ./tests/data/lavf/lavf.mpg ./tests/data/lavf/lavf.mpg CRC=0xf361ed74 +6103dbae73aec6c9bf05bbbc6ea35f89 *./tests/data/lavf/lavf.mpg +372736 ./tests/data/lavf/lavf.mpg +91b42dd3352e21dd0dee57f6a7241ca2 *./tests/data/lavf/lavf.mpg +387072 ./tests/data/lavf/lavf.mpg diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf index 73eb307..49e61a8 100644 --- a/tests/ref/lavf/mxf +++ b/tests/ref/lavf/mxf @@ -1,3 +1,7 @@ +c78207030d57b48295b089916849d50d *./tests/data/lavf/lavf.mxf +525881 ./tests/data/lavf/lavf.mxf +./tests/data/lavf/lavf.mxf CRC=0x4ace0849 785e38ddd2466046f30aa36399b8f8fa *./tests/data/lavf/lavf.mxf 525881 ./tests/data/lavf/lavf.mxf -./tests/data/lavf/lavf.mxf CRC=0x4ace0849 \ No newline at end of file +ccaa42c75e653f71604fd28c7c83722d *./tests/data/lavf/lavf.mxf +537657 ./tests/data/lavf/lavf.mxf -- 1.7.8.3
On date Monday 2012-01-23 17:04:20 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- tests/lavf-regression.sh | 34 ++++++++++++++++++++++++++++++---- tests/ref/lavf/dv_fmt | 4 ++++ tests/ref/lavf/gxf | 4 ++++ tests/ref/lavf/mov | 4 ++++ tests/ref/lavf/mpg | 4 ++++ tests/ref/lavf/mxf | 6 +++++- 6 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index af34e86..56029a4 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -13,13 +13,35 @@ eval do_$test=y
ENC_OPTS="$ENC_OPTS -metadata title=lavftest"
-do_lavf() +do_lavf_nocrc() { file=${outfile}lavf.$1 do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 +} +
+do_lavf() +{ + do_lavf_nocrc "$@" do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 }
I'm not sure why you don't want do_crc with timecodes. Alternatively you may check on the presence of the third parameter (e.g. with [-n $3]) and compute CRC only in that case.
+do_lavf_timecode_nodrop() +{ + do_lavf_nocrc $1 "$2 -timecode 02:56:14:13" "$3" +} + +do_lavf_timecode_drop() +{ + do_lavf_nocrc $1 "$2 -timecode 02:56:14;13 -r 30000/1001" "$3" +}
Here the $3 is ignored if I'm not wrong. [...] Looks fine otherwise. -- FFmpeg = Faithful Fundamentalist Minimalistic Ponderous Eretic Game
On Tue, Jan 24, 2012 at 01:38:47PM +0100, Stefano Sabatini wrote:
On date Monday 2012-01-23 17:04:20 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- tests/lavf-regression.sh | 34 ++++++++++++++++++++++++++++++---- tests/ref/lavf/dv_fmt | 4 ++++ tests/ref/lavf/gxf | 4 ++++ tests/ref/lavf/mov | 4 ++++ tests/ref/lavf/mpg | 4 ++++ tests/ref/lavf/mxf | 6 +++++- 6 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index af34e86..56029a4 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -13,13 +13,35 @@ eval do_$test=y
ENC_OPTS="$ENC_OPTS -metadata title=lavftest"
-do_lavf() +do_lavf_nocrc() { file=${outfile}lavf.$1 do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 +} +
+do_lavf() +{ + do_lavf_nocrc "$@" do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 }
I'm not sure why you don't want do_crc with timecodes.
Well actually the CRC looked the same as long as I don't play with the rate. Do you think it's worth keeping them? It's slowing down the tests quite a bit if I do so, and I'm not sure they are actually useful in this case. [...] -- Clément B.
On Wed, Jan 25, 2012 at 05:42:39PM +0100, Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:38:47PM +0100, Stefano Sabatini wrote:
On date Monday 2012-01-23 17:04:20 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- tests/lavf-regression.sh | 34 ++++++++++++++++++++++++++++++---- tests/ref/lavf/dv_fmt | 4 ++++ tests/ref/lavf/gxf | 4 ++++ tests/ref/lavf/mov | 4 ++++ tests/ref/lavf/mpg | 4 ++++ tests/ref/lavf/mxf | 6 +++++- 6 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index af34e86..56029a4 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -13,13 +13,35 @@ eval do_$test=y
ENC_OPTS="$ENC_OPTS -metadata title=lavftest"
-do_lavf() +do_lavf_nocrc() { file=${outfile}lavf.$1 do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 +} +
+do_lavf() +{ + do_lavf_nocrc "$@" do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 }
I'm not sure why you don't want do_crc with timecodes.
Well actually the CRC looked the same as long as I don't play with the rate. Do you think it's worth keeping them? It's slowing down the tests quite a bit if I do so, and I'm not sure they are actually useful in this case.
New simplified patch, with the CRC. Also reordered the tests so do_lavf is the last one (the file is re-used for seeking tests later). -- Clément B.
From: Clément Bœsch <clement.boesch@smartjog.com> --- doc/APIchanges | 3 + libavutil/Makefile | 2 + libavutil/avutil.h | 4 +- libavutil/timecode.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavutil/timecode.h | 125 ++++++++++++++++++++++++++++++++++++ 5 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 libavutil/timecode.c create mode 100644 libavutil/timecode.h diff --git a/doc/APIchanges b/doc/APIchanges index 9359162..4198fef 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-01-xx - xxxxxxx - lavu 51.35.100 + Add public timecode helpers. + 2012-01-15 - lavc 53.34.0 New audio encoding API: b2c75b6 Add CODEC_CAP_VARIABLE_FRAME_SIZE capability for use by audio diff --git a/libavutil/Makefile b/libavutil/Makefile index b6165a1..a93e563 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -36,6 +36,7 @@ HEADERS = adler32.h \ rational.h \ samplefmt.h \ sha.h \ + timecode.h \ BUILT_HEADERS = avconfig.h @@ -70,6 +71,7 @@ OBJS = adler32.o \ rc4.o \ samplefmt.o \ sha.o \ + timecode.o \ tree.o \ utils.o \ diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 3f77262..99af12d 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -154,8 +154,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 34 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 35 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ diff --git a/libavutil/timecode.c b/libavutil/timecode.c new file mode 100644 index 0000000..8ce9394 --- /dev/null +++ b/libavutil/timecode.c @@ -0,0 +1,174 @@ +/* + * 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 + * A few references: + * https://en.wikipedia.org/wiki/SMPTE_time_code + * http://www.dropframetimecode.org + */ + +#include <stdio.h> +#include "timecode.h" +#include "log.h" +#include "error.h" + +int av_timecode_adjust_ntsc_framenum(int framenum) +{ + /* only works for NTSC 29.97 */ + int d = framenum / 17982; + int m = framenum % 17982; + //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */ + return framenum + 18 * d + 2 * ((m - 2) / 1798); +} + +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum) +{ + unsigned fps = tc->fps; + int drop = !!(tc->flags & AV_TIMECODE_FLAG_DROPFRAME); + int hh, mm, ss, ff; + + framenum += tc->start; + if (drop) + framenum = av_timecode_adjust_ntsc_framenum(framenum); + ff = framenum % fps; + ss = framenum / fps % 60; + mm = framenum / (fps*60) % 60; + hh = framenum / (fps*3600) % 24; + return 0 << 31 | // color frame flag + drop << 30 | // drop frame flag + (ff / 10) << 28 | // tens of frames + (ff % 10) << 24 | // units of frames + 0 << 23 | // field phase (NTSC), b0 (PAL) + (ss / 10) << 20 | // tens of seconds + (ss % 10) << 16 | // units of seconds + 0 << 15 | // b0 (NTSC), b2 (PAL) + (mm / 10) << 12 | // tens of minutes + (mm % 10) << 8 | // units of minutes + 0 << 7 | // b1 + 0 << 6 | // b2 (NTSC), field phase (PAL) + (hh / 10) << 4 | // tens of hours + (hh % 10); // units of hours +} + +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum) +{ + int fps = tc->fps; + int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME; + int hh, mm, ss, ff, neg = 0; + + framenum += tc->start; + if (drop) + framenum = av_timecode_adjust_ntsc_framenum(framenum); + if (framenum < 0) { + framenum = -framenum; + neg = tc->flags & AV_TIMECODE_FLAG_ALLOWNEGATIVE; + } + ff = framenum % fps; + ss = framenum / fps % 60; + mm = framenum / (fps*60) % 60; + hh = framenum / (fps*3600); + if (tc->flags & AV_TIMECODE_FLAG_24HOURSMAX) + hh = hh % 24; + snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d", + neg ? "-" : "", + hh, mm, ss, drop ? ';' : ':', ff); + return buf; +} + +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit) +{ + snprintf(buf, AV_TIMECODE_STR_SIZE, "%02d:%02d:%02d%c%02d", + tc25bit>>19 & 0x1f, // hours + tc25bit>>13 & 0x3f, // minutes + tc25bit>>6 & 0x3f, // seconds + tc25bit & 1<<24 ? ';' : ':', // drop + tc25bit & 0x3f); // frames + return buf; +} + +static int check_timecode(void *log_ctx, AVTimecode *tc) +{ + if (tc->fps <= 0) { + av_log(log_ctx, AV_LOG_ERROR, "Timecode frame rate must be specified\n"); + return AVERROR(EINVAL); + } + if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30) { + av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n"); + return AVERROR(EINVAL); + } + switch (tc->fps) { + case 24: + case 25: + case 30: return 0; + + default: + av_log(log_ctx, AV_LOG_ERROR, "Timecode frame rate not supported\n"); + return AVERROR_PATCHWELCOME; + } +} + +static int fps_from_frame_rate(AVRational rate) +{ + if (!rate.den || !rate.num) + return -1; + return (rate.num + rate.den/2) / rate.den; +} + +int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start) +{ + memset(tc, 0, sizeof(*tc)); + tc->start = frame_start; + tc->flags = flags; + tc->rate = rate; + tc->fps = fps_from_frame_rate(rate); + return check_timecode(log_ctx, tc); +} + +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str) +{ + char c; + int hh, mm, ss, ff, ret; + + if (sscanf(str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) { + av_log(log_ctx, AV_LOG_ERROR, "Unable to parse timecode, " + "syntax: hh:mm:ss[:;.]ff\n"); + return AVERROR_INVALIDDATA; + } + + memset(tc, 0, sizeof(*tc)); + tc->flags = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0; // drop if ';', '.', ... + tc->rate = rate; + tc->fps = fps_from_frame_rate(rate); + + ret = check_timecode(log_ctx, tc); + if (ret < 0) + return ret; + + tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff; + if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) { /* adjust frame number */ + int tmins = 60*hh + mm; + tc->start -= 2 * (tmins - tmins/10); + } + return 0; +} + diff --git a/libavutil/timecode.h b/libavutil/timecode.h new file mode 100644 index 0000000..bb9ed58 --- /dev/null +++ b/libavutil/timecode.h @@ -0,0 +1,125 @@ +/* + * 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_H +#define AVUTIL_TIMECODE_H + +#include <stdint.h> +#include "rational.h" + +#define AV_TIMECODE_STR_SIZE 16 + +#define AV_TIMECODE_OPTION(ctx, string_field, flags) \ + "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \ + "use ';' or '.' before frame number for drop frame", \ + offsetof(ctx, string_field), \ + AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags + +enum AVTimecodeFlag { + AV_TIMECODE_FLAG_DROPFRAME = 1<<0, ///< timecode is drop frame + AV_TIMECODE_FLAG_24HOURSMAX = 1<<1, ///< timecode wraps after 24 hours + AV_TIMECODE_FLAG_ALLOWNEGATIVE = 1<<2, ///< negative time values are allowed +}; + +typedef struct { + int start; ///< timecode frame start (first base frame number) + uint32_t flags; ///< flags such as drop frame, +24 hours support, ... + AVRational rate; ///< frame rate in rational form + unsigned fps; ///< frame per second; must be consistent with the rate field +} AVTimecode; + +/** + * Adjust frame number for NTSC drop frame time code. + * + * @param framenum frame number to adjust + * @return adjusted frame number + * @warning adjustment is only valid in NTSC 29.97 + */ +int av_timecode_adjust_ntsc_framenum(int framenum); + +/** + * Convert frame number to SMPTE 12M binary representation. + * + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the SMPTE binary representation + * + * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum(). + * @note The frame number is relative to tc->start. + */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum); + +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + * + * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start. + */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum); + +/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit); + +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str); + +#endif /* AVUTIL_TIMECODE_H */ -- 1.7.8.3
On date Monday 2012-01-23 17:04:21 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- doc/APIchanges | 3 + libavutil/Makefile | 2 + libavutil/avutil.h | 4 +- libavutil/timecode.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavutil/timecode.h | 125 ++++++++++++++++++++++++++++++++++++ 5 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 libavutil/timecode.c create mode 100644 libavutil/timecode.h [...] +/** + * @file + * Timecode helpers header + */ + +#ifndef AVUTIL_TIMECODE_H +#define AVUTIL_TIMECODE_H + +#include <stdint.h> +#include "rational.h" + +#define AV_TIMECODE_STR_SIZE 16 + +#define AV_TIMECODE_OPTION(ctx, string_field, flags) \ + "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \ + "use ';' or '.' before frame number for drop frame", \ + offsetof(ctx, string_field), \ + AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags + +enum AVTimecodeFlag { + AV_TIMECODE_FLAG_DROPFRAME = 1<<0, ///< timecode is drop frame + AV_TIMECODE_FLAG_24HOURSMAX = 1<<1, ///< timecode wraps after 24 hours + AV_TIMECODE_FLAG_ALLOWNEGATIVE = 1<<2, ///< negative time values are allowed +}; + +typedef struct { + int start; ///< timecode frame start (first base frame number) + uint32_t flags; ///< flags such as drop frame, +24 hours support, ... + AVRational rate; ///< frame rate in rational form + unsigned fps; ///< frame per second; must be consistent with the rate field +} AVTimecode; + +/** + * Adjust frame number for NTSC drop frame time code. + * + * @param framenum frame number to adjust + * @return adjusted frame number + * @warning adjustment is only valid in NTSC 29.97 + */ +int av_timecode_adjust_ntsc_framenum(int framenum); +
+/** + * Convert frame number to SMPTE 12M binary representation. + * + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the SMPTE binary representation + *
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
+ * @note The frame number is relative to tc->start.
same here
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons. -- FFmpeg = Frightening and Funny Majestic Puristic Experimenting Generator
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms: @note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx." I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example? [...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
Sorry to Alexander, I think I missed that…
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
I see the make form is used a little in avfilter, but I'm not sure. "make" makes me think of a function returning a sucess or failure after a processing, while get will return what is announced in the function name. "get_" looks fine to me here... Of course, I get the point of the buffer being the destination but well…
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons.
Why? It just initialized the passed struct given a few parameters. It doesn't really build anything. If someone strongly believes in one form over the other, I'll do the necessary; otherwise I'd avoid reworking the whole patchset for this if you don't mind. (Q: no git-sed or similar to do rename on successive commits without git rebase, edit, git ammend, git rebase continue... etc?) BTW, I'd like to apply the first part at least (patches 1 to 5) in a week (or two if you want some more time to do some review). [...] -- Clément B.
Hi Clément, Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Sorry to Alexander, I think I missed that…
Please pardon me if I caused any confusion. I did not mean to say that every get should be replaced with make. I only meant to say that "make" is propably more precise if you pass a string buffer into a function which gets filled by that function. If I am not mistaken this returns the result as an uint32_t "value" type, so get is fine IMHO. In other words you can attribute creation/allocation to the function itself.
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
Here probably "make" is better. Or maybe av_timecode_to_string would be prettier?
I see the make form is used a little in avfilter, but I'm not sure. "make" makes me think of a function returning a sucess or failure after a processing, while get will return what is announced in the function name.
"get_" looks fine to me here... Of course, I get the point of the buffer being the destination but well…
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
same as above
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons.
Why? It just initialized the passed struct given a few parameters. It doesn't really build anything.
If someone strongly believes in one form over the other, I'll do the necessary; otherwise I'd avoid reworking the whole patchset for this if you don't mind.
I believe init is appropriate here. [...] Alexander
On date Tuesday 2012-01-24 22:21:02 +0100, Alexander Strasser encoded:
Hi Clément,
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Sorry that was a note and I somehow misread it as a @param, it's perfectly fine then.
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Sorry to Alexander, I think I missed that…
Please pardon me if I caused any confusion. I did not mean to say that every get should be replaced with make. I only meant to say that "make" is propably more precise if you pass a string buffer into a function which gets filled by that function.
If I am not mistaken this returns the result as an uint32_t "value" type, so get is fine IMHO. In other words you can attribute creation/allocation to the function itself.
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
Here probably "make" is better. Or maybe av_timecode_to_string would be prettier?
I'd like to stick with the convenction: a function name contains a verb, even if it is not always respected.
I see the make form is used a little in avfilter, but I'm not sure. "make" makes me think of a function returning a sucess or failure after a processing, while get will return what is announced in the function name.
"get_" looks fine to me here... Of course, I get the point of the buffer being the destination but well…
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
same as above
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons.
Why? It just initialized the passed struct given a few parameters. It doesn't really build anything.
If someone strongly believes in one form over the other, I'll do the necessary; otherwise I'd avoid reworking the whole patchset for this if you don't mind.
I believe init is appropriate here.
I'll stop bikeshedding now, I generally agree with the opinion of Alexander, but I'm not strong about them. -- FFmpeg = Foolish and Free MultiPurpose Epic Genius
On Tue, Jan 24, 2012 at 10:21:02PM +0100, Alexander Strasser wrote:
Hi Clément,
Hi Alexander,
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Proper naming for public is important, better overthink it first.
Sorry to Alexander, I think I missed that…
Please pardon me if I caused any confusion. I did not mean to say that every get should be replaced with make. I only meant to say that "make" is propably more precise if you pass a string buffer into a function which gets filled by that function.
If I am not mistaken this returns the result as an uint32_t "value" type, so get is fine IMHO. In other words you can attribute creation/allocation to the function itself.
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
Here probably "make" is better. Or maybe av_timecode_to_string would be prettier?
Consider these changes done locally: av_timecode_get_string → av_timecode_make_string av_timecode_get_mpegtc_string → av_timecode_make_mpegtc_string BTW, for my git-sed question, I used the following command to do the rename: git filter-branch -f --tree-filter 'for f in $(git ls-files "*.[ch]"); do sed -i s#old_name#new_name#g $f; done' HEAD...HEAD~12 It's very slow (I wasn't able to make git-ls-files list only the files modified in the last commit), and I couldn't simplify HEAD...HEAD~12: I'm in a branch with the 12 commits, and while HEAD...master works, it raises a warning about master not being modified. Using only "master" doesn't work either. Any hint welcome for the next rename request :)
I see the make form is used a little in avfilter, but I'm not sure. "make" makes me think of a function returning a sucess or failure after a processing, while get will return what is announced in the function name.
"get_" looks fine to me here... Of course, I get the point of the buffer being the destination but well…
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
same as above
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons.
Why? It just initialized the passed struct given a few parameters. It doesn't really build anything.
If someone strongly believes in one form over the other, I'll do the necessary; otherwise I'd avoid reworking the whole patchset for this if you don't mind.
I believe init is appropriate here.
OK, I keep the "init" then. [...] -- Clément B.
Hi, Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 10:21:02PM +0100, Alexander Strasser wrote:
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Proper naming for public is important, better overthink it first.
I fear I have another one. Seems I am only causing you work :( But please don't do anything if you think I am not making sense here. I just saw it would be good to have the tc parameter as the first one, for all av_timecode_* functions that use (read/write) its state (I think all others don't have that param at all).
Sorry to Alexander, I think I missed that…
Please pardon me if I caused any confusion. I did not mean to say that every get should be replaced with make. I only meant to say that "make" is propably more precise if you pass a string buffer into a function which gets filled by that function.
If I am not mistaken this returns the result as an uint32_t "value" type, so get is fine IMHO. In other words you can attribute creation/allocation to the function itself.
+ +/** + * Load timecode string in buf. + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc timecode data correctly initialized + * @param framenum frame number + * @return the buf parameter + *
+ * @note Timecode representation can be a negative timecode and have more than + * 24 hours, but will only be honored if the flags are correctly set. + * @note The frame number is relative to tc->start.
ditto
+ */ +char *av_timecode_get_string(char *buf, const AVTimecode *tc, int framenum);
ditto: get -> make?
Here probably "make" is better. Or maybe av_timecode_to_string would be prettier?
Consider these changes done locally: av_timecode_get_string → av_timecode_make_string av_timecode_get_mpegtc_string → av_timecode_make_mpegtc_string
LGTM
BTW, for my git-sed question, I used the following command to do the rename:
git filter-branch -f --tree-filter 'for f in $(git ls-files "*.[ch]"); do sed -i s#old_name#new_name#g $f; done' HEAD...HEAD~12
It's very slow (I wasn't able to make git-ls-files list only the files modified in the last commit), and I couldn't simplify HEAD...HEAD~12: I'm in a branch with the 12 commits, and while HEAD...master works, it raises a warning about master not being modified. Using only "master" doesn't work either. Any hint welcome for the next rename request :)
I see the make form is used a little in avfilter, but I'm not sure. "make" makes me think of a function returning a sucess or failure after a processing, while get will return what is announced in the function name.
"get_" looks fine to me here... Of course, I get the point of the buffer being the destination but well…
+/** + * Get the timecode string from the 25-bit timecode format (MPEG GOP format). + * + * @param buf destination buffer, must be at least AV_TIMECODE_STR_SIZE long + * @param tc25bit the 25-bits timecode + * @return the buf parameter + */ +char *av_timecode_get_mpegtc_string(char *buf, uint32_t tc25bit);
make?
same as above
+ +/** + * Init a timecode struct with the passed parameters. + * + * @param log_ctx a pointer to an arbitrary struct of which the first field + * is a pointer to an AVClass struct (used for av_log) + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param flags miscellaneous flags such as drop frame, +24 hours, ... + * (see AVTimecodeFlag) + * @param frame_start the first frame number + * @return 0 on success, AVERROR otherwise + */
+int av_timecode_init(void *log_ctx, AVTimecode *tc, AVRational rate, int flags, int frame_start); + +/** + * Parse timecode representation (hh:mm:ss[:;.]ff). + * + * @param log_ctx a pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct (used for av_log). + * @param tc pointer to an allocated AVTimecode + * @param rate frame rate in rational form + * @param str timecode string which will determine the frame start + * @return 0 on success, AVERROR otherwise + */ +int av_timecode_init_from_string(void *log_ctx, AVTimecode *tc, AVRational rate, const char *str);
For these two, either make or init should be fine, I have no strong opinion though but a slight bias towards "make" for internal consistency reasons.
Why? It just initialized the passed struct given a few parameters. It doesn't really build anything.
If someone strongly believes in one form over the other, I'll do the necessary; otherwise I'd avoid reworking the whole patchset for this if you don't mind.
I believe init is appropriate here.
OK, I keep the "init" then.
Fine. Alexander
On Wed, Jan 25, 2012 at 07:34:23PM +0100, Alexander Strasser wrote:
Hi,
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 10:21:02PM +0100, Alexander Strasser wrote:
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
+ * @note Frame number adjustment is automatically done in case of drop timecode, + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
+ */ +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Proper naming for public is important, better overthink it first.
I fear I have another one. Seems I am only causing you work :(
But please don't do anything if you think I am not making sense here.
I just saw it would be good to have the tc parameter as the first one, for all av_timecode_* functions that use (read/write) its state (I think all others don't have that param at all).
So a read only context would likely have a higher priority than an output in the parameters list priority? I don't mind much. I'll update the patchset next week. Consider it done locally. [...] -- Clément B.
On Thu, Jan 26, 2012 at 01:11:21PM +0100, Clément Bœsch wrote:
On Wed, Jan 25, 2012 at 07:34:23PM +0100, Alexander Strasser wrote:
Hi,
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 10:21:02PM +0100, Alexander Strasser wrote:
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...]
> + * @note Frame number adjustment is automatically done in case of drop timecode, > + * you do NOT have to call av_adjust_ntsc_framenum().
nit++: no complete sentence, lowcased and no dot at the end
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...]
> + */ > +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
Nit: get->make is maybe more approriate (as noted by Alexander Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Proper naming for public is important, better overthink it first.
I fear I have another one. Seems I am only causing you work :(
But please don't do anything if you think I am not making sense here.
I just saw it would be good to have the tc parameter as the first one, for all av_timecode_* functions that use (read/write) its state (I think all others don't have that param at all).
So a read only context would likely have a higher priority than an output in the parameters list priority? I don't mind much. I'll update the patchset next week. Consider it done locally.
OK, new version. Prototypes: int av_timecode_adjust_ntsc_framenum(int framenum); uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum); char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum); char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df); char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit); int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx); int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx); So briefly what's new: - better comments and doxy of av_timecode_get_smpte_from_framenum() - add av_timecode_make_smpte_tc_string() - various renames - AVTimecode context has a higher priority than output buffer in parameters list - log_ctx is now the last parameter I also attach to this email a patch for the usage of av_timecode_make_smpte_tc_string() in DV. This function can also be used to extract the timecode from MXF. If I see no more comment I'll push the whole patchset by the end of the week. [...] -- Clément B.
On Tue, Jan 31, 2012 at 02:39:02PM +0100, Clément Bœsch wrote:
On Thu, Jan 26, 2012 at 01:11:21PM +0100, Clément Bœsch wrote:
On Wed, Jan 25, 2012 at 07:34:23PM +0100, Alexander Strasser wrote:
Hi,
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 10:21:02PM +0100, Alexander Strasser wrote:
Clément Bœsch wrote:
On Tue, Jan 24, 2012 at 01:47:30PM +0100, Stefano Sabatini wrote: [...] > > + * @note Frame number adjustment is automatically done in case of drop timecode, > > + * you do NOT have to call av_adjust_ntsc_framenum(). > > nit++: no complete sentence, lowcased and no dot at the end >
Most of the the @note I see are of two forms:
@note frame number adjust is [...] ...framenum(). ==> "note that xxxx." @note Frame number [...] ...framenum(). ==> "NOTE: xxxx."
I used the second form, but it seems you do not want the first form either. Should I just drop the period? The sentence still has verbs… Could you be a bit more explicit about what you are expecting with an example?
[...] > > + */ > > +uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum); > > Nit: get->make is maybe more approriate (as noted by Alexander > Strasser in a recent mail)
First of all thanks to Stefano for caring about naming. Second I appologize to you, Clément, as proper naming needs some discussion :(
Proper naming for public is important, better overthink it first.
I fear I have another one. Seems I am only causing you work :(
But please don't do anything if you think I am not making sense here.
I just saw it would be good to have the tc parameter as the first one, for all av_timecode_* functions that use (read/write) its state (I think all others don't have that param at all).
So a read only context would likely have a higher priority than an output in the parameters list priority? I don't mind much. I'll update the patchset next week. Consider it done locally.
OK, new version. Prototypes:
int av_timecode_adjust_ntsc_framenum(int framenum); uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum);
char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum); char *av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df); char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit);
int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx); int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx);
So briefly what's new: - better comments and doxy of av_timecode_get_smpte_from_framenum() - add av_timecode_make_smpte_tc_string() - various renames - AVTimecode context has a higher priority than output buffer in parameters list - log_ctx is now the last parameter
[...] Patchset upstream, flame me on cvslog. -- Clément B.
From: Clément Bœsch <clement.boesch@smartjog.com> --- ffprobe.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ffprobe.c b/ffprobe.c index ca6133e..85f4ed7 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/dict.h" +#include "libavutil/timecode.h" #include "libavdevice/avdevice.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" @@ -1453,13 +1454,9 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i else print_str_opt("pix_fmt", "unknown"); print_int("level", dec_ctx->level); if (dec_ctx->timecode_frame_start >= 0) { - uint32_t tc = dec_ctx->timecode_frame_start; - print_fmt("timecode", "%02d:%02d:%02d%c%02d", - tc>>19 & 0x1f, // hours - tc>>13 & 0x3f, // minutes - tc>>6 & 0x3f, // seconds - tc & 1<<24 ? ';' : ':', // drop - tc & 0x3f); // frames + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_get_mpegtc_string(tcbuf, dec_ctx->timecode_frame_start); + print_str("timecode", tcbuf); } else { print_str_opt("timecode", "N/A"); } -- 1.7.8.3
On date Monday 2012-01-23 17:04:22 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- ffprobe.c | 11 ++++------- 1 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/ffprobe.c b/ffprobe.c index ca6133e..85f4ed7 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/dict.h" +#include "libavutil/timecode.h" #include "libavdevice/avdevice.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" @@ -1453,13 +1454,9 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i else print_str_opt("pix_fmt", "unknown"); print_int("level", dec_ctx->level); if (dec_ctx->timecode_frame_start >= 0) { - uint32_t tc = dec_ctx->timecode_frame_start; - print_fmt("timecode", "%02d:%02d:%02d%c%02d", - tc>>19 & 0x1f, // hours - tc>>13 & 0x3f, // minutes - tc>>6 & 0x3f, // seconds - tc & 1<<24 ? ';' : ':', // drop - tc & 0x3f); // frames + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_get_mpegtc_string(tcbuf, dec_ctx->timecode_frame_start); + print_str("timecode", tcbuf); } else { print_str_opt("timecode", "N/A"); }
Fine once we agree on API. -- FFmpeg = Free & Faithful Miracolous Prodigious Ecumenical Generator
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavcodec/mpeg12.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index d34b54d..c54beb5 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -33,6 +33,7 @@ #include "dsputil.h" #include "mpegvideo.h" #include "libavutil/avassert.h" +#include "libavutil/timecode.h" #include "mpeg12.h" #include "mpeg12data.h" @@ -2165,15 +2166,11 @@ static void mpeg_decode_gop(AVCodecContext *avctx, broken_link = get_bits1(&s->gb); if (s->avctx->debug & FF_DEBUG_PICT_INFO) { - int time_code_hours = tc>>19 & 0x1f; - int time_code_minutes = tc>>13 & 0x3f; - int time_code_seconds = tc>>6 & 0x3f; - int drop_frame_flag = tc & 1<<24; - int time_code_pictures = tc & 0x3f; - av_log(s->avctx, AV_LOG_DEBUG, "GOP (%02d:%02d:%02d%c%02d) closed_gop=%d broken_link=%d\n", - time_code_hours, time_code_minutes, time_code_seconds, - drop_frame_flag ? ';' : ':', - time_code_pictures, s->closed_gop, broken_link); + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_get_mpegtc_string(tcbuf, tc); + av_log(s->avctx, AV_LOG_DEBUG, + "GOP (%s) closed_gop=%d broken_link=%d\n", + tcbuf, s->closed_gop, broken_link); } } /** -- 1.7.8.3
On Mon, Jan 23, 2012 at 05:04:23PM +0100, Clément Bœsch wrote:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- libavcodec/mpeg12.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
LGTM, thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have often repented speaking, but never of holding my tongue. -- Xenocrates
From: Clément Bœsch <clement.boesch@smartjog.com> --- doc/filters.texi | 2 -- libavfilter/vf_drawtext.c | 34 +++++++++++++++------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 3c9f554..7120385 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1257,8 +1257,6 @@ timestamp expressed in seconds, NAN if the input timestamp is unknown @item timecode initial timecode representation in "hh:mm:ss[:;.]ff" format. It can be used with or without text parameter. @var{rate} option must be specified. -Note that timecode options are @emph{not} effective if FFmpeg is build with -@code{--disable-avcodec}. @item r, rate frame rate (timecode only) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index d0d854b..5b2eb10 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -30,7 +30,6 @@ #include <time.h> #include "config.h" -#include "libavcodec/timecode.h" #include "libavutil/avstring.h" #include "libavutil/colorspace.h" #include "libavutil/file.h" @@ -39,6 +38,7 @@ #include "libavutil/random_seed.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/timecode.h" #include "libavutil/tree.h" #include "libavutil/lfg.h" #include "avfilter.h" @@ -157,7 +157,9 @@ typedef struct { AVExpr *d_pexpr; int draw; ///< set to zero to prevent drawing AVLFG prng; ///< random - struct ff_timecode tc; + char *tc_opt_string; ///< specified timecode option string + AVRational tc_rate; ///< frame rate for timecode + AVTimecode tc; ///< timecode context int frame_id; } DrawTextContext; @@ -179,9 +181,9 @@ static const AVOption drawtext_options[]= { {"tabsize", "set tab size", OFFSET(tabsize), AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX }, {"basetime", "set base time", OFFSET(basetime), AV_OPT_TYPE_INT64, {.dbl=AV_NOPTS_VALUE}, INT64_MIN, INT64_MAX }, {"draw", "if false do not draw", OFFSET(d_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX }, -{"timecode", "set initial timecode", OFFSET(tc.str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, -{"r", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, -{"rate", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, +{"timecode", "set initial timecode", OFFSET(tc_opt_string), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"r", "set rate (timecode only)", OFFSET(tc_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, +{"rate", "set rate (timecode only)", OFFSET(tc_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, /* FT_LOAD_* flags */ {"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" }, @@ -341,17 +343,13 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) av_file_unmap(textbuf, textbuf_size); } - if (dtext->tc.str) { -#if CONFIG_AVCODEC - if (avpriv_init_smpte_timecode(ctx, &dtext->tc) < 0) - return AVERROR(EINVAL); + if (dtext->tc_opt_string) { + int ret = av_timecode_init_from_string(ctx, &dtext->tc, dtext->tc_rate, + dtext->tc_opt_string); + if (ret < 0) + return ret; if (!dtext->text) dtext->text = av_strdup(""); -#else - av_log(ctx, AV_LOG_ERROR, - "Timecode options are only available if libavfilter is built with libavcodec enabled.\n"); - return AVERROR(EINVAL); -#endif } if (!dtext->text) { @@ -729,13 +727,11 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, buf_size *= 2; } while ((buf = av_realloc(buf, buf_size))); -#if CONFIG_AVCODEC - if (dtext->tc.str) { - char tcbuf[16]; - avpriv_timecode_to_string(tcbuf, &dtext->tc, dtext->frame_id++); + if (dtext->tc_opt_string) { + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_get_string(tcbuf, &dtext->tc, dtext->frame_id++); buf = av_asprintf("%s%s", dtext->text, tcbuf); } -#endif if (!buf) return AVERROR(ENOMEM); -- 1.7.8.3
On date Monday 2012-01-23 17:04:24 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- doc/filters.texi | 2 -- libavfilter/vf_drawtext.c | 34 +++++++++++++++------------------- 2 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi index 3c9f554..7120385 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1257,8 +1257,6 @@ timestamp expressed in seconds, NAN if the input timestamp is unknown @item timecode initial timecode representation in "hh:mm:ss[:;.]ff" format. It can be used with or without text parameter. @var{rate} option must be specified. -Note that timecode options are @emph{not} effective if FFmpeg is build with -@code{--disable-avcodec}.
@item r, rate frame rate (timecode only) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index d0d854b..5b2eb10 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -30,7 +30,6 @@ #include <time.h>
#include "config.h" -#include "libavcodec/timecode.h" #include "libavutil/avstring.h" #include "libavutil/colorspace.h" #include "libavutil/file.h" @@ -39,6 +38,7 @@ #include "libavutil/random_seed.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/timecode.h" #include "libavutil/tree.h" #include "libavutil/lfg.h" #include "avfilter.h" @@ -157,7 +157,9 @@ typedef struct { AVExpr *d_pexpr; int draw; ///< set to zero to prevent drawing AVLFG prng; ///< random - struct ff_timecode tc; + char *tc_opt_string; ///< specified timecode option string + AVRational tc_rate; ///< frame rate for timecode + AVTimecode tc; ///< timecode context int frame_id; } DrawTextContext;
@@ -179,9 +181,9 @@ static const AVOption drawtext_options[]= { {"tabsize", "set tab size", OFFSET(tabsize), AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX }, {"basetime", "set base time", OFFSET(basetime), AV_OPT_TYPE_INT64, {.dbl=AV_NOPTS_VALUE}, INT64_MIN, INT64_MAX }, {"draw", "if false do not draw", OFFSET(d_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX }, -{"timecode", "set initial timecode", OFFSET(tc.str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, -{"r", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, -{"rate", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, +{"timecode", "set initial timecode", OFFSET(tc_opt_string), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, +{"r", "set rate (timecode only)", OFFSET(tc_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, +{"rate", "set rate (timecode only)", OFFSET(tc_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX },
/* FT_LOAD_* flags */ {"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" }, @@ -341,17 +343,13 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) av_file_unmap(textbuf, textbuf_size); }
- if (dtext->tc.str) { -#if CONFIG_AVCODEC - if (avpriv_init_smpte_timecode(ctx, &dtext->tc) < 0) - return AVERROR(EINVAL); + if (dtext->tc_opt_string) { + int ret = av_timecode_init_from_string(ctx, &dtext->tc, dtext->tc_rate, + dtext->tc_opt_string); + if (ret < 0) + return ret; if (!dtext->text) dtext->text = av_strdup(""); -#else - av_log(ctx, AV_LOG_ERROR, - "Timecode options are only available if libavfilter is built with libavcodec enabled.\n"); - return AVERROR(EINVAL); -#endif }
if (!dtext->text) { @@ -729,13 +727,11 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, buf_size *= 2; } while ((buf = av_realloc(buf, buf_size)));
-#if CONFIG_AVCODEC - if (dtext->tc.str) { - char tcbuf[16]; - avpriv_timecode_to_string(tcbuf, &dtext->tc, dtext->frame_id++); + if (dtext->tc_opt_string) { + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_get_string(tcbuf, &dtext->tc, dtext->frame_id++); buf = av_asprintf("%s%s", dtext->text, tcbuf); } -#endif
Should be Oll Korrect once we agree on names. -- FFmpeg = Friendly Fiendish Minimalistic Picky Enchanting Genius
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavformat/dvenc.c | 32 ++++++++++++-------------------- 1 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c index 049bb7b..2a9236a 100644 --- a/libavformat/dvenc.c +++ b/libavformat/dvenc.c @@ -33,12 +33,12 @@ #include "avformat.h" #include "internal.h" #include "libavcodec/dvdata.h" -#include "libavcodec/timecode.h" #include "dv.h" #include "libavutil/fifo.h" #include "libavutil/mathematics.h" #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" +#include "libavutil/timecode.h" struct DVMuxContext { AVClass *av_class; @@ -51,7 +51,8 @@ struct DVMuxContext { int has_audio; /* frame under contruction has audio */ int has_video; /* frame under contruction has video */ uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */ - struct ff_timecode tc; + char *tc_opt_str; /* timecode option string */ + AVTimecode tc; /* timecode context */ }; static const int dv_aaux_packs_dist[12][9] = { @@ -79,22 +80,13 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu { struct tm tc; time_t ct; - int ltc_frame; uint32_t timecode; va_list ap; buf[0] = (uint8_t)pack_id; switch (pack_id) { case dv_timecode: - /* - * LTC drop-frame frame counter drops two frames (0 and 1) every - * minute, unless it is exactly divisible by 10 - */ - ltc_frame = c->tc.start + c->frames; - if (c->tc.drop) - ltc_frame = avpriv_framenum_to_drop_timecode(ltc_frame); - timecode = avpriv_framenum_to_smpte_timecode(ltc_frame, c->sys->ltc_divisor, - c->tc.drop); + timecode = av_timecode_get_smpte_from_framenum(&c->tc, c->frames); timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6; // biphase and binary group flags AV_WB32(buf + 1, timecode); break; @@ -366,6 +358,7 @@ static void dv_delete_mux(DVMuxContext *c) static int dv_write_header(AVFormatContext *s) { + AVRational rate; DVMuxContext *dvc = s->priv_data; if (!dv_init_mux(s)) { @@ -375,13 +368,12 @@ static int dv_write_header(AVFormatContext *s) " (50Mbps allows an optional second audio stream)\n"); return -1; } - if (dvc->tc.str) { - dvc->tc.rate.num = dvc->sys->time_base.den; - dvc->tc.rate.den = dvc->sys->time_base.num; - if (avpriv_init_smpte_timecode(s, &dvc->tc) < 0) - return -1; - } - return 0; + rate.num = dvc->sys->ltc_divisor; + rate.den = 1; + if (dvc->tc_opt_str) + return av_timecode_init_from_string(s, &dvc->tc, rate, + dvc->tc_opt_str); + return av_timecode_init(s, &dvc->tc, rate, 0, 0); } static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) @@ -415,7 +407,7 @@ static const AVClass class = { .item_name = av_default_item_name, .version = LIBAVUTIL_VERSION_INT, .option = (const AVOption[]){ - {TIMECODE_OPT(DVMuxContext, AV_OPT_FLAG_ENCODING_PARAM)}, + {AV_TIMECODE_OPTION(DVMuxContext, tc_opt_str, AV_OPT_FLAG_ENCODING_PARAM)}, {NULL}, }, }; -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavformat/mov.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 3bb42fe..38fd0d5 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -30,13 +30,13 @@ #include "libavutil/mathematics.h" #include "libavutil/avstring.h" #include "libavutil/dict.h" +#include "libavutil/timecode.h" #include "avformat.h" #include "internal.h" #include "avio_internal.h" #include "riff.h" #include "isom.h" #include "libavcodec/get_bits.h" -#include "libavcodec/timecode.h" #include "id3v1.h" #include "mov_chan.h" @@ -2633,17 +2633,16 @@ finish: static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, uint32_t value) { - char buf[16]; - struct ff_timecode tc = { - .drop = st->codec->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE, - .rate = (AVRational){st->codec->time_base.den, - st->codec->time_base.num}, - }; - - if (avpriv_check_timecode_rate(s, tc.rate, tc.drop) < 0) - return AVERROR(EINVAL); + AVTimecode tc; + char buf[AV_TIMECODE_STR_SIZE]; + AVRational rate = {st->codec->time_base.den, + st->codec->time_base.num}; + int flags = st->codec->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE ? AV_TIMECODE_FLAG_DROPFRAME : 0; + int ret = av_timecode_init(s, &tc, rate, flags, 0); + if (ret < 0) + return ret; av_dict_set(&st->metadata, "timecode", - avpriv_timecode_to_string(buf, &tc, value), 0); + av_timecode_get_string(buf, &tc, value), 0); return 0; } -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavformat/isom.h | 1 + libavformat/mov.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 8f92cae..52ce585 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -127,6 +127,7 @@ typedef struct MOVStreamContext { int dts_shift; ///< dts shift when ctts is negative uint32_t palette[256]; int has_palette; + uint32_t tmcd_flags; ///< tmcd track flags } MOVStreamContext; typedef struct MOVContext { diff --git a/libavformat/mov.c b/libavformat/mov.c index 38fd0d5..7f21fd1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1381,9 +1381,11 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) st->codec->height = sc->height; } else { if (st->codec->codec_tag == MKTAG('t','m','c','d')) { + MOVStreamContext *tmcd_ctx = st->priv_data; int val; avio_rb32(pb); /* reserved */ val = avio_rb32(pb); /* flags */ + tmcd_ctx->tmcd_flags = val; if (val & 1) st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE; avio_rb32(pb); /* time scale */ @@ -2631,13 +2633,12 @@ finish: } static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, - uint32_t value) + uint32_t value, int flags) { AVTimecode tc; char buf[AV_TIMECODE_STR_SIZE]; AVRational rate = {st->codec->time_base.den, st->codec->time_base.num}; - int flags = st->codec->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE ? AV_TIMECODE_FLAG_DROPFRAME : 0; int ret = av_timecode_init(s, &tc, rate, flags, 0); if (ret < 0) return ret; @@ -2649,6 +2650,7 @@ static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) { MOVStreamContext *sc = st->priv_data; + int flags = 0; int64_t cur_pos = avio_tell(sc->pb); uint32_t value; @@ -2658,12 +2660,16 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); + if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME; + if (sc->tmcd_flags & 0x0002) flags |= AV_TIMECODE_FLAG_24HOURSMAX; + if (sc->tmcd_flags & 0x0004) flags |= AV_TIMECODE_FLAG_ALLOWNEGATIVE; + /* Assume Counter flag is set to 1 in tmcd track (even though it is likely * not the case) and thus assume "frame number format" instead of QT one. * 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). */ - parse_timecode_in_framenum_format(s, st, value); + parse_timecode_in_framenum_format(s, st, value, flags); avio_seek(sc->pb, cur_pos, SEEK_SET); return 0; -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavcodec/mpeg12enc.c | 25 ++++++++++++++----------- libavcodec/mpegvideo.h | 5 +++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 01dd8f0..6a1e714 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -33,10 +33,10 @@ #include "mpeg12.h" #include "mpeg12data.h" #include "bytestream.h" -#include "timecode.h" #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/avassert.h" +#include "libavutil/timecode.h" static const uint8_t inv_non_linear_qscale[13] = { 0, 2, 4, 6, 8, @@ -174,17 +174,20 @@ static av_cold int encode_init(AVCodecContext *avctx) } } - s->drop_frame_timecode = s->tc.drop = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); + s->drop_frame_timecode = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); + if (s->drop_frame_timecode) + s->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME; if (s->drop_frame_timecode && s->frame_rate_index != 4) { av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); return -1; } - if (s->tc.str) { - s->tc.rate = avpriv_frame_rate_tab[s->frame_rate_index]; - if (avpriv_init_smpte_timecode(s, &s->tc) < 0) - return -1; - s->drop_frame_timecode = s->tc.drop; + if (s->tc_opt_str) { + AVRational rate = avpriv_frame_rate_tab[s->frame_rate_index]; + int ret = av_timecode_init_from_string(s, &s->tc, rate, s->tc_opt_str); + if (ret < 0) + return ret; + s->drop_frame_timecode = !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME); s->avctx->timecode_frame_start = s->tc.start; } else { s->avctx->timecode_frame_start = 0; // default is -1 @@ -302,9 +305,9 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) time_code = s->current_picture_ptr->f.coded_picture_number + s->avctx->timecode_frame_start; s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number; - av_assert0(s->drop_frame_timecode == s->tc.drop); - if (s->tc.drop) - time_code = avpriv_framenum_to_drop_timecode(time_code); + av_assert0(s->drop_frame_timecode == !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); + if (s->drop_frame_timecode) + time_code = av_timecode_adjust_ntsc_framenum(time_code); put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); put_bits(&s->pb, 1, 1); @@ -935,7 +938,7 @@ static void mpeg1_encode_block(MpegEncContext *s, #define OFFSET(x) offsetof(MpegEncContext, x) #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM #define COMMON_OPTS\ - {TIMECODE_OPT(MpegEncContext,\ + {AV_TIMECODE_OPTION(MpegEncContext, tc_opt_str, \ AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)},\ { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },\ { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, \ diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index f7c8fb7..568fb86 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -36,7 +36,7 @@ #include "parser.h" #include "mpeg12data.h" #include "rl.h" -#include "timecode.h" +#include "libavutil/timecode.h" #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded @@ -649,7 +649,8 @@ typedef struct MpegEncContext { /* RTP specific */ int rtp_mode; - struct ff_timecode tc; + char *tc_opt_str; ///< timecode option string + AVTimecode tc; ///< timecode context uint8_t *ptr_lastgob; int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavformat/gxfenc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c index 47b64ef..dc8fd32 100644 --- a/libavformat/gxfenc.c +++ b/libavformat/gxfenc.c @@ -22,7 +22,7 @@ #include "libavutil/intfloat.h" #include "libavutil/opt.h" #include "libavutil/mathematics.h" -#include "libavcodec/timecode.h" +#include "libavutil/timecode.h" #include "avformat.h" #include "internal.h" #include "gxf.h" @@ -1000,7 +1000,7 @@ static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pk } static const AVOption options[] = { - { TIMECODE_OPT(GXFContext, AV_OPT_FLAG_ENCODING_PARAM) }, + { AV_TIMECODE_OPTION(GXFContext, tc.str, AV_OPT_FLAG_ENCODING_PARAM) }, { NULL } }; -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavformat/mxfenc.c | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 881902b..b77d1b7 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -37,8 +37,8 @@ #include "libavutil/opt.h" #include "libavutil/random_seed.h" +#include "libavutil/timecode.h" #include "libavcodec/bytestream.h" -#include "libavcodec/timecode.h" #include "audiointerleave.h" #include "avformat.h" #include "internal.h" @@ -187,7 +187,8 @@ typedef struct MXFContext { unsigned body_partitions_count; int last_key_index; ///< index of last key frame uint64_t duration; - struct ff_timecode tc; + char *tc_opt_str; ///< timecode option string + AVTimecode tc; ///< timecode context AVStream *timecode_track; int timecode_base; ///< rounded time code base (25 or 30) int edit_unit_byte_count; ///< fixed edit unit byte count @@ -675,7 +676,7 @@ static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum // Drop Frame mxf_write_local_tag(pb, 1, 0x1503); - avio_w8(pb, mxf->tc.drop); + avio_w8(pb, !!(mxf->tc.flags & AV_TIMECODE_FLAG_DROPFRAME)); } static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) @@ -1395,7 +1396,7 @@ static void mxf_gen_umid(AVFormatContext *s) static int mxf_write_header(AVFormatContext *s) { MXFContext *mxf = s->priv_data; - int i; + int i, ret; uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; const int *samples_per_frame = NULL; AVDictionaryEntry *t; @@ -1412,6 +1413,7 @@ static int mxf_write_header(AVFormatContext *s) st->priv_data = sc; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + AVRational rate; if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be first track\n"); return -1; @@ -1428,13 +1430,15 @@ static int mxf_write_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "unsupported video frame rate\n"); return -1; } + rate = (AVRational){mxf->time_base.den, mxf->time_base.num}; avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); - if (mxf->tc.str) { - mxf->tc.rate.num = mxf->time_base.den; - mxf->tc.rate.den = mxf->time_base.num; - if (avpriv_init_smpte_timecode(s, &mxf->tc) < 0) - return -1; - } + if (mxf->tc_opt_str) + ret = av_timecode_init_from_string(s, &mxf->tc, rate, + mxf->tc_opt_str); + else + ret = av_timecode_init(s, &mxf->tc, rate, 0, 0); + if (ret < 0) + return ret; if (s->oformat == &ff_mxf_d10_muxer) { if (st->codec->bit_rate == 50000000) if (mxf->time_base.den == 25) sc->index = 3; @@ -1549,7 +1553,7 @@ static void mxf_write_system_item(AVFormatContext *s) unsigned frame; uint32_t time_code; - frame = mxf->tc.start + mxf->last_indexed_edit_unit + mxf->edit_units_count; + frame = mxf->last_indexed_edit_unit + mxf->edit_units_count; // write system metadata pack avio_write(pb, system_metadata_pack_key, 16); @@ -1558,7 +1562,7 @@ static void mxf_write_system_item(AVFormatContext *s) avio_w8(pb, 0x04); // content package rate avio_w8(pb, 0x00); // content package type avio_wb16(pb, 0x00); // channel handle - avio_wb16(pb, frame); // continuity count + avio_wb16(pb, mxf->tc.start + frame); // continuity count if (mxf->essence_container_count > 1) avio_write(pb, multiple_desc_ul, 16); else { @@ -1570,11 +1574,7 @@ static void mxf_write_system_item(AVFormatContext *s) avio_wb64(pb, 0); // creation date/time stamp avio_w8(pb, 0x81); // SMPTE 12M time code - time_code = frame; - if (mxf->tc.drop) - time_code = avpriv_framenum_to_drop_timecode(time_code); - time_code = avpriv_framenum_to_smpte_timecode(time_code, mxf->timecode_base, - mxf->tc.drop); + time_code = av_timecode_get_smpte_from_framenum(&mxf->tc, frame); avio_wb32(pb, time_code); avio_wb32(pb, 0); // binary group data avio_wb64(pb, 0); @@ -1876,7 +1876,7 @@ static const AVClass mxf_class = { .item_name = av_default_item_name, .version = LIBAVUTIL_VERSION_INT, .option = (const AVOption[]){ - {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)}, + {AV_TIMECODE_OPTION(MXFContext, tc_opt_str, AV_OPT_FLAG_ENCODING_PARAM)}, {NULL} }, }; @@ -1886,7 +1886,7 @@ static const AVClass mxf_d10_class = { .item_name = av_default_item_name, .version = LIBAVUTIL_VERSION_INT, .option = (const AVOption[]){ - {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)}, + {AV_TIMECODE_OPTION(MXFContext, tc_opt_str, AV_OPT_FLAG_ENCODING_PARAM)}, {NULL} }, }; -- 1.7.8.3
From: Clément Bœsch <clement.boesch@smartjog.com> --- libavcodec/timecode.c | 6 +++++- libavcodec/timecode.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c index 2e0f4a4..f9862e5 100644 --- a/libavcodec/timecode.c +++ b/libavcodec/timecode.c @@ -22,8 +22,13 @@ /** * @file * Timecode helpers + * This *private* API is deprecated, please use the one available in libavutil instead. */ +#include "version.h" + +#if FF_API_OLD_TIMECODE + #include <stdio.h> #include "timecode.h" #include "libavutil/log.h" @@ -128,7 +133,6 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc) return 0; } -#if FF_API_OLD_TIMECODE int ff_framenum_to_drop_timecode(int frame_num) { return avpriv_framenum_to_drop_timecode(frame_num); diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h index bcfb0fa..8bc69e9 100644 --- a/libavcodec/timecode.h +++ b/libavcodec/timecode.h @@ -22,11 +22,16 @@ /** * @file * Timecode helpers header + * This *private* API is deprecated, please use the one available in libavutil instead. */ #ifndef AVCODEC_TIMECODE_H #define AVCODEC_TIMECODE_H +#include "version.h" + +#if FF_API_OLD_TIMECODE + #include <stdint.h> #include "avcodec.h" #include "libavutil/rational.h" @@ -93,7 +98,6 @@ int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop); */ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc); -#if FF_API_OLD_TIMECODE attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num); attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop); attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc); -- 1.7.8.3
On date Monday 2012-01-23 17:04:31 +0100, Clément Bœsch encoded:
From: Clément Bœsch <clement.boesch@smartjog.com>
--- libavcodec/timecode.c | 6 +++++- libavcodec/timecode.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c index 2e0f4a4..f9862e5 100644 --- a/libavcodec/timecode.c +++ b/libavcodec/timecode.c @@ -22,8 +22,13 @@ /** * @file * Timecode helpers + * This *private* API is deprecated, please use the one available in libavutil instead. */
+#include "version.h" + +#if FF_API_OLD_TIMECODE + #include <stdio.h> #include "timecode.h" #include "libavutil/log.h" @@ -128,7 +133,6 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc) return 0; }
-#if FF_API_OLD_TIMECODE int ff_framenum_to_drop_timecode(int frame_num) { return avpriv_framenum_to_drop_timecode(frame_num); diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h index bcfb0fa..8bc69e9 100644 --- a/libavcodec/timecode.h +++ b/libavcodec/timecode.h @@ -22,11 +22,16 @@ /** * @file * Timecode helpers header + * This *private* API is deprecated, please use the one available in libavutil instead. */
#ifndef AVCODEC_TIMECODE_H #define AVCODEC_TIMECODE_H
+#include "version.h" + +#if FF_API_OLD_TIMECODE + #include <stdint.h> #include "avcodec.h" #include "libavutil/rational.h" @@ -93,7 +98,6 @@ int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop); */ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc);
-#if FF_API_OLD_TIMECODE attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num); attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop); attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc); -- 1.7.8.3
Should be fine (a test can't hurt though). -- FFmpeg = Faithful and Frightening Moronic Purposeless Egregious Game
participants (4)
-
Alexander Strasser -
Clément Bœsch -
Michael Niedermayer -
Stefano Sabatini