jujulj a écrit :
> hi,
>
> I need to get the decoded samples from audio files of various formats
> using libavcodec.
> I've modified apiexample.c in order to detect automatically the
> appropriate codec, as shown in
> http://www.dranger.com/ffmpeg/tutorial03.c
>
> I replaced the following:
>
> <code>
>
>    // find the mpeg audio decoder
>     codec = avcodec_find_decoder(CODEC_ID_MP2);
>     if (!codec) {
>         fprintf(stderr, "codec not found\n");
>         exit(1);
>     }
>
>     c= avcodec_alloc_context();
>
> </code>
>
>
> by this:
>
> <code>
>
>     AVFormatContext *pFormatCtx;
>     int i, audioStream;
>
>     // Open audio file
>     if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) {
>         printf("Couldn't open file\n");
>         return -1;
>     }
>
>     // Retrieve stream information
>     if(av_find_stream_info(pFormatCtx)<0)
>         return -1; // Couldn't find stream information
>
>     // Dump information about file onto standard error
>     dump_format(pFormatCtx, 0, filename, 0);
>
>     // Find the first audio stream
>     audioStream=-1;
>     for(i=0; i<pFormatCtx->nb_streams; i++) {
>         if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO
> && audioStream < 0) {
>             audioStream=i;
>         }
>     }
>
>     if(audioStream==-1)
>         return -1;
>
>     c=pFormatCtx->streams[audioStream]->codec;
>
> </code>
>
> in apiexample.c (I also included avformat.h of course).
>
> My problem is that it does not even open the file, i.e.
>
> <code>
>
> av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL) do not return 0
>
> </code>
>
> do not return 0.
>
> The original code (i.e. hardcoding codec =
> avcodec_find_decoder(CODEC_ID_MP2);) works...
>
> Is this the right way to do what I want to achieve?
>
> apiexample_modified.c is attached.
>
> thank you
>
> Jul
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
in tutorial, he used av_register_all. Couldn't see it in your main()
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to