All pastes #1598719 Raw Edit

Stuff

public text v1 · immutable
#1598719 ·published 2009-10-06 16:43 UTC
rendered paste body
Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
--- libs/libmythtv/avformatdecoder.cpp	(revision 22272)
+++ libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -606,9 +606,13 @@
     if (CODEC_IS_MPEG(context->codec_id))
         frameseekadjust = maxkeyframedist+1;
 
+    long long startts = av_rescale(ic->start_time,
+                                (int64_t)AV_TIME_BASE * (int64_t)st->time_base.num,
+                                st->time_base.den);
+
     // convert framenumber to normalized timestamp
     long double diff = (max(desiredFrame - frameseekadjust, 0LL)) * AV_TIME_BASE;
-    long long ts = (long long)( diff / fps );
+    long long ts = startts + (long long)( diff / fps );
     if (av_seek_frame(ic, -1, ts, AVSEEK_FLAG_BACKWARD) < 0)
     {
         VERBOSE(VB_IMPORTANT, LOC_ERR
@@ -620,8 +624,8 @@
     // libav sometimes returns the end of the stream instead.
     if (desiredFrame <= 1)
     {
-        av_update_cur_dts(ic, st, 0);
-        ic->start_time = 0;
+        av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BACKWARD);
+        ic->start_time = st->cur_dts;
     }
 
     int normalframes = 0;
@@ -633,11 +637,7 @@
 
         if (ic->start_time != (int64_t)AV_NOPTS_VALUE)
         {
-            int64_t st1 = av_rescale(ic->start_time,
-                                    st->time_base.den,
-                                    AV_TIME_BASE * (int64_t)st->time_base.num);
-            adj_cur_dts = lsb3full(adj_cur_dts, st1, st->pts_wrap_bits);
-
+            adj_cur_dts = lsb3full(adj_cur_dts, ic->start_time, st->pts_wrap_bits);
         }
 
         long long newts = av_rescale(adj_cur_dts,
@@ -1178,6 +1178,10 @@
     if (ringBuffer->isDVD())
         directrendering = false;
 
+    av_seek_frame(ic, -1, 0, AVSEEK_FLAG_BACKWARD);
+    ic->start_time = stream->cur_dts;
+    VERBOSE(VB_PLAYBACK, LOC + "Setting context start_time to " << ic->start_time);
+
     if (selectedStream)
     {
         fps = normalized_fps(stream, enc);