If I change the files doc/examples/encode_audio.c and
doc/examples/decode_audio.c to use FLAC instead of MP2 and count the
number of samples encoded and decoded I find that decode_audio outputs
fewer samples than were encoded. Eventually I found that the
following change fixes this.
@@ -168,8 +172,9 @@ int main(int argc, char **argv)
/* decode until eof */
data = inbuf;
data_size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
+ int done = 0;
- while (data_size > 0) {
+ while (!done) {
if (!decoded_frame) {
if (!(decoded_frame = av_frame_alloc())) {
fprintf(stderr, "Could not allocate audio frame\n");
@@ -180,6 +185,7 @@ int main(int argc, char **argv)
ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
data, data_size,
AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
+ done = pkt->size == 0 && data_size == 0;
if (ret < 0) {
fprintf(stderr, "Error while parsing\n");
exit(1);
It seems like the parser indicates that it's parsed bytes when it
hasn't. To finish parsing you have to keep iterating until one more
packet with size == 0 is returned.
Is this correct? Is the example code supposed to work with any codec
or only MP2?
_______________________________________________
Libav-user mailing list -- [email protected]
To unsubscribe send an email to [email protected]