[FFmpeg-devel] [PATCH 1/2] avdevice/decklink_dec: mark the field flag if framerate > 30FPS

Marton Balint cus at passwd.hu
Fri Jul 17 20:13:28 EEST 2020



On Fri, 17 Jul 2020, lance.lmwang at gmail.com wrote:

> From: Limin Wang <lance.lmwang at gmail.com>
>
> In SMPTE ST 12-1: 2014 Sec 12.2, we need to mark the frame flag if the frame rate > 30FPS to
> avoid interoperability issues. It will be used by the encoder to identify even or odd frames
> and correctly calculate the frame number of the SEI TC.

This feature looks like it belongs to av_timecode_get_smpte_from_framenum 
and not into decklink. Also checking previous timecode and guessing 
something is a hack, especially since you have the exact source timecode.

Regards,
Marton

>
> ---
> libavdevice/decklink_common.h |  1 +
> libavdevice/decklink_dec.cpp  | 14 ++++++++++++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> index bd68c7b..8ddc411 100644
> --- a/libavdevice/decklink_common.h
> +++ b/libavdevice/decklink_common.h
> @@ -151,6 +151,7 @@ struct decklink_ctx {
>     int channels;
>     int audio_depth;
>     unsigned long tc_seen;    // used with option wait_for_tc
> +    uint32_t last_tc;
> };
> 
> typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
> diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
> index dde68ff..a60c01b 100644
> --- a/libavdevice/decklink_dec.cpp
> +++ b/libavdevice/decklink_dec.cpp
> @@ -884,12 +884,26 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
>                         int metadata_len;
>                         uint8_t* packed_metadata;
>                         AVTimecode tcr;
> +                        AVRational rate = ctx->video_st->r_frame_rate;
>
>                         if (av_timecode_init_from_string(&tcr, ctx->video_st->r_frame_rate, tc, ctx) >= 0) {
>                             uint32_t tc_data = av_timecode_get_smpte_from_framenum(&tcr, 0);
>                             int size = sizeof(uint32_t) * 4;
>                             uint32_t *sd = (uint32_t *)av_packet_new_side_data(&pkt, AV_PKT_DATA_S12M_TIMECODE, size);
> 
> +                            /* set the field flag if frame rate > 30FPS */
> +                            /* Refer to SMPTE ST 12-1:2014 Sec 12.2 */
> +                            if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
> +                                /* Odd frame */
> +                                if (ctx->last_tc == tc_data) {
> +                                    if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
> +                                        tc_data |= (1 << 7);
> +                                    else
> +                                        tc_data |= (1 << 23);
> +                                }
> +                            }
> +                            ctx->last_tc = tc_data;
> +
>                             if (sd) {
>                                 *sd       = 1;       // one TC
>                                 *(sd + 1) = tc_data; // TC
> -- 
> 2.9.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list