]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mov.c
Make Launch more appropriate with support for full paths for the ffmpeg binary
[ffmpeg] / libavformat / mov.c
index c2f7abffa019d655b24891f74509d49446a974f3..71cd5113b058eb636b30bda3cce2f6397ddc18eb 100644 (file)
@@ -118,6 +118,7 @@ static const CodecTag mov_video_tags[] = {
     { CODEC_ID_QTRLE, MKTAG('r', 'l', 'e', ' ') }, /* Apple Animation (RLE) */
     { CODEC_ID_QDRAW, MKTAG('q', 'd', 'r', 'w') }, /* QuickDraw */
     { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */
+    { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 produced by Sony HD camera */
     { CODEC_ID_NONE, 0 },
 };
 
@@ -144,6 +145,7 @@ static const CodecTag mov_audio_tags[] = {
     { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */
     { CODEC_ID_AC3, MKTAG('m', 's', 0x20, 0x00) }, /* Dolby AC-3 */
     { CODEC_ID_ALAC,MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */
+    { CODEC_ID_QDM2,MKTAG('Q', 'D', 'M', '2') }, /* QDM2 */
     { CODEC_ID_NONE, 0 },
 };
 
@@ -480,16 +482,16 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
         /* helps parsing the string hereafter... */
         c->mp4 = 0;
         if(type == MKTAG('v', 'i', 'd', 'e'))
-            st->codec.codec_type = CODEC_TYPE_VIDEO;
+            st->codec->codec_type = CODEC_TYPE_VIDEO;
         else if(type == MKTAG('s', 'o', 'u', 'n'))
-            st->codec.codec_type = CODEC_TYPE_AUDIO;
+            st->codec->codec_type = CODEC_TYPE_AUDIO;
     } else if(ctype == 0) { /* MP4 */
         /* helps parsing the string hereafter... */
         c->mp4 = 1;
         if(type == MKTAG('v', 'i', 'd', 'e'))
-            st->codec.codec_type = CODEC_TYPE_VIDEO;
+            st->codec->codec_type = CODEC_TYPE_VIDEO;
         else if(type == MKTAG('s', 'o', 'u', 'n'))
-            st->codec.codec_type = CODEC_TYPE_AUDIO;
+            st->codec->codec_type = CODEC_TYPE_AUDIO;
     }
     get_be32(pb); /* component  manufacture */
     get_be32(pb); /* component flags */
@@ -549,15 +551,6 @@ static int mov_mp4_read_descr(ByteIOContext *pb, int *tag)
     return len;
 }
 
-static inline unsigned int get_be24(ByteIOContext *s)
-{
-    unsigned int val;
-    val = get_byte(s) << 16;
-    val |= get_byte(s) << 8;
-    val |= get_byte(s);
-    return val;
-}
-
 static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 {
     AVStream *st = c->fc->streams[c->fc->nb_streams-1];
@@ -590,10 +583,10 @@ static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 #ifdef DEBUG
            av_log(NULL, AV_LOG_DEBUG, "Specific MPEG4 header len=%d\n", len);
 #endif
-           st->codec.extradata = (uint8_t*) av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
-           if (st->codec.extradata) {
-               get_buffer(pb, st->codec.extradata, len);
-               st->codec.extradata_size = len;
+           st->codec->extradata = (uint8_t*) av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
+           if (st->codec->extradata) {
+               get_buffer(pb, st->codec->extradata, len);
+               st->codec->extradata_size = len;
            }
        }
     }
@@ -648,11 +641,12 @@ static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
     get_be32(pb); /* modification time */
 
     c->streams[c->fc->nb_streams-1]->time_scale = get_be32(pb);
+    av_set_pts_info(c->fc->streams[c->fc->nb_streams-1], 64, 1, c->streams[c->fc->nb_streams-1]->time_scale);
 
 #ifdef DEBUG
     av_log(NULL, AV_LOG_DEBUG, "track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->time_scale); /* time scale */
 #endif
-    get_be32(pb); /* duration */
+    c->fc->streams[c->fc->nb_streams-1]->duration= get_be32(pb); /* duration */
 
     get_be16(pb); /* language */
     get_be16(pb); /* quality */
@@ -702,14 +696,35 @@ static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
     
     // currently SVQ3 decoder expect full STSD header - so let's fake it
     // this should be fixed and just SMI header should be passed
-    av_free(st->codec.extradata);
-    st->codec.extradata_size = 0x5a + atom.size;
-    st->codec.extradata = (uint8_t*) av_mallocz(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
-
-    if (st->codec.extradata) {
-       strcpy(st->codec.extradata, "SVQ3"); // fake
-       get_buffer(pb, st->codec.extradata + 0x5a, atom.size);
-       //av_log(NULL, AV_LOG_DEBUG, "Reading SMI %Ld  %s\n", atom.size, (char*)st->codec.extradata + 0x5a);
+    av_free(st->codec->extradata);
+    st->codec->extradata_size = 0x5a + atom.size;
+    st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+    if (st->codec->extradata) {
+       strcpy(st->codec->extradata, "SVQ3"); // fake
+       get_buffer(pb, st->codec->extradata + 0x5a, atom.size);
+       //av_log(NULL, AV_LOG_DEBUG, "Reading SMI %Ld  %s\n", atom.size, (char*)st->codec->extradata + 0x5a);
+    } else
+       url_fskip(pb, atom.size);
+
+    return 0;
+}
+
+static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
+{
+    AVStream *st = c->fc->streams[c->fc->nb_streams-1];
+
+    if((uint64_t)atom.size > (1<<30))
+        return -1;
+    
+    // pass all frma atom to codec, needed at least for QDM2
+    av_free(st->codec->extradata);
+    st->codec->extradata_size = atom.size;
+    st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+    if (st->codec->extradata) {
+       get_buffer(pb, st->codec->extradata, atom.size);
+       //av_log(NULL, AV_LOG_DEBUG, "Reading frma %Ld  %s\n", atom.size, (char*)st->codec->extradata);
     } else
        url_fskip(pb, atom.size);
 
@@ -723,13 +738,13 @@ static int mov_read_avcC(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
     if((uint64_t)atom.size > (1<<30))
         return -1;
 
-    av_free(st->codec.extradata);
+    av_free(st->codec->extradata);
 
-    st->codec.extradata_size = atom.size;
-    st->codec.extradata = (uint8_t*) av_mallocz(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+    st->codec->extradata_size = atom.size;
+    st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
 
-    if (st->codec.extradata) {
-       get_buffer(pb, st->codec.extradata, atom.size);
+    if (st->codec->extradata) {
+       get_buffer(pb, st->codec->extradata, atom.size);
     } else
        url_fskip(pb, atom.size);
 
@@ -789,7 +804,7 @@ static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 {
     AVStream *st = c->fc->streams[c->fc->nb_streams-1];
-    //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
+    MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
     int entries, frames_per_sample;
     uint32_t format;
     uint8_t codec_name[32];
@@ -828,7 +843,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
             AVCodec *codec;
            codec = avcodec_find_decoder(id);
             if (codec)
-               st->codec.codec_type = codec->type;
+               st->codec->codec_type = codec->type;
         }
 #ifdef DEBUG
         av_log(NULL, AV_LOG_DEBUG, "size=%d 4CC= %c%c%c%c codec_type=%d\n",
@@ -837,23 +852,23 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                (format >> 8) & 0xff,
                (format >> 16) & 0xff,
                (format >> 24) & 0xff,
-               st->codec.codec_type);
+               st->codec->codec_type);
 #endif
-       st->codec.codec_tag = format;
-       if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
+       st->codec->codec_tag = format;
+       if(st->codec->codec_type==CODEC_TYPE_VIDEO) {
            MOV_atom_t a = { 0, 0, 0 };
-            st->codec.codec_id = id;
+            st->codec->codec_id = id;
             get_be16(pb); /* version */
             get_be16(pb); /* revision level */
             get_be32(pb); /* vendor */
             get_be32(pb); /* temporal quality */
             get_be32(pb); /* spacial quality */
-            if(st->codec.codec_id == CODEC_ID_MPEG4){ //FIXME this is silly
+            if(st->codec->codec_id == CODEC_ID_MPEG4){ //FIXME this is silly
                 get_be16(pb);
                 get_be16(pb);
             }else{
-                st->codec.width = get_be16(pb); /* width */
-                st->codec.height = get_be16(pb); /* height */
+                st->codec->width = get_be16(pb); /* width */
+                st->codec->height = get_be16(pb); /* height */
             }
             get_be32(pb); /* horiz resolution */
             get_be32(pb); /* vert resolution */
@@ -864,16 +879,16 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 #endif
         get_buffer(pb, codec_name, 32); /* codec name, pascal string (FIXME: true for mp4?) */
         if (codec_name[0] <= 31) {
-            memcpy(st->codec.codec_name, &codec_name[1],codec_name[0]);
-            st->codec.codec_name[codec_name[0]] = 0;
+            memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]);
+            st->codec->codec_name[codec_name[0]] = 0;
         }
 
-           st->codec.bits_per_sample = get_be16(pb); /* depth */
-            st->codec.color_table_id = get_be16(pb); /* colortable id */
+           st->codec->bits_per_sample = get_be16(pb); /* depth */
+            st->codec->color_table_id = get_be16(pb); /* colortable id */
 
 /*          These are set in mov_read_stts and might already be set!
-            st->codec.time_base.den      = 25;
-            st->codec.time_base.num = 1;
+            st->codec->time_base.den      = 25;
+            st->codec->time_base.num = 1;
 */
            size -= (16+8*4+2+32+2*2);
 #if 0
@@ -947,8 +962,8 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 #else
 
             /* figure out the palette situation */
-            color_depth = st->codec.bits_per_sample & 0x1F;
-            color_greyscale = st->codec.bits_per_sample & 0x20;
+            color_depth = st->codec->bits_per_sample & 0x1F;
+            color_greyscale = st->codec->bits_per_sample & 0x20;
 
             /* if the depth is 2, 4, or 8 bpp, file is palettized */
             if ((color_depth == 2) || (color_depth == 4) || 
@@ -969,7 +984,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                             color_index = 0;
                     }
 
-                } else if (st->codec.color_table_id & 0x08) {
+                } else if (st->codec->color_table_id & 0x08) {
 
                     /* if flag bit 3 is set, use the default palette */
                     color_count = 1 << color_depth;
@@ -1011,17 +1026,17 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                     }
                 }
 
-                st->codec.palctrl = &c->palette_control;
-                st->codec.palctrl->palette_changed = 1;
+                st->codec->palctrl = &c->palette_control;
+                st->codec->palctrl->palette_changed = 1;
             } else
-                st->codec.palctrl = NULL;
+                st->codec->palctrl = NULL;
 
             a.size = size;
            mov_read_default(c, pb, a);
 #endif
        } else {
-            st->codec.codec_id = codec_get_id(mov_audio_tags, format);
-           if(st->codec.codec_id==CODEC_ID_AMR_NB || st->codec.codec_id==CODEC_ID_AMR_WB) //from TS26.244
+            st->codec->codec_id = codec_get_id(mov_audio_tags, format);
+           if(st->codec->codec_id==CODEC_ID_AMR_NB || st->codec->codec_id==CODEC_ID_AMR_WB) //from TS26.244
            {
 #ifdef DEBUG
                av_log(NULL, AV_LOG_DEBUG, "AMR-NB or AMR-WB audio identified!!\n");
@@ -1044,21 +1059,21 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                get_byte(pb); //frames_per_sample
 
                st->duration = AV_NOPTS_VALUE;//Not possible to get from this info, must count number of AMR frames
-               if(st->codec.codec_id==CODEC_ID_AMR_NB)
+               if(st->codec->codec_id==CODEC_ID_AMR_NB)
                {
-                   st->codec.sample_rate=8000;
-                   st->codec.channels=1;
+                   st->codec->sample_rate=8000;
+                   st->codec->channels=1;
                }
                else //AMR-WB
                {
-                   st->codec.sample_rate=16000;
-                   st->codec.channels=1;
+                   st->codec->sample_rate=16000;
+                   st->codec->channels=1;
                }
-               st->codec.bits_per_sample=16;
-               st->codec.bit_rate=0; /*It is not possible to tell this before we have 
+               st->codec->bits_per_sample=16;
+               st->codec->bit_rate=0; /*It is not possible to tell this before we have 
                                        an audio frame and even then every frame can be different*/
            }
-            else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 's' ))
+            else if( st->codec->codec_tag == MKTAG( 'm', 'p', '4', 's' ))
             {
                 //This is some stuff for the hint track, lets ignore it!
                 //Do some mp4 auto detect.
@@ -1066,7 +1081,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                 size-=(16);
                 url_fskip(pb, size); /* The mp4s atom also contians a esds atom that we can skip*/
             }
-            else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 'a' ))
+            else if( st->codec->codec_tag == MKTAG( 'm', 'p', '4', 'a' ))
             {
                 MOV_atom_t a;
                 int mp4_version;
@@ -1075,10 +1090,13 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                 mp4_version=get_be16(pb);/*version*/
                 get_be16(pb); /*revesion*/
                 get_be32(pb);
-                st->codec.channels = get_be16(pb); /* channels */
-                st->codec.bits_per_sample = get_be16(pb); /* bits per sample */
+                st->codec->channels = get_be16(pb); /* channels */
+                st->codec->bits_per_sample = get_be16(pb); /* bits per sample */
                 get_be32(pb);
-                st->codec.sample_rate = get_be16(pb); /* sample rate, not always correct */
+                st->codec->sample_rate = get_be16(pb); /* sample rate, not always correct */
+                if(st->codec->sample_rate == 1) //nonsese rate? -> ignore
+                    st->codec->sample_rate= 0;
+
                 get_be16(pb);
                 c->mp4=1;
                 
@@ -1095,35 +1113,35 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                 mov_read_default(c, pb, a);
 
                 /* Get correct sample rate from extradata */
-                if(st->codec.extradata_size) {
+                if(st->codec->extradata_size) {
                    const int samplerate_table[] = {
                      96000, 88200, 64000, 48000, 44100, 32000, 
                      24000, 22050, 16000, 12000, 11025, 8000,
                      7350, 0, 0, 0
                    };
-                   unsigned char *px = st->codec.extradata;
+                   unsigned char *px = st->codec->extradata;
                    // 5 bits objectTypeIndex, 4 bits sampleRateIndex, 4 bits channels
                    int samplerate_index = ((px[0] & 7) << 1) + ((px[1] >> 7) & 1);
-                   st->codec.sample_rate = samplerate_table[samplerate_index];
-                   st->codec.channels = (px[1] >> 3) & 15;
+                   st->codec->sample_rate = samplerate_table[samplerate_index];
+                   st->codec->channels = (px[1] >> 3) & 15;
                 }
             }
-            else if( st->codec.codec_tag == MKTAG( 'a', 'l', 'a', 'c' ))
+            else if( st->codec->codec_tag == MKTAG( 'a', 'l', 'a', 'c' ))
             {
                 /* Handle alac audio tag + special extradata */
                 get_be32(pb); /* version */
                 get_be32(pb);
-                st->codec.channels = get_be16(pb); /* channels */
-                st->codec.bits_per_sample = get_be16(pb); /* bits per sample */
+                st->codec->channels = get_be16(pb); /* channels */
+                st->codec->bits_per_sample = get_be16(pb); /* bits per sample */
                 get_be32(pb);
-                st->codec.sample_rate = get_be16(pb);
+                st->codec->sample_rate = get_be16(pb);
                 get_be16(pb);
 
                 /* fetch the 36-byte extradata needed for alac decoding */
-                st->codec.extradata_size = 36;
-                st->codec.extradata = (uint8_t*) 
-                    av_mallocz(st->codec.extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
-                get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
+                st->codec->extradata_size = 36;
+                st->codec->extradata = (uint8_t*) 
+                    av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+                get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
             }
            else if(size>=(16+20))
            {//16 bytes read, reading atleast 20 more
@@ -1135,23 +1153,23 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
                 get_be16(pb); /* revision level */
                 get_be32(pb); /* vendor */
 
-                st->codec.channels = get_be16(pb);             /* channel count */
-               st->codec.bits_per_sample = get_be16(pb);       /* sample size */
+                st->codec->channels = get_be16(pb);            /* channel count */
+               st->codec->bits_per_sample = get_be16(pb);      /* sample size */
 
                 /* handle specific s8 codec */
                 get_be16(pb); /* compression id = 0*/
                 get_be16(pb); /* packet size = 0 */
 
-                st->codec.sample_rate = ((get_be32(pb) >> 16));
-               //av_log(NULL, AV_LOG_DEBUG, "CODECID %d  %d  %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format);
+                st->codec->sample_rate = ((get_be32(pb) >> 16));
+               //av_log(NULL, AV_LOG_DEBUG, "CODECID %d  %d  %.4s\n", st->codec->codec_id, CODEC_ID_PCM_S16BE, (char*)&format);
 
-               switch (st->codec.codec_id) {
+               switch (st->codec->codec_id) {
                case CODEC_ID_PCM_S16BE:
-                   if (st->codec.bits_per_sample == 8)
-                       st->codec.codec_id = CODEC_ID_PCM_S8;
+                   if (st->codec->bits_per_sample == 8)
+                       st->codec->codec_id = CODEC_ID_PCM_S8;
                     /* fall */
                case CODEC_ID_PCM_U8:
-                   st->codec.bit_rate = st->codec.sample_rate * 8;
+                   st->codec->bit_rate = st->codec->sample_rate * 8;
                    break;
                default:
                     ;
@@ -1204,6 +1222,10 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
             }
         }
     }
+    
+    if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) {
+        st->codec->sample_rate= sc->time_scale;
+    }
 
     return 0;
 }
@@ -1338,44 +1360,17 @@ av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1,
         sample_duration = get_be32(pb);
         c->streams[c->fc->nb_streams - 1]->stts_data[i].count= sample_count;
         c->streams[c->fc->nb_streams - 1]->stts_data[i].duration= sample_duration;
+
 #ifdef DEBUG
         av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
 #endif
         duration+=sample_duration*sample_count;
         total_sample_count+=sample_count;
-
-#if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone
-
-        if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
-            st->codec.time_base.num = sample_duration ? sample_duration : 1;
-            st->codec.time_base.den = c->streams[c->fc->nb_streams-1]->time_scale;
-#ifdef DEBUG
-            av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.time_base.den, sample_duration);
-#endif
-        }
-#endif
     }
 
-    /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/
-    if(duration>0)
-    {
-        av_reduce(
-            &st->codec.time_base.den, 
-            &st->codec.time_base.num, 
-            c->streams[c->fc->nb_streams-1]->time_scale * total_sample_count,
-            duration,
-            INT_MAX
-        );
-
-#ifdef DEBUG
-        av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.time_base.den/st->codec.time_base.num,total_sample_count,duration,c->streams[c->fc->nb_streams-1]->time_scale);
-#endif
-    }
-    else
-    {
-        st->codec.time_base.num = 1;
-        st->codec.time_base.den = c->streams[c->fc->nb_streams-1]->time_scale;
-    }
+    st->nb_frames= total_sample_count;
+    if(duration)
+        st->duration= duration;
     return 0;
 }
 
@@ -1423,9 +1418,8 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
 
     sc->sample_to_chunk_index = -1;
     st->priv_data = sc;
-    st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
+    st->codec->codec_type = CODEC_TYPE_MOV_OTHER;
     st->start_time = 0; /* XXX: check */
-    st->duration = (c->duration * (int64_t)AV_TIME_BASE) / c->time_scale;
     c->streams[c->fc->nb_streams-1] = sc;
 
     return mov_read_default(c, pb, atom);
@@ -1455,7 +1449,7 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
     st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
     get_be32(pb); /* reserved */
     st->start_time = 0; /* check */
-    st->duration = (get_be32(pb) * (int64_t)AV_TIME_BASE) / c->time_scale; /* duration */
+    get_be32(pb); /* highlevel (considering edits) duration in movie timebase */
     get_be32(pb); /* reserved */
     get_be32(pb); /* reserved */
 
@@ -1467,8 +1461,8 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
     url_fskip(pb, 36); /* display matrix */
 
     /* those are fixed-point */
-    st->codec.width = get_be32(pb) >> 16; /* track width */
-    st->codec.height = get_be32(pb) >> 16; /* track height */
+    /*st->codec->width =*/ get_be32(pb) >> 16; /* track width */
+    /*st->codec->height =*/ get_be32(pb) >> 16; /* track height */
 
     return 0;
 }
@@ -1633,7 +1627,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf },
 { MKTAG( 'u', 'u', 'i', 'd' ), mov_read_leaf },
 { MKTAG( 'v', 'm', 'h', 'd' ), mov_read_leaf }, /* video media info header */
-{ MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default },
+{ MKTAG( 'w', 'a', 'v', 'e' ), mov_read_wave },
 /* extra mp4 */
 { MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf },
 /* QT atoms */
@@ -1779,7 +1773,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
 
 #if 1
     for(i=0; i<s->nb_streams;) {
-        if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
+        if(s->streams[i]->codec->codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
             av_free(s->streams[i]);
             for(j=i+1; j<s->nb_streams; j++)
                 s->streams[j-1] = s->streams[j];
@@ -1918,7 +1912,7 @@ again:
             {
                // I can't figure out why for PCM audio sample_size is always 1
                // (it should actually be channels*bits_per_second/8) but it is.
-               AVCodecContext* cod = &s->streams[sc->ffindex]->codec;
+               AVCodecContext* cod = s->streams[sc->ffindex]->codec;
                 if (sc->sample_size == 1 && (cod->codec_id == CODEC_ID_PCM_S16BE || cod->codec_id == CODEC_ID_PCM_S16LE))
                    foundsize=(sc->sample_to_chunk[i].count*cod->channels*cod->bits_per_sample)/8;
                else
@@ -2033,12 +2027,8 @@ readchunk:
             pts = dts + duration;
         }else
             pts = dts;
-        pkt->pts = av_rescale( pts,
-                         (int64_t)s->streams[sc->ffindex]->time_base.den,
-                         (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num );
-        pkt->dts = av_rescale( dts,
-                         (int64_t)s->streams[sc->ffindex]->time_base.den,
-                         (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num );
+        pkt->pts = pts;
+        pkt->dts = dts;
 #ifdef DEBUG
     av_log(NULL, AV_LOG_DEBUG, "stream #%d smp #%ld dts = %lld pts = %lld (smp:%ld time:%lld idx:%d ent:%d count:%d dur:%d)\n"
       , pkt->stream_index, sc->current_sample-1, pkt->dts, pkt->pts
@@ -2058,12 +2048,11 @@ readchunk:
 /**
  * Seek method based on the one described in the Appendix C of QTFileFormat.pdf
  */
-static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
+static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
 {
     MOVContext* mov = (MOVContext *) s->priv_data;
     MOVStreamContext* sc;
     int32_t i, a, b, m;
-    int64_t sample_time;
     int64_t start_time;
     int32_t seek_sample, sample;
     int32_t duration;
@@ -2100,10 +2089,6 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
 #ifdef DEBUG
   av_log(s, AV_LOG_DEBUG, "Searching for time %li in stream #%i (time_scale=%i)\n", (long)timestamp, mov_idx, sc->time_scale);
 #endif
-    // convert timestamp from time_base unit to timescale unit
-    sample_time = av_rescale( timestamp,
-                            (int64_t)sc->time_scale * s->streams[stream_index]->time_base.num,
-                            (int64_t)s->streams[stream_index]->time_base.den);
     start_time = 0; // FIXME use elst atom
     sample = 1; // sample are 0 based in table
 #ifdef DEBUG