[Cin] Getting field_order in dv demuxer early?

Andrew Randrianasulu randrianasulu at gmail.com
Sat Nov 14 23:16:30 CET 2020

В сообщении от Sunday 15 November 2020 00:07:27 Andrea paz via Cin написал(а):
> Stupid idea from an ignorant person (definitely wrong):
> It seems to me that GG has implemented media autorotation and timecode
> reading them in the metadata and then rotating or aligning them. Maybe
> also the aspect ratio or other can be read/put in the metadata?
> Excuse me for talking about things I don't know...

In my case I probably don't know how to fully initialize those structures, so only this partial form of extracting field_order from container/stream works.

(I tried few other forms of accesing frame data, but they resulted in Cin segfaulting)

dv codec (decoder) itself sets 


But by time this data become avilable CinGG already probed streams and set default field order 'UNKNOW' (I think this is safe default?)

I'm not sure how to force re-probing or hold filling those field until all data from decoder will be ready.

I found libopenshot, it probably shows how I can improve setting our flags from libavcodec's ones (I missed two cases), but their internal organization a bit different from Cin ....


 // Get scan type and order from codec context/params
  730         if (!check_interlace) {
  731                 check_interlace = true;
  732                 AVFieldOrder field_order = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->field_order;
  733                 switch(field_order) {
  734                         case AV_FIELD_PROGRESSIVE:
  735                                 info.interlaced_frame = false;
  736                                 break;
  737                         case AV_FIELD_TT:
  738                         case AV_FIELD_TB:
  739                                 info.interlaced_frame = true;
  740                                 info.top_field_first = true;
  741                                 break;
  742                         case AV_FIELD_BT:
  743                         case AV_FIELD_BB:
  744                                 info.interlaced_frame = true;
  745                                 info.top_field_first = false;
  746                                 break;
  747                         case AV_FIELD_UNKNOWN:
  748                                 // Check again later?
  749                                 check_interlace = false;
  750                                 break;
  751                 }

In my patch I omitted AV_FIELD_BT / AV_FIELD_TB (those exist because apparently fields can be coded and displayed in different order!)

Code in ffprobe was:

static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
    AVStream *stream = ist->st;
    AVCodecParameters *par;
    AVCodecContext *dec_ctx;
    char val_str[128];
    const char *s;
    AVRational sar, dar;
    AVBPrint pbuf;
    const AVCodecDescriptor *cd;
    int ret = 0;
    const char *profile = NULL;
    par     = stream->codecpar;

[skip a lot]

        if (par->field_order == AV_FIELD_PROGRESSIVE)
            print_str("field_order", "progressive");
        else if (par->field_order == AV_FIELD_TT)
            print_str("field_order", "tt");
        else if (par->field_order == AV_FIELD_BB)
            print_str("field_order", "bb");
        else if (par->field_order == AV_FIELD_TB)
            print_str("field_order", "tb");
        else if (par->field_order == AV_FIELD_BT)
            print_str("field_order", "bt");
            print_str_opt("field_order", "unknown");

BUT there was another isntance of field reporting:

static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
                       AVFormatContext *fmt_ctx)
    AVBPrint pbuf;
    char val_str[128];
    const char *s;
    int i;


        print_int("width",                  frame->width);
        print_int("height",                 frame->height);
        s = av_get_pix_fmt_name(frame->format);
        if (s) print_str    ("pix_fmt", s);
        else   print_str_opt("pix_fmt", "unknown");
        sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
        if (sar.num) {
            print_q("sample_aspect_ratio", sar, ':');
        } else {
            print_str_opt("sample_aspect_ratio", "N/A");
        print_fmt("pict_type",              "%c", av_get_picture_type_char(frame->pict_type));
        print_int("coded_picture_number",   frame->coded_picture_number);
        print_int("display_picture_number", frame->display_picture_number);
        print_int("interlaced_frame",       frame->interlaced_frame);
        print_int("top_field_first",        frame->top_field_first);
        print_int("repeat_pict",            frame->repeat_pict);

BUT I currently have no  idea  how to say Cin to not fill interlacing type after stream probe says 'unknown' and wait until codec frame probe will give correct info.

More information about the Cin mailing list