[FFmpeg-devel] [PATCH] wrong time base for audio in AVI

Reimar Döffinger Reimar.Doeffinger
Sun Apr 13 11:49:31 CEST 2008


On Sun, Apr 13, 2008 at 11:28:54AM +0200, Michael Niedermayer wrote:
> On Sun, Apr 13, 2008 at 10:56:22AM +0200, Reimar D?ffinger wrote:
> [...]
> > > > tell, though pkt->duration == 0 sounds unhealthy to me.
> > > 
> > > Well its the best it can be set to within the constrains ...
> > 
> > Which is why I assumed the constraints to be wrong (and I still think
> > they are, but I am not motivated to investigate further right now).
> 
> The constraint is the timebase in the header i assume. Thats what the
> muxer decided to store there, it would not be any less wrong to export
> another timebase than what is stored in the header. You simply cannot
> both export the correct timebase and correct duration in that timebase.

IMO no, the header does not contain a time base and the AVI demuxer
falls back to 1/framerate (using frame_period), even for the audio stream.
This is why I overwrote it with 1/samplerate, since 1/framerate seemed
like a rather idiotic time base for the audio stream to me.
Unfortunately things are not as simple as I imagine it to be, this can't
simply be changes as e.g. attached patch would do, since this completely
breaks the audio timestamps.
Probably it's not worth "fixing", it just annoys me a bit.

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/avidec.c
===================================================================
--- libavformat/avidec.c	(revision 12797)
+++ libavformat/avidec.c	(working copy)
@@ -45,6 +45,7 @@
     int prefix_count;
     uint32_t pal[256];
     int has_pal;
+    int guessed_timebase;
 } AVIStream;
 
 typedef struct {
@@ -383,9 +384,11 @@
             }else if(frame_period){
                 ast->rate = 1000000;
                 ast->scale = frame_period;
+                ast->guessed_timebase = 1;
             }else{
                 ast->rate = 25;
                 ast->scale = 1;
+                ast->guessed_timebase = 1;
             }
             av_set_pts_info(st, 64, ast->scale, ast->rate);
 
@@ -494,6 +503,11 @@
                         av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align);
                         ast->sample_size= st->codec->block_align;
                     }
+                    if (ast->guessed_timebase && st->codec->sample_rate) {
+                        ast->scale = 1;
+                        ast->rate = st->codec->sample_rate;
+                        av_set_pts_info(st, 64, ast->scale, ast->rate);
+                    }
                     if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
                         url_fskip(pb, 1);
                     /* Force parsing as several audio frames can be in



More information about the ffmpeg-devel mailing list