[Ffmpeg-devel] Captured buffer (PCM) to MPEG frame(s).. How to do this???
Michael Niedermayer
michaelni
Fri Jan 12 12:00:28 CET 2007
Hi
On Fri, Jan 12, 2007 at 01:58:13PM +0700, Paul wrote:
> I capture (using directsound) my voice to a buffer, and i would like to encode every buffer (captured) into MPEG frame(s) and then write to output file.
> Here are my code to encode a buffer (audio date with PCM format) to MPEG frame(s)
> But it is not success, i donot know where/what i missing. So, can you help?
>
> {
> //packet.data is a buffer that stored audio data (PCM format)
> //AVCODEC_MAX_AUDIO_FRAME_SIZE = 192000
> samples = (short *) av_fast_realloc(samples, &samples_size, FFMAX(4096, AVCODEC_MAX_AUDIO_FRAME_SIZE));
> samples = (short *)packet.data;
>
> avcodec_decode_audio(pCodecCtx, samples, &frameFinished, packet.data, 4096);
no you cannot decode a packet into itself
> fifo_write(&fifo, (uint8_t *)samples, 4096, &fifo.wptr);
you also must use the returned number of samples instead of a random 4096
>
> if(frameFinished)
> {
> int frame_bytes = c->frame_size * 2 * c->channels;
> fifo_read(&fifo, data_buf, frame_bytes, &fifo.rptr);
> {
> // encode the samples
> pkt.size= avcodec_encode_audio(c, audio_out, 4096,(short *)data_buf);
> pkt.stream_index= audio_st->index;
> pkt.data= audio_out;
> pkt.flags |= PKT_FLAG_KEY;
>
> fwrite(pkt.data,sizeof(int8_t),pkt.size,file);
> // write the compressed frame in the media file
> if (av_interleaved_write_frame(oc, &pkt) != 0)
> {
> fprintf(stderr, "Error while writing audio frame\n");
> return false;
> }
> }
> }
this must be a loop of course how could it work otherwise?!
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070112/06382c7e/attachment.pgp>
More information about the ffmpeg-devel
mailing list