From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 21/21] fftools/ffmpeg: always use the same path for setting InputStream.[next_]dts Date: Thu, 27 Apr 2023 16:26:01 +0200 Message-ID: <20230427142601.2613-21-anton@khirnov.net> (raw) In-Reply-To: <20230427142601.2613-1-anton@khirnov.net> 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. --- fftools/ffmpeg.c | 34 ++++------------------- tests/ref/fate/cover-art-aiff-id3v2-remux | 34 +++++++++++------------ tests/ref/fate/cover-art-mp3-id3v2-remux | 22 +++++++-------- 3 files changed, 33 insertions(+), 57 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 07bd40749d..c72fc6608e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -974,11 +974,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; @@ -1393,7 +1388,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); } @@ -1416,13 +1411,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, @@ -1432,23 +1424,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; @@ -1512,8 +1487,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: @@ -1543,7 +1517,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; diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux index 3ca2855eb8..a59ba37c65 100644 --- a/tests/ref/fate/cover-art-aiff-id3v2-remux +++ b/tests/ref/fate/cover-art-aiff-id3v2-remux @@ -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 diff --git a/tests/ref/fate/cover-art-mp3-id3v2-remux b/tests/ref/fate/cover-art-mp3-id3v2-remux index 906a646799..52b7e72a56 100644 --- a/tests/ref/fate/cover-art-mp3-id3v2-remux +++ b/tests/ref/fate/cover-art-mp3-id3v2-remux @@ -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,15 +36,15 @@ TAG:encoder=Lavf [/STREAM] [STREAM] index=1 -codec_name=mjpeg +codec_name=bmp DISPOSITION:attached_pic=1 -TAG:comment=Other +TAG:comment=Band/Orchestra [/STREAM] [STREAM] index=2 -codec_name=bmp +codec_name=mjpeg DISPOSITION:attached_pic=1 -TAG:comment=Band/Orchestra +TAG:comment=Other [/STREAM] [STREAM] index=3 -- 2.39.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-04-27 14:28 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-04-27 14:25 [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg: deprecate -adrift_threshold Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 02/21] fftools/ffmpeg: reduce access to OutputStream.enc_ctx Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 03/21] fftools/ffmpeg: drop OutputStream.pict_type Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 04/21] fftools/ffmpeg: drop OutputStream.error Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 05/21] fftools/ffmpeg: move OutputStream.packets_encoded to Encoder Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 06/21] fftools/ffmpeg: drop undocumented runtime debug-setting Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 07/21] fftools/ffmpeg_filter: make ifilter_parameters_from_frame() static Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 08/21] fftools/ffmpeg_filter: add filtergraph private data Anton Khirnov 2023-04-28 8:45 ` Nicolas George 2023-04-28 12:01 ` James Almer 2023-04-28 13:52 ` Nicolas George 2023-04-29 8:46 ` Nicolas George 2023-04-29 9:07 ` Anton Khirnov 2023-04-29 9:13 ` Nicolas George 2023-04-29 12:08 ` James Almer 2023-04-29 16:55 ` Nicolas George 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 09/21] fftools/ffmpeg_filter: make graph_desc private Anton Khirnov 2023-04-28 8:46 ` Nicolas George 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 10/21] fftools/ffmpeg_filter: factorize allocating InputFilter Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 11/21] fftools/ffmpeg_filter: add InputFilter private data Anton Khirnov 2023-04-28 8:47 ` Nicolas George 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 12/21] fftools/ffmpeg_filter: keep track of filtergraph input timebase Anton Khirnov 2023-04-28 8:48 ` Nicolas George 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 13/21] fftools/ffmpeg_filter: use correct timebase for filter EOF timestamp Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 14/21] fftools/ffmpeg: stop using packet pts for decoded audio frame pts Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 15/21] fftools/ffmpeg: set AVFrame.time_base for decoded frames Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 16/21] fftools/ffmpeg: rework audio-decode timestamp handling Anton Khirnov 2023-04-28 11:42 ` Michael Niedermayer 2023-04-28 13:11 ` Anton Khirnov 2023-04-28 19:24 ` Michael Niedermayer 2023-04-29 7:32 ` [FFmpeg-devel] [PATCH] " Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 17/21] fftools/ffmpeg: stop using InputStream.pts for generating video timestamps Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 18/21] fftools/ffmpeg_filter: stop using InputStream.pts for filter EOF ts Anton Khirnov 2023-04-27 14:25 ` [FFmpeg-devel] [PATCH 19/21] fftools/ffmpeg: drop InputStream.[next_]pts Anton Khirnov 2023-04-27 14:26 ` [FFmpeg-devel] [PATCH 20/21] fftools/ffmpeg: constify packets passed to decode*() Anton Khirnov 2023-04-27 14:26 ` Anton Khirnov [this message] 2023-05-01 13:45 ` [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg: deprecate -adrift_threshold Anton Khirnov 2023-05-01 13:46 ` Paul B Mahol
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230427142601.2613-21-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git