diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 137fd52745..e742b170cf 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -184,6 +184,9 @@ int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len, void **data, size_t *sei_size); +int ff_alloc_timecode_metadata_av1(const AVFrame *frame, AVRational rate, + void **data, size_t *size); + /** * Get an estimated video bitrate based on frame size, frame rate and coded * bits per pixel. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5ac20c6a5e..cb6cf2d6a1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1041,6 +1041,37 @@ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_l return 0; } +int ff_alloc_timecode_metadata_av1(const AVFrame *frame, AVRational rate, + void **data, size_t *size) +{ + AVFrameSideData *sd = NULL; + PutBitContext pb; + uint32_t *tc; + + if (frame) + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE); + + *data = NULL; + if (!sd) + return 0; + tc = (uint32_t*)sd->data; + if (!(tc[0] & 3)) // num_clock_ts + return 0; + + *size = 5; + *data = av_mallocz(*size); + if (!*data) + return AVERROR(ENOMEM); + + init_put_bits(&pb, *data, *size); + put_timecode_fields(&pb, rate, tc[1]); + put_bits(&pb, 5, 1); // time_offset_length + put_bits(&pb, 1, 0); // time_offset_value + flush_put_bits(&pb); + + return 0; +} + int64_t ff_guess_coded_bitrate(AVCodecContext *avctx) { AVRational framerate = avctx->framerate;