[libav-api] Frames extraction

Dmitry d.p.0 at mail.ru
Wed Nov 5 21:14:27 CET 2014


*Hello!**
**I have a code for getting text string at each video frame 
(intermediate testing)**
**but on frame 16 I got following messages:**
**
**[h264 @ 0x1c6d900] AVC: nal size 20971526**
**[h264 @ 0x1c6d900] no frame!**
**Error while decoding frame 16**
**
**ffmpeg info about video file is here:*
-------------------------------------------------------------------------
   Metadata:
     major_brand     : mp42
     minor_version   : 0
     compatible_brands: isommp42
   Duration: 00:04:19.32, start: 0.000000, bitrate: 3146 kb/s
     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 
1280x720 [SAR 1:1 DAR 16:9], 2999 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc 
(default)
     Metadata:
       handler_name    : VideoHandler
     Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, 
fltp, 144 kb/s (default)
     Metadata:
       handler_name    : IsoMedia File Produced by Google, 5-11-2011
-------------------------------------------------------------------------

*part of code is here :*
--------------------------------------------------------------------------------------------------------------
     av_register_all();

     const char    *url = "video.mp4";
     AVFormatContext *s = NULL;
     int ret = avformat_open_input(&s, url, NULL, NULL);
     if (ret < 0)
         abort();

     AVPacket cur_packet;
     av_init_packet(&cur_packet);

     AVFrame *avf=av_frame_alloc();
     int got_picture;

     int len;
     int frame = 0;

     uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
     memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
     FILE *f = fopen(url, "rb");

     AVCodec *codec;
     AVCodecContext *c= NULL;

     codec = avcodec_find_decoder(s->streams[0]->codec->codec_id);
     if (!codec) {
             fprintf(stderr, "codec not found\n");
             exit(1);
     }

     c=s->streams[0]->codec;
     s->streams[0]->codec->codec=codec;

     if(codec->capabilities & CODEC_CAP_TRUNCATED)
         c->flags|= CODEC_FLAG_TRUNCATED;

     if (avcodec_open2(c, codec, NULL) < 0) {
         fprintf(stderr, "could not open codec\n");
         exit(1);
     }

     for(;;) {
         av_read_frame(s, &cur_packet );


         if (cur_packet.size == 0)
              break;


         while (cur_packet.size > 0) {
             len = avcodec_decode_video2(c, avf, &got_picture,&cur_packet);

             if (len < 0) {
                 fprintf(stderr, "Error while decoding frame %d\n", frame);
                 exit(1);
             }
             if (got_picture) {
                 printf("saving frame %3d\n", frame);

*/* I just want to get printf message for each frame due to testing 
purposes. */*

                 frame++;
             }
             cur_packet.size -= len;
             cur_packet.data += len;
         }
     }

     fclose(f);
     avformat_close_input(&s);
-----------------------------------------------------------------------------------------------------------------------------------


More information about the libav-api mailing list