Hi all, I'm developing a multimedia application using ffmpeg encoding library. I'm a little bit confused when using avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples). I refered to output_example.c which just initializes AVCodecContext as follows: /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; It's easy to understand bit_rate=64000 to tell the encoder what's the output (encoded frames) rate. But for input parameters, it seems that sample_rate and channels only tell how many samples per second and how many channels of data are contained in one sample. This way, the encoder doesn't know what's the size of one sample. In my understanding, If smaple_rate=44100, channels=2, bits_per_channel = 16bit, then one frame contains 44100 samples and each sample's size is 16bit/8 * 2 (channels) = 4 bytes. As a result, the size of one input frame(1s) should be 44100 * 4 = 176400 bytes. Here I don't understand why there isn't a field to tell the encoder how many bits a channel contains, and how can the encoder read one sample for encoding if the encoder doesn't know the size of one sample? Thanks, Bin _________________________________________________________________ Connect to the next generation of MSN Messenger http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline _______________________________________________ libav-user mailing list [hidden email] https://lists.mplayerhq.hu/mailman/listinfo/libav-user |
[hidden email] wrote:
> But for input parameters, it seems that sample_rate and channels only tell how many samples per second and how many channels of data are contained in one sample. This way, the encoder doesn't know what's the size of one sample. In my understanding, If smaple_rate=44100, channels=2, bits_per_channel = 16bit, then one frame contains 44100 samples and each sample's size is 16bit/8 * 2 (channels) = 4 bytes. As a result, the size of one input frame(1s) should be 44100 * 4 = 176400 bytes. > Here I don't understand why there isn't a field to tell the encoder how many bits a channel contains, and how can the encoder read one sample for encoding if the encoder doesn't know the size of one sample? I believe the amount of bits per sample is specified by the codec id. Luca _______________________________________________ libav-user mailing list [hidden email] https://lists.mplayerhq.hu/mailman/listinfo/libav-user |
> I believe the amount of bits per sample is specified by the codec id. If so, where can I find the information about amount of bits per sample for various audio codecs, like AAC, MP3, WMA, etc. Thanks. -Bin > Date: Wed, 23 Jul 2008 09:28:11 +0200 > From: [hidden email] > To: [hidden email] > Subject: Re: [libav-user] How to fill in AVCodecContext data structure when encoding wave audio samples > > [hidden email] wrote: > > But for input parameters, it seems that sample_rate and channels only tell how many samples per second and how many channels of data are contained in one sample. This way, the encoder doesn't know what's the size of one sample. In my understanding, If smaple_rate=44100, channels=2, bits_per_channel = 16bit, then one frame contains 44100 samples and each sample's size is 16bit/8 * 2 (channels) = 4 bytes. As a result, the size of one input frame(1s) should be 44100 * 4 = 176400 bytes. > > Here I don't understand why there isn't a field to tell the encoder how many bits a channel contains, and how can the encoder read one sample for encoding if the encoder doesn't > know the size of one sample? > > I believe the amount of bits per sample is specified by the codec id. > > > Luca > _______________________________________________ > libav-user mailing list > [hidden email] > https://lists.mplayerhq.hu/mailman/listinfo/libav-user _________________________________________________________________ Connect to the next generation of MSN Messenger http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline _______________________________________________ libav-user mailing list [hidden email] https://lists.mplayerhq.hu/mailman/listinfo/libav-user |
In reply to this post by Luca Abeni
On date Wednesday 2008-07-23 09:28:11 +0200, Luca Abeni wrote:
> [hidden email] wrote: > > But for input parameters, it seems that sample_rate and channels > > only tell how many samples per second and how many channels of > > data are contained in one sample. This way, the encoder doesn't > > know what's the size of one sample. In my understanding, If > > smaple_rate=44100, channels=2, bits_per_channel = 16bit, then one > > frame contains 44100 samples and each sample's size is 16bit/8 * > > 2 (channels) = 4 bytes. As a result, the size of one input > > frame(1s) should be 44100 * 4 = 176400 bytes. Here I don't > > understand why there isn't a field to tell the encoder how many > > bits a channel contains, and how can the encoder read one sample > > for encoding if the encoder doesn't > know the size of one > > sample? > > I believe the amount of bits per sample is specified by the codec id. I confirm this, check the function av_get_bits_per_sample(codecID). I don't know if do exist codecs which support more bits-per-sample values, but I suppose no either libav* would have an hard time supporting them. Regards. _______________________________________________ libav-user mailing list [hidden email] https://lists.mplayerhq.hu/mailman/listinfo/libav-user |
(question:) >But for input parameters, it seems that sample_rate and channels >only tell how many samples per second and how many channels of >data are contained in one sample. This way, the encoder doesn't >know what's the size of one sample. In my understanding, If >smaple_rate=44100, channels=2, bits_per_channel = 16bit, then one >frame contains 44100 samples and each sample's size is 16bit/8 * >2 (channels) = 4 bytes. As a result, the size of one input >frame(1s) should be 44100 * 4 = 176400 bytes. Here I don't >understand why there isn't a field to tell the encoder how many >bits a channel contains, and how can the encoder read one sample >for encoding if the encoder doesn't > know the size of one >sample? (answers:) >I believe the amount of bits per sample is specified by the codec id. >I confirm this, check the function av_get_bits_per_sample(codecID). >I don't know if do exist codecs which support more bits-per-sample >values, but I suppose no either libav* would have an hard time >supporting them. (again:) I checked av_get_bits_per_sample(codecID) and found it only computes correct bits_per_sample for CODEC_ID_PCM_XXX and CODEC_ID_ADPCM_XXX, for any other codecIDs, it just returns 0. But obviously before I call int avcodec_open(AVCodecContext *avctx, AVCodec *codec), I set the codec id to CODEC_ID_MP3, CODEC_ID_WMAV2, CODEC_ID_AAC, etc. I would never set codec id to CODEC_ID_PCM_XXX or CODEC_ID_ADPCM_XXX. So it seems still confusing me:-) Thanks, Bin _________________________________________________________________ Discover the new Windows Vista http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE _______________________________________________ libav-user mailing list [hidden email] https://lists.mplayerhq.hu/mailman/listinfo/libav-user |
Free forum by Nabble | Edit this page |