[Libav-user] nb_stream always fails

keren christkeren at gmail.com
Wed Feb 12 05:01:57 CET 2014


Carl Eugen Hoyos <cehoyos at ...> writes:

> 
> keren <christkeren <at> ...> writes:
> 
> > i am using ffmpeg version 2.1.3, with this i 
> > am unable to execute any of the sample code.
> 
> Please provide a little more information.
> (And consider testing current git head, if you 
> are a user nothing else is supported.)
> 
> Carl Eugen
> 


Hi this is the first time I haven't been able to find my answer 

I have this codesniplet that is my attempt to follow the few tutorials I
have found on getting some basic libav functionality (working my way to
extracting video frames).

      1 #ifndef INT64_C
      2 #define INT64_C(c) (c ## LL)
      3 #define UINT64_C(c) (c ## ULL)
      4 #endif
      5 
      6 extern "C" {
      7 #include <libavformat/avformat.h>
      8 #include <libavcodec/avcodec.h>
      9 #include <libavutil/avutil.h>
      10 }
      11 #include <iostream>
      12 using namespace std;
      13 #define FILENAME "/home/jon/Videos/testvideo.avi"
      14 
      15 
      16 int main(int argc, char** argv)
      17 {
      18     av_register_all();
      19     AVFormatContext * avFormatPtr = avformat_alloc_context();
      20     if (avformat_open_input(&avFormatPtr, FILENAME, NULL, NULL) != 0)
      21         cout<<"Error while calling avformat_open_input (probably
invalid file  format)"<<endl;
      22     if (avformat_find_stream_info(avFormatPtr, NULL) < 0)
      23         cout<<"Error while calling avformat_find_stream_info"<<endl;
      24     av_dump_format(avFormatPtr,0,FILENAME,false);
      25 
      26     cout<<"There are "<<avFormatPtr->nb_streams<<" streams"<<endl;
      27     unsigned int video_codec_id = -1;
      28     for (unsigned int i = 0; i < avFormatPtr->nb_streams; ++i) {
      29         cout<<"loop iteration "<<i<<endl;
      30        
if(avFormatPtr->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
      31         {
      32             cout<<"Found video "<<i<<endl;
      33             video_codec_id = i;
      34         }
      35         cout<<"debug point";
      36     }
      37 
      38     cout<<"fin"<<endl;
      39}           

Now the problem is that this always segfaults, here is the output

    Input #0, avi, from '/home/jon/Videos/testvideo.avi':
      Metadata:
        encoder         : Lavf53.21.0
      Duration: 00:01:51.08, start: 0.000000, bitrate: 17129 kb/s
        Stream #0.0: Video: mpeg4 (Simple Profile), yuv420p, 1920x1088 [PAR
1:1 DAR 30:17], 25 tbr, 25 tbn, 25 tbc
    There are 157328928 streams
    loop iteration 0
    Segmentation fault (core dumped)

The number of streams part changes every time leading my to think that it is
just pointing to a random place in the memory so I guess I must be
misunderstanding something about

    avformat_find_stream_info

Now this also always segfaults in the first loop iteration so I guess
streams hasn't been initialized either. Thanks in advance for any help.




More information about the Libav-user mailing list