changeset 1292:6042770198c6 libavformat

move track timescale/sampleDuration init to write_header and return error if not set
author bcoudurier
date Mon, 04 Sep 2006 14:22:44 +0000
parents 185190bdc185
children 1816e097c39f
files movenc.c
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/movenc.c	Mon Sep 04 09:57:47 2006 +0000
+++ b/movenc.c	Mon Sep 04 14:22:44 2006 +0000
@@ -1299,14 +1299,6 @@
     for (i=0; i<mov->nb_streams; i++) {
         if(mov->tracks[i].entry <= 0) continue;
 
-        if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
-            mov->tracks[i].timescale = mov->tracks[i].enc->time_base.den;
-            mov->tracks[i].sampleDuration = mov->tracks[i].enc->time_base.num;
-        } else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
-            mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
-            mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
-        }
-
         mov->tracks[i].trackDuration =
             (int64_t)mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
         mov->tracks[i].time = mov->time;
@@ -1468,12 +1460,20 @@
         track->mode = mov->mode;
         if(st->codec->codec_type == CODEC_TYPE_VIDEO){
             track->tag = mov_find_video_codec_tag(s, track);
+            track->timescale = st->codec->time_base.den;
+            track->sampleDuration = st->codec->time_base.num;
             av_set_pts_info(st, 64, 1, st->codec->time_base.den);
         }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
             track->tag = mov_find_audio_codec_tag(s, track);
+            track->timescale = st->codec->sample_rate;
+            track->sampleDuration = st->codec->frame_size;
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
             track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
         }
+        if (!track->sampleDuration) {
+            av_log(s, AV_LOG_ERROR, "track %d: sample duration is not set\n", i);
+            return -1;
+        }
     }
 
     mov_write_mdat_tag(pb, mov);