Because old thread now a bit too big for mobile gmail client.
2528 static int field_probe(AVFormatContext *fmt_ctx, AVStream *st)
2529 {
2530 AVDictionary *copts = 0;
2531 //av_dict_copy(&copts, opts, 0);
2532 AVCodecID codec_id = st->codecpar->codec_id;
2533 #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
2534 AVCodec *decoder = avcodec_find_decoder(codec_id);
2535 #endif
2536 #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
2537 const AVCodec *decoder = avcodec_find_decoder(codec_id);
2538 #endif
2539 AVCodecContext *ctx = avcodec_alloc_context3(decoder);
2540 if( !ctx ) {
2541 fprintf(stderr,"codec alloc failed\n");
2542 return -1;
2543 }
2544 avcodec_parameters_to_context(ctx, st->codecpar);
2545 if( avcodec_open2(ctx, decoder, &copts) < 0 ) {
2546 fprintf(stderr,"codec open failed\n");
2547 return -1;
2548 }
2549 av_dict_free(&copts);
2550
2551 AVFrame *ipic = av_frame_alloc();
2552 AVPacket ipkt;
2553 av_init_packet(&ipkt);
2554 int ilaced = -1;
2555 for( int retrys=100; --retrys>=0 && ilaced<0; ) {
2556 av_packet_unref(&ipkt);
2557 int ret = av_read_frame(fmt_ctx, &ipkt);
2558 if( ret == AVERROR_EOF ) break;
2559 if( ret != 0 ) continue;
2560 if( ipkt.stream_index != st->index ) continue;
2561 if( !ipkt.data || !ipkt.size ) continue;
2562 ret = avcodec_send_packet(ctx, &ipkt);
2563 if( ret < 0 ) {
2564 fprintf(stderr, "avcodec_send_packet failed\n");
2565 break;
2566 }
2567 ret = avcodec_receive_frame(ctx, ipic);
2568 if( ret >= 0 ) {
2569 ilaced = ipic->interlaced_frame ? 1 : 0;
2570 break;
2571 }
2572 if( ret != AVERROR(EAGAIN) )
2573 fprintf(stderr, "avcodec_receive_frame failed %d\n", ret);
2574 }
2575 av_packet_unref(&ipkt);
2576 av_frame_free(&ipic);
2577 avcodec_free_context(&ctx);
2578 return ilaced;
may be we can add flags to force interlaced vs progressive to bdwrite ... and/or debug why it fails.