]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mux.c
avutil/audio_fifo: split into a separate doxy module
[ffmpeg] / libavformat / mux.c
index 57044f3ab23c201b815f6bbefb506b84ad5346c8..687f7043da529c08147125af3a4425318b99190b 100644 (file)
@@ -107,11 +107,8 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precisio
     AVRational q;
     int j;
 
-    if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-        q = (AVRational){1, st->codec->sample_rate};
-    } else {
-        q = st->codec->time_base;
-    }
+    q = st->time_base;
+
     for (j=2; j<14; j+= 1+(j>2))
         while (q.den / q.num < min_precision && q.num % j == 0)
             q.num /= j;
@@ -252,6 +249,25 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
         st    = s->streams[i];
         codec = st->codec;
 
+#if FF_API_LAVF_CODEC_TB
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (!st->time_base.num && codec->time_base.num) {
+            av_log(s, AV_LOG_WARNING, "Using AVStream.codec.time_base as a "
+                   "timebase hint to the muxer is deprecated. Set "
+                   "AVStream.time_base instead.\n");
+            avpriv_set_pts_info(st, 64, codec->time_base.num, codec->time_base.den);
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+        if (!st->time_base.num) {
+            /* fall back on the default timebase values */
+            if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->sample_rate)
+                avpriv_set_pts_info(st, 64, 1, codec->sample_rate);
+            else
+                avpriv_set_pts_info(st, 33, 1, 90000);
+        }
+
         switch (codec->codec_type) {
         case AVMEDIA_TYPE_AUDIO:
             if (codec->sample_rate <= 0) {
@@ -264,13 +280,6 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
                                      av_get_bits_per_sample(codec->codec_id) >> 3;
             break;
         case AVMEDIA_TYPE_VIDEO:
-            if (codec->time_base.num <= 0 ||
-                codec->time_base.den <= 0) { //FIXME audio too?
-                av_log(s, AV_LOG_ERROR, "time base not set\n");
-                ret = AVERROR(EINVAL);
-                goto fail;
-            }
-
             if ((codec->width <= 0 || codec->height <= 0) &&
                 !(of->flags & AVFMT_NODIMENSIONS)) {
                 av_log(s, AV_LOG_ERROR, "dimensions not set\n");
@@ -623,7 +632,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
     if (!pkt) {
         if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
             ret = s->oformat->write_packet(s, NULL);
-            if (s->flush_packets && s->pb && s->pb->error >= 0)
+            if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
                 avio_flush(s->pb);
             if (ret >= 0 && s->pb && s->pb->error < 0)
                 ret = s->pb->error;