<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I have 2 contexts defined and I and running the samples thru swresample before sending to AAC encoder. Bur I must have something define wrong as not interleaved I get only a tone. </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Using the following code the define the RAW, PCM and resample contexts.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
int status=0;
<div>// setup RAW codec and context</div>
<div> AVCodec *raw_codec = avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE);</div>
<div><br>
</div>
<div> if (!raw_codec)</div>
<div> {</div>
<div> log_error("PCM_S32_LE codec id not found!");</div>
<div> return -1;</div>
<div> } </div>
<div> actx->rawctx = avcodec_alloc_context3(raw_codec); </div>
<div> if (!actx->rawctx) </div>
<div> {</div>
<div> log_error("Could not alloc RAW context");</div>
<div> return -1;</div>
<div> }</div>
<div> </div>
<div> </div>
<div> actx->rawctx->channels = 2; </div>
<div> actx->rawctx->channel_layout = av_get_default_channel_layout(2); </div>
<div> actx->rawctx->sample_rate = DEFAULT_SPEED;</div>
<div> actx->rawctx->sample_fmt = raw_codec->sample_fmts[0]; // AV_SAMPLE_FMT_S32</div>
<div> actx->rawctx->bit_rate = 2822400; // or 64000</div>
<div> actx->rawctx->time_base.num = 1;</div>
<div> actx->rawctx->time_base.den = 44100;</div>
<div> actx->rawctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; // Allow the use of the experimental AAC encoder.</div>
<div> </div>
<div> </div>
<div> // setup AAC codec and stream context</div>
<div> AVCodec *aac_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);</div>
<div> if (!aac_codec)</div>
<div> {</div>
<div> log_error("AAC codec id not found!");</div>
<div> return -1;</div>
<div> } </div>
<div><br>
</div>
<div> actx->audctx = avcodec_alloc_context3(aac_codec); </div>
<div> log_debug("encode aac contet %p", actx->audctx);</div>
<div> </div>
<div> if (!actx->audctx) </div>
<div> {</div>
<div> log_error("Could not alloc an encoding context");</div>
<div> return -1;</div>
<div> }</div>
<div><br>
</div>
<div> actx->audctx->channels = 2; //use default channels???</div>
<div> actx->audctx->channel_layout = av_get_default_channel_layout(2); //use default channels???</div>
<div> actx->audctx->sample_rate = 44100;</div>
<div> actx->audctx->sample_fmt = aac_codec->sample_fmts[0];</div>
<div> actx->audctx->bit_rate = 64000;</div>
<div> actx->audctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; // Allow the use of the experimental AAC encoder.</div>
<div></div>
<div> if ((status = avcodec_open2(actx->audctx, aac_codec, NULL) < 0)) </div>
<div> {</div>
<div> log_error("Could not open output codec (error '%s')", av_err2str(status));</div>
<div> return -1;</div>
<div> }</div>
<div><br>
</div>
<div>// setup resampler context</div>
<div> actx->swrctx = swr_alloc_set_opts(NULL, av_get_default_channel_layout(actx->audctx->channels), actx->audctx->sample_fmt,</div>
<div> actx->audctx->sample_rate, av_get_default_channel_layout(actx->rawctx->channels), actx->rawctx->sample_fmt,</div>
<div> actx->rawctx->sample_rate, 0, NULL);</div>
<div> if (!actx->swrctx) </div>
<div> {</div>
<div> log_error("Could not allocate resample context");</div>
<div> return -1;</div>
<div> }</div>
<div> </div>
<div> if ((status = swr_init(actx->swrctx)) < 0) </div>
<div> {</div>
<div> log_error("Could not open resample context");</div>
<div> swr_free(&actx->swrctx);</div>
<div> return -1;</div>
<span> }</span><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Libav-user <libav-user-bounces@ffmpeg.org> on behalf of Paul B Mahol <onemda@gmail.com><br>
<b>Sent:</b> Thursday, November 25, 2021 2:03 AM<br>
<b>To:</b> This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. <libav-user@ffmpeg.org><br>
<b>Subject:</b> Re: [Libav-user] PCM interleaved audio</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Thu, Nov 25, 2021 at 3:38 AM william keeling <<a href="mailto:WilliamKeeling@hotmail.com">WilliamKeeling@hotmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
Does anyone have an example of encoding PCM interleaved audio stream?<span> </span></p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
<span></span>I can<span> </span>encode the stream if I manual un-interleave the PCM samples and put them in R/L planes.<span>
</span>I am using “avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE_PLANAR)” for my manually un-interleaved stream and “avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE)” to the native interleaved stream.<span>
</span>I am not sure what else I need to do to define the stream as 2 channel interleaved stream.<u></u> </p>
</div>
</div>
</blockquote>
<div><br>
</div>
<div><br>
</div>
<div>For converting between interleaved vs noninterleaved it can be done manually or via libraries like libswresample of libavfilter.</div>
<div><br>
</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
<u></u></p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
<span style="font-family:Calibri,sans-serif; font-size:11pt; color:rgb(0,0,0)">Thanks</span><br>
</p>
<br>
</div>
</div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote>
</div>
</div>
</div>
</body>
</html>