Revision fec401f7 ffmpeg.c

View differences:

ffmpeg.c
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 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 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 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 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 1904
        if (ist->discard)
1907 1905
            goto discard_packet;
1908 1906

  
1907
        if (pkt.dts != AV_NOPTS_VALUE)
1908
            pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
1909
        if (pkt.pts != AV_NOPTS_VALUE)
1910
            pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base);
1911

  
1909 1912
//        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 1913
        if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {
1911 1914
            int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts;
......
1913 1916
                input_files_ts_offset[ist->file_index]-= delta;
1914 1917
                if (verbose > 2)
1915 1918
                    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
                }
1919
                pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
1920
                if(pkt.pts != AV_NOPTS_VALUE)
1921
                    pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
1921 1922
            }
1922 1923
        }
1923 1924

  

Also available in: Unified diff