[Ffmpeg-devel] Audio Decoding and Encoding Using FFmpeg: program crashing at avcodec_encode_audio

Renjith Nair renjith4
Tue Mar 7 15:26:32 CET 2006


Mans, Thanks for your reply. I am using c++ (windows environment) so i have
to use the explicit casting else the compiler gives an error.

I was using different codecContexts for encoding, but as it was not working
and so i tried to use the same codec context for both. Earlier it was like
this
outPacket.size = avcodec_encode_audio(outCodecCtx,output, outputSize,
(short*)outBuf);

Now i have changed it back to the original ( i.e using different contexts
for encoding and decoding).  But unfortunatley the error is the same.

Thanks & regards,
Renjith


On 3/7/06, M?ns Rullg?rd <mru at inprovide.com> wrote:
>
>
> Renjith Nair said:
> > Hi All,
> >
> > I have a problem while trying to encode audio using ffmpeg. Whenever the
> >  function avcodec_encode_audio is called teh system crashes. When that
> line
> > is commented out then the program works without any problem. Can anybody
> > have a clue, what is wrong with this code. Thanks in Advance.
> >
> >
> > P.S: I am developing an audio encoding/decoding api using ffmpeg and
> > planning to publish the code and the documentation on the web for free.
> Very
> > few ffmpeg documentations (for programmers) are currently available on
> the
> > web. So i plan to create a programmer's documentation with sample
> programs
> > to assist the further development of ffmpeg. All are welcome to
> co-operate.
> >
> > The code with the problem is the following:
> >>
> >>
> > outBuf = (int16_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
> > output = (uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
>
> Don't cast the return value of malloc() (unless you are using C++ (which
> you
> shouldn't)).
>
> > while(av_read_frame(pFormatCtx, &packet)>=0)
> > {
> >      // Is this a packet from the audio stream?
> >      if(packet.stream_index==audioStream)
> >      {
> >     // Decoding the frame
> >     len = avcodec_decode_audio(pCodecCtx,outBuf, &outBufSize,packet.data
> ,
> > packet.size);
> >
> >     // Encoding the frame
> >     outPacket.size = avcodec_encode_audio(pCodecCtx,output, outputSize,
> > (short*)outBuf);//<-- This line causes the crash
>
> You can't use the same AVCodecContext for both encoding and decoding.
>
> --
> M?ns Rullg?rd
> mru at inprovide.com
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>




More information about the ffmpeg-devel mailing list