<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16434"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=121090606-14102011><FONT color=#005080
face="Trebuchet MS">Hi Matthew,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=121090606-14102011><FONT color=#005080
face="Trebuchet MS"></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=121090606-14102011><FONT color=#005080
face="Trebuchet MS">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.</FONT>
<P><SPAN class=121090606-14102011><FONT color=#005080
face="Trebuchet MS">//constructor</FONT></SPAN></P><SPAN
class=121090606-14102011><FONT size=2>
<P><FONT color=#005080
face="Trebuchet MS">av_log_set_callback(avlog);</FONT></P>
<P><FONT color=#005080
face="Trebuchet MS">av_log_set_level(AV_LOG_VERBOSE);</FONT></P>
<P><SPAN class=121090606-14102011><FONT color=#005080 size=3
face="Trebuchet MS">//callback</FONT></SPAN></P><SPAN
class=121090606-14102011><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>static</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT
color=#0000ff size=2>void</FONT></FONT><FONT size=2> avlog(</FONT><FONT
color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2>
*ptr, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>int</FONT></FONT><FONT size=2> level, </FONT><FONT color=#0000ff
size=2><FONT color=#0000ff size=2>const</FONT></FONT><FONT size=2> </FONT><FONT
color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2>
*fmt, va_list vargs)</P>
<P>{</P>
<P>std::ofstream _logFile;</P>
<P>_logFile.open(</FONT><FONT color=#a31515 size=2><FONT color=#a31515
size=2>"c:\\avlog.txt"</FONT></FONT><FONT size=2>);</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>static</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT
color=#0000ff size=2>char</FONT></FONT><FONT size=2> message[8192]; </P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT
color=#0000ff size=2>char</FONT></FONT><FONT size=2> *module = NULL;</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Comment back
in to filter only "important" messages</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/*if (level >
AV_LOG_WARNING)</P>
<P>return;*/</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Get module
name</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>if</FONT></FONT><FONT size=2> (ptr)</P>
<P>{</P>
<P>AVClass *avc = *(AVClass**) ptr;</P>
<P>module = avc->item_name(ptr);</P>
<P>}</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Create the
actual message</P></FONT></FONT><FONT size=2>
<P>vsnprintf(message, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>sizeof</FONT></FONT><FONT size=2>(message), fmt, vargs);</P>
<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Append the
message to the logfile</P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2>if</FONT></FONT><FONT size=2> (module)</P>
<P>{</P>
<P>_logFile << module << </FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2>" ********************"</FONT></FONT><FONT size=2> <<
std::endl;</P>
<P>}</P>
<P>_logFile << </FONT><FONT color=#a31515 size=2><FONT color=#a31515
size=2>"lvl: "</FONT></FONT><FONT size=2> << level << std::endl
<< </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"msg:
"</FONT></FONT><FONT size=2> << message << std::endl;</P>
<P>_logFile.close();</P>
<P>}</P>
<P> </P>
<P><SPAN class=121090606-14102011><FONT color=#005080 size=3
face="Trebuchet MS">Any idea how I can get my logging working?</FONT></SPAN></P>
<P><SPAN class=121090606-14102011><FONT color=#005080 size=3
face="Trebuchet MS"></FONT></SPAN> </P>
<P><SPAN class=121090606-14102011><FONT color=#005080 size=3
face="Trebuchet MS">Regards.</FONT></SPAN></P></FONT></SPAN></FONT></SPAN></SPAN></DIV>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> libav-user-bounces@ffmpeg.org
[mailto:libav-user-bounces@ffmpeg.org] <B>On Behalf Of </B>Matthew
Einhorn<BR><B>Sent:</B> 12 October 2011 05:17 PM<BR><B>To:</B> This list is
about using libavcodec, libavformat, libavutil,libavdevice and
libavfilter.<BR><B>Subject:</B> Re: [Libav-user] avcodec_encode_audio()
usage<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=gmail_quote>On Wed, Oct 12, 2011 at 2:05 AM, Marlon Reid <SPAN
dir=ltr><<A
href="mailto:Marlon@scansoft.co.za">Marlon@scansoft.co.za</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><U></U>
<DIV
style="BACKGROUND-COLOR: #e0e0e0; FONT-FAMILY: Arial; COLOR: #000000; FONT-SIZE: 10pt"
bgcolor="#e0e0e0">
<DIV dir=ltr align=left><FONT color=#005080><FONT color=#000000 size=3
face="Trebuchet MS">Hi,<BR><BR>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<FONT
color=#005080><SPAN> <FONT color=#000000> uninitialized. It is
as if avcodec_encode_audio() never modifies
outbuf.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#005080><FONT size=3
face="Trebuchet MS"><FONT
color=#000000><SPAN> </SPAN><SPAN> </SPAN><BR>In any case, here is
my function<BR><BR></FONT></FONT></FONT></DIV>
<DIV>
<DIV>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=4 width=4><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD>
<TD width="100%"><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD>
<TD height=4 width=4><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD></TR>
<TR>
<TD><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=3 height=4
NOSEND="1"></FONT></TD>
<TD width="100%">
<DIV><B><FONT face="Trebuchet MS">Code:</FONT></B></DIV>
<DIV><BR><FONT face="Trebuchet MS">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)<BR>{<BR><BR>AVCodec *codec;<BR>AVCodecContext *c=
NULL;<BR>int outbuf_size;<BR>uint8_t
*outbuf;<BR><BR>avcodec_init();<BR>avcodec_register_all();<BR><BR>codec
= avcodec_find_encoder(CODEC_ID_MP3);<BR>c =
avcodec_alloc_context3(codec);<BR><BR>/* put sample parameters
*/<BR>c->bit_rate = 64000;<BR>c->sample_rate =
SAMPLE_RATE;<BR>c->channels = NUM_CHANNELS;<BR>c->sample_fmt =
AV_SAMPLE_FMT_S16;<BR><BR>avcodec_open(c, codec)<BR>frame_size =
c->frame_size;<BR>outbuf_size =
AVCODEC_MAX_AUDIO_FRAME_SIZE; <SPAN><FONT
color=#005080> </FONT></SPAN></FONT></DIV>
<DIV><FONT face="Trebuchet MS"><SPAN> </SPAN>uint8_t * outbuf = new
uint8_t<SPAN><FONT
color=#005080> [ </FONT></SPAN>outbuf_size<SPAN><FONT
color=#005080> ] </FONT></SPAN>;<BR><BR>/* encode the samples
*/<BR>*out_size = avcodec_encode_audio(c, outbuf, outbuf_size,
(short*)in_pcm_buffer);<BR><BR>return outbuf;<BR>}</FONT></DIV>
<DIV><FONT face="Trebuchet MS"></FONT> </DIV>
<DIV><SPAN><FONT face="Trebuchet MS">I suspect that I am using the
avcodec_encode_audio() incorrectly. Any assistance will be
great.</FONT></SPAN></DIV>
<DIV><SPAN><FONT face="Trebuchet MS"></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face="Trebuchet MS">Thanks</FONT></SPAN></DIV></TD>
<TD><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=3 height=4
NOSEND="1"></FONT></TD></TR>
<TR>
<TD height=4 width=4><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD>
<TD width="100%"><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD>
<TD height=4 width=4><FONT face="Trebuchet MS"><IMG border=0 alt=""
src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" width=4 height=4
NOSEND="1"></FONT></TD></TR></TBODY></TABLE></DIV></DIV></DIV></BLOCKQUOTE></DIV>I
don't know what the issue is, but the obvious question is since you don't check
if any of the functions (<FONT
face="Trebuchet MS">avcodec_find_encoder</FONT>...) failed, are you sure they
didn't fail?<BR></BODY></HTML>