aboutsummaryrefslogtreecommitdiffstats
path: root/fftools
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-04-26 10:51:38 +0200
committerAnton Khirnov <anton@khirnov.net>2023-05-02 10:59:24 +0200
commit129c7bf53fbe2be4f5483ecf6fc036ff9caf05cf (patch)
tree902666c7ed1467c945c99ebba05d69943b32dc74 /fftools
parent3190bed148df57740ef818764979d60dde53d3d0 (diff)
downloadffmpeg-129c7bf53fbe2be4f5483ecf6fc036ff9caf05cf.tar.gz
fftools/ffmpeg: always use the same path for setting InputStream.[next_]dts
Currently those are set in different ways depending on whether the stream is decoded or not, using some values from the decoder if it is. This is wrong, because there may be arbitrary amount of delay between input packets and output frames (depending e.g. on the thread count when frame threading is used). Always use the path that was previously used only for streamcopy. This should not cause any issues, because these values are now used only for streamcopy and discontinuity handling. This change will allow to decouple discontinuity processing from decoding and move it to ffmpeg_demux. It also makes the code simpler. Changes output in fate-cover-art-aiff-id3v2-remux and fate-cover-art-mp3-id3v2-remux, where attached pictures are now written in the correct order. This happens because InputStream.dts is no longer reset to AV_NOPTS_VALUE after decoding, so streamcopy actually sees valid dts values.
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index bb8c6bf00c..be9a3b2e34 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -982,11 +982,6 @@ static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output,
ist->samples_decoded += decoded_frame->nb_samples;
ist->frames_decoded++;
- /* increment next_dts to use for the case where the input stream does not
- have timestamps or there are multiple frames in the packet */
- ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
- decoded_frame->sample_rate;
-
audio_ts_process(ist, decoded_frame);
ist->nb_samples = decoded_frame->nb_samples;
@@ -1401,7 +1396,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
if (!ist->saw_first_ts) {
ist->first_dts =
ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
- if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
+ if (pkt && pkt->pts != AV_NOPTS_VALUE) {
ist->first_dts =
ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
}
@@ -1424,13 +1419,10 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
// while we have more to decode or while the decoder did output something on EOF
while (ist->decoding_needed) {
- int64_t duration_dts = 0;
int64_t duration_pts = 0;
int got_output = 0;
int decode_failed = 0;
- ist->dts = ist->next_dts;
-
switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output,
@@ -1440,23 +1432,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
case AVMEDIA_TYPE_VIDEO:
ret = decode_video (ist, repeating ? NULL : avpkt, &got_output, &duration_pts, !pkt,
&decode_failed);
- if (!repeating || !pkt || got_output) {
- if (pkt && pkt->duration) {
- duration_dts = av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
- } else if(ist->dec_ctx->framerate.num != 0 && ist->dec_ctx->framerate.den != 0) {
- int ticks = ist->last_pkt_repeat_pict >= 0 ?
- ist->last_pkt_repeat_pict + 1 :
- ist->dec_ctx->ticks_per_frame;
- duration_dts = ((int64_t)AV_TIME_BASE *
- ist->dec_ctx->framerate.den * ticks) /
- ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame;
- }
-
- if(ist->dts != AV_NOPTS_VALUE && duration_dts) {
- ist->next_dts += duration_dts;
- }else
- ist->next_dts = AV_NOPTS_VALUE;
- }
av_packet_unref(avpkt);
break;
@@ -1520,8 +1495,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
}
}
- /* handle stream copy */
- if (!ist->decoding_needed && pkt) {
+ if (pkt) {
ist->dts = ist->next_dts;
switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
@@ -1551,7 +1525,9 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
}
break;
}
- } else if (!ist->decoding_needed)
+ }
+
+ if (!pkt && !ist->decoding_needed)
eof_reached = 1;
duration_exceeded = 0;