Decoding audio file.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Decoding audio file.

libeesh k
Hi,

  I am using ffmpeg libraries to convert an audio file in one format to
mp3.But at the time of decoding there is a error in avcodec_decode_audio2.
Header skipping missing one byte
Header skipping missing one byte
Header skipping missing one byte
.
.
My code is
  while(av_read_packet(pFormatCtx, &packet)>=0)
    {
     if(packet.stream_index==audioStream)
      {
          frame_size_ptr = AVCODEC_MAX_AUDIO_FRAME_SIZE;
          int bufferSize=packet.size;
          long lSize = bufferSize  + FF_INPUT_BUFFER_PADDING_SIZE;
          uint8_t  *buffer = new uint8_t[lSize];
          int bytesDecoded = -1;
            // Decode video frame
          bytesDecoded = avcodec_decode_audio2(pCodecCtx, samples,
&frame_size_ptr,  buffer, bufferSize);
          delete buffer;
          if(frame_size_ptr)
          {
              writeAudioFrame(pFormatOut, audio_st, samples);
          }
       }
    }
Any help....
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decoding audio file.

Michel Bardiaux-2
libeesh k wrote:
> Hi,
>
>   I am using ffmpeg libraries to convert an audio file in one format to
> mp3.But at the time of decoding there is a error in avcodec_decode_audio2.
> Header skipping missing one byte
> Header skipping missing one byte
> Header skipping missing one byte

The way to proceed is to validate your file first, using the ffmpeg
command line to convert it to mp3. This will also give us info on your
input, which you didnt describe at all!

Then either ffmpeg works, and the problem is in your code (at which
point you better transfer the thread to libav-user); or it doesnt, and
the problem is either in your file or in the codec. But now, impossible
to say.

> .
> .
> My code is
>   while(av_read_packet(pFormatCtx, &packet)>=0)
>     {
>      if(packet.stream_index==audioStream)
>       {
>           frame_size_ptr = AVCODEC_MAX_AUDIO_FRAME_SIZE;
>           int bufferSize=packet.size;
>           long lSize = bufferSize  + FF_INPUT_BUFFER_PADDING_SIZE;
>           uint8_t  *buffer = new uint8_t[lSize];
>           int bytesDecoded = -1;
>             // Decode video frame
>           bytesDecoded = avcodec_decode_audio2(pCodecCtx, samples,
> &frame_size_ptr,  buffer, bufferSize);
>           delete buffer;
>           if(frame_size_ptr)
>           {
>               writeAudioFrame(pFormatOut, audio_st, samples);
>           }
>        }
>     }
>

--
Michel Bardiaux
R&D Director
T +32 [0] 2 790 29 41
F +32 [0] 2 790 29 02
E mailto:[hidden email]

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decoding audio file.

libeesh k
  Hi,

     I am trying to convert audio format to mp3. and now changed my code to

     while(av_read_frame(pFormatCtx, &packet)>=0)
    {
        if(packet.stream_index==audioStream)
        {
            avcodec_decode_audio(pCodecCtx, buffer, &frameFinished,
packet.data,     packet.size);

            if(frameFinished)
            {
                //Write the frame
                writeAudioFrame(oc, audio_st, buffer, packet);

            }
        }

        // Free the packet that was allocated by av_read_frame
        av_free_packet(&packet);
    }

Then the code works fine. It converts mp2 and mp3 formats to mp3 correctly.
But the problem is when I pass an uncompressed avi captured from micropfone
to it.The output mp3 file has only a beep sound.And it shows 1 minute length
for a
4 second avi.
I also tested avi with ffmpeg command line.It works perfect.

Any help ?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decoding audio file.

Rich Felker
On Tue, Feb 12, 2008 at 10:44:18AM +0530, libeesh k wrote:

>   Hi,
>
>      I am trying to convert audio format to mp3. and now changed my code to
>
>      while(av_read_frame(pFormatCtx, &packet)>=0)
>     {
>         if(packet.stream_index==audioStream)
>         {
>             avcodec_decode_audio(pCodecCtx, buffer, &frameFinished,
> packet.data,     packet.size);
>
>             if(frameFinished)
>             {
>                 //Write the frame
>                 writeAudioFrame(oc, audio_st, buffer, packet);
>
>             }
>         }
>
>         // Free the packet that was allocated by av_read_frame
>         av_free_packet(&packet);
>     }
>
> Then the code works fine. It converts mp2 and mp3 formats to mp3 correctly.
> But the problem is when I pass an uncompressed avi captured from micropfone
> to it.The output mp3 file has only a beep sound.And it shows 1 minute length
> for a
> 4 second avi.
> I also tested avi with ffmpeg command line.It works perfect.
>
> Any help ?

There's nothing in your code above to encode to mp3, so I have no idea
how you expect it to work or how you claim it already works for
mp2/mp3 input...

Also keep in mind, buffering is more complicated than you've made it
because the source and destination format frame sizes might not be the
same..

Rich
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Decoding audio file.

libeesh k
>
>
> There's nothing in your code above to encode to mp3, so I have no idea
> how you expect it to work or how you claim it already works for
> mp2/mp3 input...
>
> Also keep in mind, buffering is more complicated than you've made it
> because the source and destination format frame sizes might not be the
> same..
>
> Rich


   Hi,

    When i use this code I got lot of error messages.
   Incorrect frame size
   Incomplete frame.
   and
   Header missing skipping one byte....many times.
  These messages  come at avcodec_decode)audio2().

   Can  u give any suggestions.It will help me.

       while(av_read_packet(pFormatCtx, &packet)>=0)
    {
     if(packet.stream_index==audioStream)
      {

          long lAudioBytesRemaining=packet.size;
          long lAudioRawDataSize = packet.size;
          uint8_t  * pAudioRawData=packet.data;
          int bytesDecoded = -1;
            // Decode video frame
          while(1)
          {
            frame_size_ptr = AVCODEC_MAX_AUDIO_FRAME_SIZE;
            long lSize = lAudioBytesRemaining  +
FF_INPUT_BUFFER_PADDING_SIZE;
            uint8_t* buffer = (uint8_t*) av_malloc(lSize);
            memset(buffer, 0, lSize);
            memcpy(buffer, pAudioRawData, lAudioBytesRemaining);
            bytesDecoded = avcodec_decode_audio2(pCodecCtx, samples,
&frame_size_ptr,  buffer, lAudioBytesRemaining);
            av_free(buffer);
            if(bytesDecoded < 1)
            {
                break;//Decoding error!
            }
            else
            {
                writeAudioFrame(pFormatOut, audio_st, samples,
frame_size_ptr);
            }
            lAudioBytesRemaining -= bytesDecoded;
            pAudioRawData += bytesDecoded;
          }
       }
    }

>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user