[Libav-user] avcodec_encode_audio() usage

Marlon Reid Marlon at scansoft.co.za
Fri Oct 14 08:10:37 CEST 2011


Hi Matthew,
 
I removed my error checking functions for the sake of brevity.  I also
attach to my debugger so that I can see what the program is doing.  It
take an uninitialized "outbuf" and then passes back an empty "outbuf".
I tried using av_log_set_callback but it never gets into the function I
set as the call back. 

//constructor

av_log_set_callback(avlog);

av_log_set_level(AV_LOG_VERBOSE);

//callback

static void avlog(void *ptr, int level, const char *fmt, va_list vargs)

{

std::ofstream _logFile;

_logFile.open("c:\\avlog.txt");

static char message[8192]; 

const char *module = NULL;

// Comment back in to filter only "important" messages

/*if (level > AV_LOG_WARNING)

return;*/

// Get module name

if (ptr)

{

AVClass *avc = *(AVClass**) ptr;

module = avc->item_name(ptr);

}

// Create the actual message

vsnprintf(message, sizeof(message), fmt, vargs);

// Append the message to the logfile

if (module)

{

_logFile << module << " ********************" << std::endl;

}

_logFile << "lvl: " << level << std::endl << "msg: " << message <<
std::endl;

_logFile.close();

}

 

Any idea how I can get my logging working?

 

Regards.

________________________________

From: libav-user-bounces at ffmpeg.org
[mailto:libav-user-bounces at ffmpeg.org] On Behalf Of Matthew Einhorn
Sent: 12 October 2011 05:17 PM
To: This list is about using libavcodec, libavformat,
libavutil,libavdevice and libavfilter.
Subject: Re: [Libav-user] avcodec_encode_audio() usage


On Wed, Oct 12, 2011 at 2:05 AM, Marlon Reid <Marlon at scansoft.co.za>
wrote:


	
	Hi,
	
	I have a small application that takes a raw pcm stream, encodes
it to mp3 and streams it to something like VLC. I am however havinging
issues with encoding my raw pcm stream. The problem is that my outbuf
from avcodec_encode_audio() is always  uninitialized.  It is as if
avcodec_encode_audio() never modifies outbuf.
	  
	In any case, here is my function
	
	
 <http://ffmpeg.zeranoe.com/forum/images/spacer.gif>
<http://ffmpeg.zeranoe.com/forum/images/spacer.gif>
<http://ffmpeg.zeranoe.com/forum/images/spacer.gif> 	
 <http://ffmpeg.zeranoe.com/forum/images/spacer.gif> 	Code:

unsigned char* CEncoder::encode_audio_frame(unsigned char*
in_pcm_buffer, int in_pcm_buffer_size, unsigned char * mp3_buffer, int
*out_size, std::string encoding)
{

AVCodec *codec;
AVCodecContext *c= NULL;
int outbuf_size;
uint8_t *outbuf;

avcodec_init();
avcodec_register_all();

codec = avcodec_find_encoder(CODEC_ID_MP3);
c = avcodec_alloc_context3(codec);

/* put sample parameters */
c->bit_rate = 64000;
c->sample_rate = SAMPLE_RATE;
c->channels = NUM_CHANNELS;
c->sample_fmt = AV_SAMPLE_FMT_S16;

avcodec_open(c, codec)
frame_size = c->frame_size;
outbuf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;  
 uint8_t * outbuf = new uint8_t [ outbuf_size ] ;

/* encode the samples */
*out_size = avcodec_encode_audio(c, outbuf, outbuf_size,
(short*)in_pcm_buffer);

return outbuf;
}
 
I suspect that I am using the avcodec_encode_audio() incorrectly.  Any
assistance will be great.
 
Thanks
 <http://ffmpeg.zeranoe.com/forum/images/spacer.gif> 	
 <http://ffmpeg.zeranoe.com/forum/images/spacer.gif>
<http://ffmpeg.zeranoe.com/forum/images/spacer.gif>
<http://ffmpeg.zeranoe.com/forum/images/spacer.gif> 	

I don't know what the issue is, but the obvious question is since you
don't check if any of the functions (avcodec_find_encoder...) failed,
are you sure they didn't fail?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20111014/578a1365/attachment.html>


More information about the Libav-user mailing list