From: Limin Wang <lance.lmw...@gmail.com> Signed-off-by: Limin Wang <lance.lmw...@gmail.com> --- doc/filters.texi | 4 ++++ libavfilter/vf_drawtext.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/doc/filters.texi b/doc/filters.texi index 5f0eb28..8334f46 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -9825,6 +9825,10 @@ If both @var{text} and @var{textfile} are specified, an error is thrown. If set to 1, the @var{textfile} will be reloaded before each frame. Be sure to update it atomically, or it may be read partially, or even fail. +@item frame_tc +If set to 1, the timecode in S12M side data will be used for each frame +if have, 0 otherwise + @item x @item y The expressions which specify the offsets where text will be drawn diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index abe1ca6..018997a 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -197,6 +197,7 @@ typedef struct DrawTextContext { AVRational tc_rate; ///< frame rate for timecode AVTimecode tc; ///< timecode context int tc24hmax; ///< 1 if timecode is wrapped to 24 hours, 0 otherwise + int frame_tc; ///< 1 use timecode in S12M side data for each frame, 0 otherwise int reload; ///< reload text file for each frame int start_number; ///< starting frame number for n/frame_num var #if CONFIG_LIBFRIBIDI @@ -268,6 +269,7 @@ static const AVOption drawtext_options[]= { { "monochrome", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_MONOCHROME }, .flags = FLAGS, .unit = "ft_load_flags" }, { "linear_design", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_LINEAR_DESIGN }, .flags = FLAGS, .unit = "ft_load_flags" }, { "no_autohint", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_NO_AUTOHINT }, .flags = FLAGS, .unit = "ft_load_flags" }, + {"frame_tc", "use timecode in S21M side data for each frame if have", OFFSET(frame_tc), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, { NULL } }; @@ -1327,6 +1329,23 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, break; } + if (s->frame_tc) { + AVFrameSideData *sd; + + if (sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE)) { + uint32_t *tc = (uint32_t*)sd->data; + int m = tc[0] & 3; + + av_bprint_clear(bp); + av_bprintf(bp, "%s", s->text); + for (int j = 1; j <= m; j++) { + char tcbuf[AV_TIMECODE_STR_SIZE]; + av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0); + av_bprintf(bp, "%s%s", tcbuf, j != m ? ", " : ""); + } + } + } + if (s->tc_opt_string) { char tcbuf[AV_TIMECODE_STR_SIZE]; av_timecode_make_string(&s->tc, tcbuf, inlink->frame_count_out); -- 1.8.3.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".