work on audio encoding
This commit is contained in:
parent
ae80fd4d2d
commit
0614af4f51
|
@ -206,6 +206,13 @@ Debug(2, "Have audio_output_context");
|
|||
av_strerror(ret, error_buffer, sizeof(error_buffer));
|
||||
Fatal( "could not open codec (%d) (%s)\n", ret, error_buffer );
|
||||
} else {
|
||||
/** Create the FIFO buffer based on the specified output sample format. */
|
||||
if (!(fifo = av_audio_fifo_alloc(audio_output_context->sample_fmt,
|
||||
audio_output_context->channels, 1))) {
|
||||
Error("Could not allocate FIFO\n");
|
||||
return;
|
||||
}
|
||||
output_frame_size = audio_output_context->frame_size;
|
||||
Debug(2, "Success opening AAC codec");
|
||||
}
|
||||
av_dict_free(&opts);
|
||||
|
@ -514,6 +521,44 @@ if ( 0 ) {
|
|||
zm_av_unref_packet(&opkt);
|
||||
return 0;
|
||||
}
|
||||
if ( data_present ) {
|
||||
|
||||
uint8_t **converted_input_samples = NULL;
|
||||
|
||||
/**
|
||||
* Allocate as many pointers as there are audio channels.
|
||||
* Each pointer will later point to the audio samples of the corresponding
|
||||
* channels (although it may be NULL for interleaved formats).
|
||||
*/
|
||||
if (!(converted_input_samples = calloc( audio_output_context->channels, sizeof(*converted_input_samples)))) {
|
||||
Error( "Could not allocate converted input sample pointers\n");
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* Allocate memory for the samples of all channels in one consecutive
|
||||
* block for convenience.
|
||||
*/
|
||||
if ((ret = av_samples_alloc(converted_input_samples, NULL,
|
||||
audio_output_context->channels,
|
||||
frame_size,
|
||||
audio_output_context->sample_fmt, 0)) < 0) {
|
||||
Error( "Could not allocate converted input samples (error '%s')\n",
|
||||
av_make_error_string(ret).c_str() );
|
||||
|
||||
av_freep(&(converted_input_samples)[0]);
|
||||
free(*converted_input_samples);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((ret = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) + frame_size)) < 0) {
|
||||
Error( "Could not reallocate FIFO\n");
|
||||
return 0;
|
||||
}
|
||||
/** Store the new samples in the FIFO buffer. */
|
||||
if (av_audio_fifo_write(fifo, (void **)converted_input_samples, frame_size) < frame_size) {
|
||||
Error( "Could not write data to FIFO\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Create a new frame to store the audio samples. */
|
||||
if (!(output_frame = av_frame_alloc())) {
|
||||
|
@ -568,6 +613,9 @@ output_frame->channel_layout, output_frame->format , output_frame->sample_rate
|
|||
zm_av_unref_packet(&opkt);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Debug(2, "Not data present" );
|
||||
} // end if data_present
|
||||
}
|
||||
} else {
|
||||
opkt.data = ipkt->data;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define ZM_VIDEOSTORE_H
|
||||
|
||||
#include "zm_ffmpeg.h"
|
||||
#include "libavutil/audio_fifo.h"
|
||||
|
||||
#if HAVE_LIBAVCODEC
|
||||
|
||||
|
@ -19,6 +20,8 @@ private:
|
|||
AVCodec *audio_output_codec;
|
||||
AVCodecContext *audio_output_context;
|
||||
int data_present;
|
||||
AVAudioFifo *fifo;
|
||||
int output_frame_size;
|
||||
|
||||
const char *filename;
|
||||
const char *format;
|
||||
|
|
Loading…
Reference in New Issue