1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

fftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts

InputFile.ts_offset can change during transcoding, due to discontinuity
correction. This should not affect the streamcopy starting timestamp.

Cf. bf2590aed3
This commit is contained in:
Anton Khirnov 2022-08-10 10:44:30 +02:00
parent 86e9cef77b
commit 274c8d5882
2 changed files with 18 additions and 5 deletions

View File

@ -1879,12 +1879,9 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
return; return;
if (!ost->streamcopy_started && !ost->copy_prior_start) { if (!ost->streamcopy_started && !ost->copy_prior_start) {
int64_t comp_start = start_time;
if (copy_ts && f->start_time != AV_NOPTS_VALUE)
comp_start = FFMAX(start_time, f->start_time + f->ts_offset);
if (pkt->pts == AV_NOPTS_VALUE ? if (pkt->pts == AV_NOPTS_VALUE ?
ist->pts < comp_start : ist->pts < ost->ts_copy_start :
pkt->pts < av_rescale_q(comp_start, AV_TIME_BASE_Q, ist->st->time_base)) pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, ist->st->time_base))
return; return;
} }
@ -2741,6 +2738,7 @@ static int init_output_stream_streamcopy(OutputStream *ost)
{ {
OutputFile *of = output_files[ost->file_index]; OutputFile *of = output_files[ost->file_index];
InputStream *ist = get_input_stream(ost); InputStream *ist = get_input_stream(ost);
InputFile *ifile = input_files[ist->file_index];
AVCodecParameters *par = ost->st->codecpar; AVCodecParameters *par = ost->st->codecpar;
AVCodecContext *codec_ctx; AVCodecContext *codec_ctx;
AVRational sar; AVRational sar;
@ -2805,6 +2803,15 @@ static int init_output_stream_streamcopy(OutputStream *ost)
if (ost->st->duration <= 0 && ist->st->duration > 0) if (ost->st->duration <= 0 && ist->st->duration > 0)
ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
if (!ost->copy_prior_start) {
ost->ts_copy_start = (of->start_time == AV_NOPTS_VALUE) ?
0 : of->start_time;
if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) {
ost->ts_copy_start = FFMAX(ost->ts_copy_start,
ifile->start_time + ifile->ts_offset);
}
}
if (ist->st->nb_side_data) { if (ist->st->nb_side_data) {
for (i = 0; i < ist->st->nb_side_data; i++) { for (i = 0; i < ist->st->nb_side_data; i++) {
const AVPacketSideData *sd_src = &ist->st->side_data[i]; const AVPacketSideData *sd_src = &ist->st->side_data[i];

View File

@ -484,6 +484,12 @@ typedef struct OutputStream {
int64_t last_mux_dts; int64_t last_mux_dts;
/* pts of the last frame received from the filters, in AV_TIME_BASE_Q */ /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
int64_t last_filter_pts; int64_t last_filter_pts;
// timestamp from which the streamcopied streams should start,
// in AV_TIME_BASE_Q;
// everything before it should be discarded
int64_t ts_copy_start;
// the timebase of the packets sent to the muxer // the timebase of the packets sent to the muxer
AVRational mux_timebase; AVRational mux_timebase;
AVRational enc_timebase; AVRational enc_timebase;