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); fifo_write(&fifo, (uint8_t *)samples, 4096, &fifo.wptr); 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; } } } av_free_packet(&m_pMPEG.packet); av_free_packet(&m_pMPEG.pkt); } i plan to write the output with 4 seconds of lenghts. But the output i receive is only one second and the data not same as i "said" into microphone.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4