[Libav-user] Audio quality loss while encoding
brado at bighillsoftware.com
Thu Apr 25 03:35:28 CEST 2013
On Apr 24, 2013, at 4:26 PM, Bruce Wheaton <bruce at spearmorgan.com> wrote:
> This seems quite clear in sampleformat.h:
> * For planar sample formats, each audio channel is in a separate data plane,
> * and linesize is the buffer size, in bytes, for a single plane. All data
> * planes must be the same size. For packed sample formats, only the first data
> * plane is used, and samples for each channel are interleaved. In this case,
> * linesize is the buffer size, in bytes, for the 1 plane.
I fear some of my posts/discussions may be somewhat laden with two different definitions of the term "packed". The FFmpeg description based on for example the above doc you posted used "packed" in contrast to planar...i.e. channels delivered in linear format vs. separate planes (which would of course be planar). QTKit uses a different meaning for "packed"....from their doc for a particular attribute constant:
Set if the sample bits occupy the entire available bits for the channel, clear if they are high- or low-aligned within the channel.
If I'm reading this correctly, FFmpeg uses packed to refer to the way channels are structured relative to each other, in a single, linear buffer or in multiple buffers for each plane. QTKit uses packed to talk about whether a frame's bits are completely used, and if not, the positioning of sample bits within the frame (i.e. if 3 bytes of 4 were used, they could be low or high aligned within that frame, whether the format was planar or not).
> I found adding support for planar data trivial.
> I use:
> avcodec_decode_audio4 (audioCodecCtx, workingFrame, &bytesUsed, &packet);
Well, I'm encoding, but I figured it would be the same -- changing sample formats and codec config, but that's it. Other than that, I'm not aware of much else to change. A different codec or sample format doesn't necessitate a different approach to resampling or encoding. I'm still betting on a data buffer or pointer issue somewhere.
> Then for interleaved formats access the samples at:
> (const void*)workingFrame->data
> and planar formats:
> (const void*)workingFrame->data[i] (where i is 0 - number channels, obviously)
As it follows my use case, to my knowledge, that's essentially what I'm doing. Feel free to check out the code yourself. It's the QTFFAVStreamer class, the createAudioStream and streamAudioFrame methods.
Thanks again for the reply.
More information about the Libav-user