All pastes #2017925 Raw Edit

Anonymous

public text v1 · immutable
#2017925 ·published 2010-12-13 03:10 UTC
rendered paste body
Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
--- libs/libmythtv/avformatdecoder.cpp	(revision 27363)
+++ libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -942,7 +942,10 @@
     fmt->flags &= ~AVFMT_NOFILE;
 
     if (!ringBuffer->isDVD() && !ringBuffer->isBD() && !livetv)
+    {
         av_estimate_timings(ic, 0);
+        av_update_stream_timings_video(ic);
+    }
 
     // Scan for the initial A/V streams
     ret = ScanStreams(novideo);
@@ -4898,4 +4901,61 @@
     return fsize;
 }
 
+void AvFormatDecoder::av_update_stream_timings_video(AVFormatContext *ic)
+{
+    int64_t start_time, start_time1, end_time, end_time1;
+    int64_t duration, duration1;
+    int i;
+    AVStream *st = NULL;
+
+    start_time = INT64_MAX;
+    end_time = INT64_MIN;
+
+    for (uint i = 0; i < ic->nb_streams; i++)
+    {
+        AVStream *st1 = ic->streams[i];
+        if (st1 && st1->codec->codec_type == CODEC_TYPE_VIDEO)
+        {
+            st = st1;
+            break;
+        }
+    }
+    if (!st)
+        return;
+
+   duration = INT64_MIN;
+   st = ic->streams[i];
+   if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {
+       start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+       if (start_time1 < start_time)
+           start_time = start_time1;
+       if (st->duration != AV_NOPTS_VALUE) {
+           end_time1 = start_time1
+                     + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
+           if (end_time1 > end_time)
+               end_time = end_time1;
+       }
+   }
+   if (st->duration != AV_NOPTS_VALUE) {
+       duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
+       if (duration1 > duration)
+           duration = duration1;
+   }
+    if (start_time != INT64_MAX) {
+        ic->start_time = start_time;
+        if (end_time != INT64_MIN) {
+            if (end_time - start_time > duration)
+                duration = end_time - start_time;
+        }
+    }
+    if (duration != INT64_MIN) {
+        ic->duration = duration;
+        if (ic->file_size > 0) {
+            /* compute the bitrate */
+            ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
+                (double)ic->duration;
+        }
+    }
+}
+
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: libs/libmythtv/avformatdecoder.h
===================================================================
--- libs/libmythtv/avformatdecoder.h	(revision 27363)
+++ libs/libmythtv/avformatdecoder.h	(working copy)
@@ -234,6 +234,7 @@
     bool GenerateDummyVideoFrame(void);
     bool HasVideo(const AVFormatContext *ic);
     float normalized_fps(AVStream *stream, AVCodecContext *enc);
+    void av_update_stream_timings_video(AVFormatContext *ic);
 
   private:
     PrivateDecoder *private_dec;