Browse code

properly implement "user specified start time offset" which was added in r3217 -ss should now work again fixes decoding of low.ogg closes issue47

Originally committed as revision 9876 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2007/08/04 04:21:50
Showing 1 changed files
... ...
@@ -400,7 +400,7 @@ static double
400 400
 get_sync_ipts(const AVOutputStream *ost)
401 401
 {
402 402
     const AVInputStream *ist = ost->sync_ist;
403
-    return (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/AV_TIME_BASE;
403
+    return (double)(ist->pts - start_time)/AV_TIME_BASE;
404 404
 }
405 405
 
406 406
 static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
... ...
@@ -659,7 +659,7 @@ static void do_subtitle_out(AVFormatContext *s,
659 659
         pkt.stream_index = ost->index;
660 660
         pkt.data = subtitle_out;
661 661
         pkt.size = subtitle_out_size;
662
-        pkt.pts = av_rescale_q(av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
662
+        pkt.pts = av_rescale_q(pts, ist->st->time_base, ost->st->time_base);
663 663
         if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) {
664 664
             /* XXX: the pts correction is handled here. Maybe handling
665 665
                it in the codec would be better */
... ...
@@ -1226,7 +1226,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
1226 1226
 
1227 1227
                         opkt.stream_index= ost->index;
1228 1228
                         if(pkt->pts != AV_NOPTS_VALUE)
1229
-                            opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
1229
+                            opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base);
1230 1230
                         else
1231 1231
                             opkt.pts= AV_NOPTS_VALUE;
1232 1232
 
... ...
@@ -1236,7 +1236,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
1236 1236
                                 dts = ist->next_pts;
1237 1237
                             else
1238 1238
                                 dts= av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
1239
-                            opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
1239
+                            opkt.dts= av_rescale_q(dts, AV_TIME_BASE_Q,  ost->st->time_base);
1240 1240
                         }
1241 1241
                         opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);
1242 1242
                         opkt.flags= pkt->flags;
... ...
@@ -1766,10 +1766,8 @@ static int av_encode(AVFormatContext **output_files,
1766 1766
         ist = ist_table[i];
1767 1767
         is = input_files[ist->file_index];
1768 1768
         ist->pts = 0;
1769
-        ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q);
1770
-        if(ist->st->start_time == AV_NOPTS_VALUE)
1771
-            ist->next_pts=0;
1772
-        if(input_files_ts_offset[ist->file_index])
1769
+        ist->next_pts=0;
1770
+        if(input_files_ts_offset[ist->file_index] != -is->start_time)
1773 1771
             ist->next_pts= AV_NOPTS_VALUE;
1774 1772
         ist->is_start = 1;
1775 1773
     }
... ...
@@ -1906,6 +1904,11 @@ static int av_encode(AVFormatContext **output_files,
1906 1906
         if (ist->discard)
1907 1907
             goto discard_packet;
1908 1908
 
1909
+        if (pkt.dts != AV_NOPTS_VALUE)
1910
+            pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
1911
+        if (pkt.pts != AV_NOPTS_VALUE)
1912
+            pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
1913
+
1909 1914
 //        fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type);
1910 1915
         if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {
1911 1916
             int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts;
... ...
@@ -1913,11 +1916,9 @@ static int av_encode(AVFormatContext **output_files,
1913 1913
                 input_files_ts_offset[ist->file_index]-= delta;
1914 1914
                 if (verbose > 2)
1915 1915
                     fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]);
1916
-                for(i=0; i<file_table[file_index].nb_streams; i++){
1917
-                    int index= file_table[file_index].ist_index + i;
1918
-                    ist_table[index]->next_pts += delta;
1919
-                    ist_table[index]->is_start=1;
1920
-                }
1916
+                pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
1917
+                if(pkt.pts != AV_NOPTS_VALUE)
1918
+                    pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
1921 1919
             }
1922 1920
         }
1923 1921