New submission from fsoft <fstin...@gmx.de>:

I found, that the decoder for ogg-vorbis-file create too much samples. The first
(necessary) samples are fine. But then following additional samples like "fading
out" the track. It seems, that we can simply cutting off the additional samples.

I don't now, is this an error in the codec? Or can principle not do the codec
this better?

I'm looking in libavformat/oggdec.c. The funktion ogg_read_header() works fine
and we can find in ogg->streams[i].granule the right value for the number of
samples of the file.
But it seems, there is no way to committing this value to the codec in
libavcodec/vorbis_dec.c.

Therefore i have made a "private" hack for me in ffmpeg.c. The idea:
I count the decoded samples and when this number is greater then the duration i
cut off the additional samples.

I'm surprised, that in ffmpeg.c the structur AVInputStream have an (unused)
variable 'sample_index'. I use this for counting the samples.

In the line 1405 in the function output_packet() we find the function
avcodec_decode_audio3() for decoding. Towards i insert the following lines for
counting and cut off:

if (ist->st->duration > 0 &&                          // Is this possible:
ist->st->duration==0 ?
    ist->st->codec->codec_id == CODEC_ID_VORBIS) {    // Can we do that for ALL
Codecs or only for Vorbis?
   int samplesize = 2;
   switch (ist->st->codec->sample_fmt) {              // Or is ever
ist->st->codec->sample_fmt==SAMPLE_FMT_S16 ?
      case SAMPLE_FMT_U8: samplesize = 1; break;
      case SAMPLE_FMT_S16: samplesize = 2; break;
      case SAMPLE_FMT_S32: samplesize = 4; break;
      case SAMPLE_FMT_FLT: samplesize = sizeof(float); break;
      case SAMPLE_FMT_DBL: samplesize = sizeof(double); break;
   }
   samplesize *= ist->st->codec->channels;
   if (ist->sample_index + decoded_data_size / samplesize > ist->st->duration)
      decoded_data_size = samplesize * (ist->st->duration - ist->sample_index);
   ist->sample_index += decoded_data_size / samplesize;
}

This works fine for me.

----------
messages: 10964
priority: normal
status: new
substatus: new
title: Ogg Vorbis decoder create too much samples
type: bug

________________________________________________
FFmpeg issue tracker <iss...@roundup.ffmpeg.org>
<https://roundup.ffmpeg.org/issue2041>
________________________________________________

Reply via email to