[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
Mon Jul 20 16:05:51 EEST 2020


On Sun, Jul 19, 2020 at 09:05:33AM +0200, Marton Balint wrote:
> 
> 
> On Sun, 19 Jul 2020, lance.lmwang at gmail.com wrote:
> 
> > On Sat, Jul 18, 2020 at 08:38:16PM +0200, Marton Balint wrote:
> > > 
> > > 
> > > On Sat, 18 Jul 2020, lance.lmwang at gmail.com wrote:
> > > 
> > > > 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.
> > > 
> > > I still don't understand how this works. Isn't timecode in the SDI signal
> > > also contain the so called "field bit" flag to support 50fps timecode? And
> > > if it does, then why can't you query it from decklink? Timecode in SDI
> > > signal is also supposed to be an SMPTE 12M timecode, so all the bits you
> > > need should be in it, you should not need to guess anything. Therefore it
> > > makes little sense to me that the DeckLink API does not provide a proper
> > > timecode as string, unless the original capture you made with your
> > > UltraStudio and which you played back also has a faulty timecode.
> > > What generated the signal which you captured with UltraStudio? Not ffmpeg I
> > > hope...
> > 
> > It's auto-generated by configure of UltraStudio.
> 
> You mean using XLR timecode input selection? I would not trust that with
> 50fps...

I'm not sure it's XLR or not, it's configured by the menu.

> 
> > I have tested with bmdTimecodeFieldMark
> > flag, it's not set as expected for testing. I have no clue how to get
> > the flag as the API provide the TC string is same for the frame pair.
> > Maybe I miss something.
> 
> I'd try to generate SDI video with timecode by some other means. E.g. using
> MediaExpress / DaVinci Resolve and a native 1080p50 file.

What's your tested result for the 1080p50 file?  I haven't MediaExpress / DaVinci Resolve
to generate the native 1080p50 file to try.


> 
> Regards,
> Marton
> 
> 
> > 
> > > 
> > > Regards,
> > > Marton
> > > 
> > > 
> > > > > > > > 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
> > > > _______________________________________________
> > > > 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