[Ffmpeg-devel] Decoding Audio and Video

Aya Koshigaya Aya
Thu Nov 2 22:19:50 CET 2006


Hi,

I had an idea how to describe what I need.. :)

I have my loop that collects the video frames, let's say 25 frames per 
second.
Now I need every 3 seconds the audiodata for the next 3 seconds.

Right now I capture the frames with the method described in the turoial
http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html

For the Audio I use this:

---------------------------------------------------------------------------------------------
long getAudioBuffer(void* buffer, long length)
{
 int rFrame = -1;
 int frameFinished = 0;
 int readData = 0;
 while (readData < length) {
  do {
   if (audioPacket.data != NULL)
    av_free_packet(&audioPacket);
   rFrame = av_read_frame(pFormatCtx, &audioPacket);
   if (rFrame >= 0 && audioPacket.stream_index == audioStream) {
    int bytesRemaining = audioPacket.size;
    int bytesDecoded = 0;
    do {
     int pSize = audioPacket.size;
     if (pSize > length - readData)
      pSize = length - readData;
     bytesDecoded = avcodec_decode_audio(pAudioCodecCtx, (int16_t *)buffer, 
&frameFinished, audioPacket.data, pSize);
     bytesRemaining -= bytesDecoded;
     readData += bytesDecoded;
    } while (!frameFinished && bytesDecoded > 0 && bytesRemaining >= 0 && 
readData < length);
   }
  } while (audioPacket.stream_index != audioStream);
 }
 return readData;
}
---------------------------------------------------------------------------------------------

but it doesn't work... :(

the requestet length most times is 38400 byte, the size of one frame 
returned by avcodec_decode_audio is 384byte, so I repeat this till I decoded 
enough frames to fill the whole buffer.

There are two problems:
a) The Sound sounds wrong.. it does two very short skratches and then 
silence.. (and program crashes after a few seconds)
b) The Videoframes are playing back way faster somehow :(

Help~ :(

Aya

----- Original Message ----- 

> Hi,
>
> I have some trouble with decoding Video and Audio at the same time... 
> Video alone is no problem, but I don't know how I should do the audio 
> part..
>
> The problem is, I need the Video and Audio seperated.. I can't just use 
> av_read_frame() in a loop and check each time if it's audio or video and 
> then decode it.
>
> I have one loop for the video, where I'm using av_read_frame() and then am 
> checking if this is my videoStream.
> (like in this tutorial: 
> http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html)
>
> But, when I'm doing the same for the Audio anything screws up.. :(
> It seems as if, when I use av_read_frame() in the audio-loop, it also 
> skips some videoframes... but the only thing both loops are using is the 
> AVFormatContext. (each loop has an own AVCodec, AVCodecContext and 
> AVPacket)
>
> To explain what I need:
> Let's say I have a Video of 10 seconds... now I want to grab the 
> Videostream of the first 5 secs, and the Audiostream of the last 5 secs... 
> the resulting video should now be 5 secs long.. hard to explain, do you 
> know what I mean?
>
> Kind regards,
>  Aya~
>
> PS: when I use avcodec_decode_audio, the result will be raw PCM audio, 
> right?
> If so, how do I determine the SampleRate, Channelcount and BitsPerSample?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel 





More information about the ffmpeg-devel mailing list