+static int field_probe(AVFormatContext *fmt_ctx, AVStream *st)
+{
+ AVDictionary *copts = 0;
+ //av_dict_copy(&copts, opts, 0);
+ AVCodecID codec_id = st->codecpar->codec_id;
+ AVCodec *decoder = avcodec_find_decoder(codec_id);
+ AVCodecContext *ctx = avcodec_alloc_context3(decoder);
+ if( !ctx ) {
+ fprintf(stderr,"codec alloc failed\n");
+ return -1;
+ }
+ avcodec_parameters_to_context(ctx, st->codecpar);
+ if( avcodec_open2(ctx, 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.stream_index != st->index ) continue;
+ if( !ipkt.data || !ipkt.size ) continue;
+ ret = avcodec_send_packet(ctx, &ipkt);
+ if( ret < 0 ) {
+ fprintf(stderr, "avcodec_send_packet failed\n");
+ break;
+ }
+ ret = avcodec_receive_frame(ctx, ipic);
+ if( ret >= 0 ) {
+ ilaced = ipic->interlaced_frame ? 1 : 0;
+ break;
+ }
+ if( ret != AVERROR(EAGAIN) )
+ fprintf(stderr, "avcodec_receive_frame failed %d\n", ret);
+ }
+ av_packet_unref(&ipkt);
+ av_frame_free(&ipic);
+ avcodec_free_context(&ctx);
+ return ilaced;
+}
+