Not able to get mono channel output libswresample

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Not able to get mono channel output libswresample

amey jain
Hello all,
I want an output stream of audio, mono channel, down sampled to 5512 Hz,
and output in a float array. I used libswresample API tutorial on page and
it is working. But there are two problems I am facing right now or not able
to understand context.
1. If channel layout is set as AV_CH_LAYOUT_MONO in out_channel_layout, and
number of output samples I get are nb_samples (say), then size of buffer
should be nb_samples * byte_per_sample * nb_channels. Since channel is mono
nb_channel should be one. However when I get size allocated using
av_samples_alloc with sample_fmt AV_SAMPLE_FMT_FLT I get size double of
what I calculated.
2. The output is in an array of uint8_t type and I have selected for output
AV_SAMPLE_FMT_FLT. So is there a way to get output in float or I will have
to convert this output only to float using bitwise operations.

  av_opt_set_channel_layout(swr, "in_channel_layout",
frame->channel_layout, 0);
  av_opt_set_channel_layout(swr, "out_channel_layout", AV_CH_LAYOUT_MONO,
0);
  av_opt_set_int(swr, "in_sample_rate",frame->sample_rate, 0);
  av_opt_set_int(swr, "out_sample_rate", 5512, 0);
  av_opt_set_sample_fmt(swr, "in_sample_fmt", src_sample_fmt, 0);
  av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
  ret = swr_init(swr);
  nb_samples = av_rescale_rnd(swr_get_delay(swr, frame->sample_rate) +
frame->nb_samples, 5512, frame->sample_rate, AV_ROUND_UP); //number of
output samples
  // buf_size is double of what calculated by nb_samples * byte_per_sample
* nb_channels
  buf_size = av_samples_alloc(&out, NULL, 2, out_count, AV_SAMPLE_FMT_FLT,
0);
  ret = swr_convert(swr, &out, out_count, (const uint8_t **) in, in_count);

Regards
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Not able to get mono channel output libswresample

Moritz Barsnick
On Thu, Jun 15, 2017 at 15:25:57 +0530, amey jain wrote:

> I used libswresample API tutorial on page and it is working.

May I point out that the list "libav-user" is the correct one for
questions regarding the libav* libraries and their APIs?:
https://www.ffmpeg.org/contact.html

You might find help here on ffmpeg-user, but this list is usually for
questions regarding the use of the command line tools.

Regards,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".