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

lance.lmwang at gmail.com lance.lmwang at gmail.com
Sat Jul 18 17:38:49 EEST 2020


On Sat, Jul 18, 2020 at 09:44:03AM +0200, Marton Balint wrote:
> 
> 
> On Sat, 18 Jul 2020, lance.lmwang at gmail.com wrote:
> 
> > On Fri, Jul 17, 2020 at 07:13:28PM +0200, Marton Balint wrote:
> > > 
> > > 
> > > 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.
> > If I understand correctly, it's not hacky, for the framerate > 30, the source timecode will be
> > frame pair(it's limited by 2bits limit of frame number ten digital. Below is one exmaple for 50fps
> > if you tested with SDI with TC.
> > 00:00:00:24
> > 00:00:00:24
> > 00:00:00:25
> > 00:00:00:25
> > 00:00:00:00
> > 00:00:00:00
> 
> Have you actually tested this with a real SDI signal containing timecode?

Yes, have tested with SDI playback by decklink UltraStudio 4K mini with TC enabled.

> 
> Thanks,
> Marton
> 
> > 
> > That's why I check the last TC to get the frame is even or odd.
> > 
> > Why not use av_timecode_get_smpte_from_framenum(), for it's calculated by the string TC by one time,
> > so it lacks the information whether it's odd or even frame.
> > 
> > > 
> > > 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".
> > > _______________________________________________
> > > 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".
> > 
> > -- 
> > Thanks,
> > Limin Wang
> > _______________________________________________
> > 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".
> _______________________________________________
> 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".

-- 
Thanks,
Limin Wang


More information about the ffmpeg-devel mailing list