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.
This commit is contained in:
Anton Khirnov 2023-04-26 10:51:38 +02:00
parent 3190bed148
commit 129c7bf53f
3 changed files with 35 additions and 59 deletions

View File

@ -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;

View File

@ -1,4 +1,4 @@
d4a9481090a8bab1a3f072a8108a1d6a *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
330ad2bf538e91a31752b38024461df1 *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
608914 tests/data/fate/cover-art-aiff-id3v2-remux.aiff
#tb 0: 1/44100
#media_type 0: audio
@ -12,24 +12,24 @@ d4a9481090a8bab1a3f072a8108a1d6a *tests/data/fate/cover-art-aiff-id3v2-remux.aif
#sar 1: 1/1
#tb 2: 1/90000
#media_type 2: video
#codec_id 2: mjpeg
#codec_id 2: png
#dimensions 2: 350x350
#sar 2: 1/1
#tb 3: 1/90000
#media_type 3: video
#codec_id 3: png
#codec_id 3: bmp
#dimensions 3: 350x350
#sar 3: 1/1
#sar 3: 0/1
#tb 4: 1/90000
#media_type 4: video
#codec_id 4: bmp
#codec_id 4: mjpeg
#dimensions 4: 350x350
#sar 4: 0/1
#sar 4: 1/1
0, 0, 0, 1024, 4096, 0xdac4695d
1, 0, 0, 0, 19650, 0xd5662610
2, 0, 0, 0, 19650, 0xd5662610
3, 0, 0, 0, 184497, 0xc33f8d44
4, 0, 0, 0, 368254, 0xfa7f4bd8
2, 0, 0, 0, 184497, 0xc33f8d44
3, 0, 0, 0, 368254, 0xfa7f4bd8
4, 0, 0, 0, 19650, 0xd5662610
0, 1024, 1024, 1024, 4096, 0xad05c909
0, 2048, 2048, 1024, 4096, 0x97e3b8f8
0, 3072, 3072, 1024, 4096, 0xb08180fa
@ -47,25 +47,25 @@ TAG:comment=Other
[/STREAM]
[STREAM]
index=2
codec_name=mjpeg
DISPOSITION:attached_pic=1
TAG:title=fourth
TAG:comment=Composer
[/STREAM]
[STREAM]
index=3
codec_name=png
DISPOSITION:attached_pic=1
TAG:title=second
TAG:comment=Illustration
[/STREAM]
[STREAM]
index=4
index=3
codec_name=bmp
DISPOSITION:attached_pic=1
TAG:title=third
TAG:comment=Conductor
[/STREAM]
[STREAM]
index=4
codec_name=mjpeg
DISPOSITION:attached_pic=1
TAG:title=fourth
TAG:comment=Composer
[/STREAM]
[FORMAT]
TAG:artist=Мельница
TAG:RATING=0

View File

@ -1,4 +1,4 @@
c1b55a9a92226cd72d3f53ccd830d127 *tests/data/fate/cover-art-mp3-id3v2-remux.mp3
94946f0efd5f9bb0061ac1fbff7d731f *tests/data/fate/cover-art-mp3-id3v2-remux.mp3
399346 tests/data/fate/cover-art-mp3-id3v2-remux.mp3
#tb 0: 1/14112000
#media_type 0: audio
@ -7,22 +7,22 @@ c1b55a9a92226cd72d3f53ccd830d127 *tests/data/fate/cover-art-mp3-id3v2-remux.mp3
#channel_layout_name 0: stereo
#tb 1: 1/90000
#media_type 1: video
#codec_id 1: mjpeg
#codec_id 1: bmp
#dimensions 1: 263x263
#sar 1: 96/96
#sar 1: 0/1
#tb 2: 1/90000
#media_type 2: video
#codec_id 2: bmp
#codec_id 2: mjpeg
#dimensions 2: 263x263
#sar 2: 0/1
#sar 2: 96/96
#tb 3: 1/90000
#media_type 3: video
#codec_id 3: png
#dimensions 3: 263x263
#sar 3: 1/1
0, -353590, -353590, 368640, 417, 0x15848290, S=1, 10
1, 0, 0, 0, 15760, 0x71d5c418
2, 0, 0, 0, 208350, 0x291b44d1
1, 0, 0, 0, 208350, 0x291b44d1
2, 0, 0, 0, 15760, 0x71d5c418
3, 0, 0, 0, 165671, 0x7c1c8070
0, 15050, 15050, 368640, 418, 0x46f684a4
0, 383690, 383690, 368640, 418, 0x46f684a4
@ -36,17 +36,17 @@ TAG:encoder=Lavf
[/STREAM]
[STREAM]
index=1
codec_name=mjpeg
DISPOSITION:attached_pic=1
TAG:comment=Other
[/STREAM]
[STREAM]
index=2
codec_name=bmp
DISPOSITION:attached_pic=1
TAG:comment=Band/Orchestra
[/STREAM]
[STREAM]
index=2
codec_name=mjpeg
DISPOSITION:attached_pic=1
TAG:comment=Other
[/STREAM]
[STREAM]
index=3
codec_name=png
DISPOSITION:attached_pic=1