From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: stop accessing the decoder context unnecessarily Date: Wed, 3 Aug 2022 15:58:24 +0200 Message-ID: <20220803135844.16662-5-anton@khirnov.net> (raw) In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> The same information is available from AVStream.codecpar. This will allow to stop allocating a decoder unless decoding is actually performed. --- fftools/ffmpeg.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4746742c02..62ff1a98df 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1495,7 +1495,7 @@ static void print_final_stats(int64_t total_size) for (j = 0; j < f->nb_streams; j++) { InputStream *ist = input_streams[f->ist_index + j]; - enum AVMediaType type = ist->dec_ctx->codec_type; + enum AVMediaType type = ist->st->codecpar->codec_type; total_size += ist->data_size; total_packets += ist->nb_packets; @@ -1915,11 +1915,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p if (pkt->dts == AV_NOPTS_VALUE) { opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase); } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size); + int duration = av_get_audio_frame_duration2(ist->st->codecpar, pkt->size); if(!duration) - duration = ist->dec_ctx->frame_size; + duration = ist->st->codecpar->frame_size; opkt->dts = av_rescale_delta(ist->st->time_base, pkt->dts, - (AVRational){1, ist->dec_ctx->sample_rate}, duration, + (AVRational){1, ist->st->codecpar->sample_rate}, duration, &ist->filter_in_rescale_delta_last, ost->mux_timebase); /* dts will be set immediately afterwards to what pts is now */ opkt->pts = opkt->dts - ost_tb_start_time; @@ -2394,6 +2394,7 @@ static int send_filter_eof(InputStream *ist) /* pkt = NULL means EOF (needed to flush decoder buffers) */ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { + const AVCodecParameters *par = ist->st->codecpar; int ret = 0, i; int repeating = 0; int eof_reached = 0; @@ -2426,7 +2427,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (pkt && pkt->dts != AV_NOPTS_VALUE) { ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); - if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed) + if (par->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed) ist->next_pts = ist->pts = ist->dts; } @@ -2440,7 +2441,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo ist->pts = ist->next_pts; ist->dts = ist->next_dts; - switch (ist->dec_ctx->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, &decode_failed); @@ -2537,12 +2538,12 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo /* handle stream copy */ if (!ist->decoding_needed && pkt) { ist->dts = ist->next_dts; - switch (ist->dec_ctx->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: av_assert1(pkt->duration >= 0); - if (ist->dec_ctx->sample_rate) { - ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) / - ist->dec_ctx->sample_rate; + if (par->sample_rate) { + ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) / + par->sample_rate; } else { ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); } @@ -4000,7 +4001,8 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + ifile->ist_index + pkt->stream_index, + av_get_media_type_string(ist->st->codecpar->codec_type), av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), @@ -4076,8 +4078,8 @@ static int process_input(int file_index) pkt->dts *= ist->ts_scale; pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); - if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || - ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && + if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) && pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) { int64_t delta = pkt_dts - ifile->last_ts; @@ -4114,8 +4116,8 @@ static int process_input(int file_index) disable_discontinuity_correction = 0; } - if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || - ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && + if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) && pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) { int64_t delta = pkt_dts - ist->next_dts; @@ -4128,7 +4130,7 @@ static int process_input(int file_index) "timestamp discontinuity for stream #%d:%d " "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n", ist->file_index, ist->st->index, ist->st->id, - av_get_media_type_string(ist->dec_ctx->codec_type), + av_get_media_type_string(ist->st->codecpar->codec_type), delta, ifile->ts_offset); pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if (pkt->pts != AV_NOPTS_VALUE) @@ -4157,7 +4159,8 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + ifile->ist_index + pkt->stream_index, + av_get_media_type_string(ist->st->codecpar->codec_type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base), -- 2.34.1 _______________________________________________ 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:[~2022-08-03 13:59 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs " Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg_opt: move adding metadata " Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_hw: stop logging to the decoder context Anton Khirnov 2022-08-03 13:58 ` Anton Khirnov [this message] 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg_opt: drop redundant decoder selection Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy Anton Khirnov 2022-08-04 12:40 ` Michael Niedermayer 2022-08-04 12:54 ` Andreas Rheinhardt 2022-08-04 14:37 ` Anton Khirnov 2022-08-04 14:51 ` Andreas Rheinhardt 2022-08-06 4:26 ` [FFmpeg-devel] [PATCH] " Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg: remove OutputStream.encoding_needed Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: remove OutputStream.sync_ist Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: deprecate specifying a sync stream with -map Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 11/25] doc/ffmpeg: update -map documentation Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg: drop a superfluous stack variable Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg: store the input file index in InputFile Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: always read input in a thread Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: drop a write-only variable Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: move the input thread into its own file Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: drop the 'h' key handling Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: handle dumping input packets in input_thread() Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread Anton Khirnov 2022-08-03 18:47 ` Andreas Rheinhardt 2022-08-04 8:20 ` Anton Khirnov 2022-08-04 8:23 ` Nicolas George 2022-08-04 8:25 ` Andreas Rheinhardt 2022-08-04 8:29 ` Nicolas George 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move seek_to_start() " Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg: move -stream_loop handling to the demuxer thread Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_demux: factorize signalling end of demuxing Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_demux: do not store demux packet in the context Anton Khirnov 2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg: move handling corrupt packets to the input thread Anton Khirnov
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=20220803135844.16662-5-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