[Libav-user] How to transcode mp3 file to G.711 encoded wav file
Bob Kirnum
bkirnum at gmail.com
Thu Dec 9 23:42:23 EET 2021
I have to assume that S16 is required by the G.711 encoder and is referring
to the input sample format. This means it requires 16 bit signed integer
as input so you will have to do the conversion from 32 bit float PCM
(output from the MP3 decoder) to 16 bit integer PCM.
On Thu, Dec 9, 2021 at 4:26 PM Robert Smith via Libav-user <
libav-user at ffmpeg.org> wrote:
> Setting anything else besides of
>
> pCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
>
> for G.711 encoder causing the function avcodec_open2 return the following
> error:
>
> [pcm_mulaw @ 0x22754a0] Specified sample_fmt is not supported.
>
>
> I don't understand why this happening especially if mulaw is defined by
> default as 8 bit
>
>
>
> On Wednesday, December 8, 2021, 05:37:49 PM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> I am saying to try . . .
>
> First use the 32 bit float version of AV_SAMPLE_FMT_S16 when setting
> sample_fmt for G.711 encoder.
>
> If that does not work then convert the decoded frame samples from 32 bit
> float to 16 bit integer. Not sure if 'swr_convert' does this, you could do
> it manually. I think the following should help.
>
>
> https://stackoverflow.com/questions/15087668/how-to-convert-pcm-samples-in-byte-array-as-floating-point-numbers-in-the-range
>
>
> On Wed, Dec 8, 2021 at 5:13 PM Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
>
> So when you are saying "convert samples from 32 bit float to 16 bit
> integer" do you mean to resample by "swr_convert" function?
>
> On Wednesday, December 8, 2021, 02:50:50 PM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> Yes, the sample format provided to encoder. Should match the samples
> you're passing to it.
>
> On Wed, Dec 8, 2021 at 2:44 PM Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
>
> I assume you are talking about encoding?
>
> On Wednesday, December 8, 2021, 02:26:22 PM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> I assume there is a sample format for 32 bit float, try that instead of AV_SAMPLE_FMT_S16.
> If that does not work you may need to convert samples from 32 bit float to
> 16 bit integer.
>
> On Wed, Dec 8, 2021 at 2:21 PM Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
>
> Dumped raw data to binary file, opened it in Audacity, found correct
> sampling rate and correctly played audio clip.
> I noticed that Audacity shows "32 bit float", as you mentioned in your
> previous E-mail that could be the reason why transcoding to uLaw fails.
>
> Could you clarify what is proper way to resolve the issue? Should I
> correct decoding? Thanks
>
> On Wednesday, December 8, 2021, 12:41:41 PM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> To verify the decoded audio from the MP3 I would simply write the decoded
> frames to file (fwrite or similar to a binary file). The resulting file is
> a raw PCM file which can be imported with Audacity. You specify the sample
> rate, sample format (i.e. 16 bit integer or 32 bit float), etc. When you
> get the right settings the audio should play good.
>
> On Wed, Dec 8, 2021 at 12:01 PM Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
>
> Hi,
>
> Thank you for your response. All my attempts to sort it out failed so far.
> Could you clarify how can I verify that I decoded the MP3 to linear PCM
> properly?
>
> I mean as result of decoding I'm getting frames:
> avcodec_decode_audio4(pMp3CodecCtx, frame, &gotFrame, &packet)
>
> So what is next? Write frame to wav file? How? The function av_interleaved_write_frame
> despite its name accept packets not a frames?
>
> How to check validity of wav container? I usually run "ffprobe -i
> Output.wav" to see details. Is there other way? Thanks
>
> On Monday, December 6, 2021, 11:43:17 AM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> Perhaps the AV_SAMPLE_FMT_S16 is referring to the sample format input to
> the G.711 uLaw encoder (input should be 16 bit linear PCM)? Then this
> would be correct. Perhaps split the effort and verify that you can decode
> the MP3 to linear PCM properly, and encode linear to uLaw properly for
> WAV separately? Using the wrong sample rate (not downsampling to 8 kHz)
> would not result in noise (what you reported), would just result in the
> wrong audio speed. One additional thought, does decoding the MP3 result in
> 16 bit integer linear PCM or 32 bit float PCM? If float, that would be a
> mismatch and result in noise when encoding to uLaw.
>
> On Mon, Dec 6, 2021 at 10:40 AM Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
>
> If I change
>
> pCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
>
> to
>
> pCodecCtx->sample_fmt = AV_SAMPLE_FMT_U8;
>
> Then I get the following error:
>
> [pcm_mulaw @ 0x2d33450] Specified sample_fmt is not supported.
>
> Any idea? Thanks
>
> On Friday, December 3, 2021, 06:15:54 PM EST, Bob Kirnum <
> bkirnum at gmail.com> wrote:
>
>
> G.711 is 8 bits, could be an issue. Also, not sure if you need to
> downsample to 8kHz manually or not.
>
> > On Dec 3, 2021, at 5:36 PM, Robert Smith via Libav-user <
> libav-user at ffmpeg.org> wrote:
> >
> > pCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20211209/78a7bc0a/attachment.htm>
More information about the Libav-user
mailing list