+static int field_probe(AVFormatContext *fmt_ctx, AVStream *st)
+{
+ AVDictionary *copts = 0;
+ //av_dict_copy(&copts, opts, 0);
+ AVCodecID codec_id = st->codec->codec_id;
+ AVCodec *decoder = avcodec_find_decoder(codec_id);
+ if( avcodec_open2(st->codec, decoder, &copts) < 0 ) {
+ fprintf(stderr,"codec open failed\n");
+ return -1;
+ }
+ av_dict_free(&copts);
+
+ AVFrame *ipic = av_frame_alloc();
+ AVPacket ipkt;
+ av_init_packet(&ipkt);
+ int ilaced = -1;
+ for( int retrys=100; --retrys>=0 && ilaced<0; ) {
+ av_packet_unref(&ipkt);
+ int ret = av_read_frame(fmt_ctx, &ipkt);
+ if( ret == AVERROR_EOF ) break;
+ if( ret != 0 ) continue;
+ if( !ipkt.data ) continue;
+ if( ipkt.stream_index != st->index ) continue;
+ while( ipkt.size > 0 ) {
+ int got_frame = 0;
+ ret = avcodec_decode_video2(st->codec, ipic, &got_frame, &ipkt);
+ if( ret <= 0 ) break;
+ if( got_frame ) {
+ ilaced = ipic->interlaced_frame ? 1 : 0;
+ break;
+ }
+ ipkt.data += ret;
+ ipkt.size -= ret;
+ }
+ }
+ av_packet_unref(&ipkt);
+ av_frame_free(&ipic);
+ return ilaced;
+}
+