From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6FF3C45E79 for ; Thu, 13 Apr 2023 14:17:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F380168BEAF; Thu, 13 Apr 2023 17:16:07 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB0C968BD88 for ; Thu, 13 Apr 2023 17:16:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A95582404F8 for ; Thu, 13 Apr 2023 16:16:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id o8ickMjBnUmN for ; Thu, 13 Apr 2023 16:16:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 915A5240705 for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 812C63A039B for ; Thu, 13 Apr 2023 16:15:53 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Apr 2023 16:12:14 +0200 Message-Id: <20230413141223.17245-16-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230413141223.17245-1-anton@khirnov.net> References: <20230413141223.17245-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: store stream media type in OutputStream X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Reduces access to a deeply nested muxer property OutputStream.st->codecpar->codec_type for this fundamental and immutable stream property. Besides making the code shorter, this will allow making the AVStream (OutputStream.st) private to the muxer in the future. --- fftools/ffmpeg.c | 4 ++-- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_mux.c | 11 +++++------ fftools/ffmpeg_mux_init.c | 26 ++++++++++++-------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 33b2f72d90..30b42b4fde 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -748,12 +748,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti const AVCodecContext * const enc = ost->enc_ctx; const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1; - if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (vid && ost->type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!vid && ost->type == AVMEDIA_TYPE_VIDEO) { float fps; uint64_t frame_number = atomic_load(&ost->packets_written); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5833c13812..f08f5db49e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -578,6 +578,8 @@ typedef struct Encoder Encoder; typedef struct OutputStream { const AVClass *class; + enum AVMediaType type; + int file_index; /* file index */ int index; /* stream index in the output file */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index b316925115..eb64d8c3ff 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -62,7 +62,6 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) { MuxStream *ms = ms_from_ost(ost); AVFormatContext *s = mux->fc; - AVStream *st = ost->st; int64_t fs; uint64_t frame_num; int ret; @@ -74,10 +73,10 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) goto fail; } - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) + if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) pkt->pts = pkt->dts = AV_NOPTS_VALUE; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (ost->type == AVMEDIA_TYPE_VIDEO) { if (ost->frame_rate.num && ost->is_cfr) { if (pkt->duration > 0) av_log(ost, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n"); @@ -101,12 +100,12 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) - FFMIN3(pkt->pts, pkt->dts, ms->last_mux_dts + 1) - FFMAX3(pkt->pts, pkt->dts, ms->last_mux_dts + 1); } - if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && + if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) && pkt->dts != AV_NOPTS_VALUE && ms->last_mux_dts != AV_NOPTS_VALUE) { int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT); if (pkt->dts < max) { - int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; + int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; if (exit_on_error) loglevel = AV_LOG_ERROR; av_log(s, loglevel, "Non-monotonous DTS in output stream " @@ -136,7 +135,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) if (debug_ts) { av_log(ost, AV_LOG_INFO, "muxer <- type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n", - av_get_media_type_string(st->codecpar->codec_type), + av_get_media_type_string(ost->type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base), diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index bc14cabad4..129973d9f0 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -108,7 +108,7 @@ static int check_opt_bitexact(void *ctx, const AVDictionary *opts, static int choose_encoder(const OptionsContext *o, AVFormatContext *s, OutputStream *ost, const AVCodec **enc) { - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; char *codec_name = NULL; *enc = NULL; @@ -117,7 +117,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st); if (!codec_name) { ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url, - NULL, ost->st->codecpar->codec_type); + NULL, ost->type); *enc = avcodec_find_encoder(ost->st->codecpar->codec_id); if (!*enc) { av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed " @@ -127,7 +127,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, return AVERROR_ENCODER_NOT_FOUND; } } else if (strcmp(codec_name, "copy")) { - *enc = find_codec_or_die(ost, codec_name, ost->st->codecpar->codec_type, 1); + *enc = find_codec_or_die(ost, codec_name, ost->type, 1); ost->st->codecpar->codec_id = (*enc)->id; } } @@ -410,6 +410,7 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) ms->ost.file_index = mux->of.index; ms->ost.index = mux->of.nb_streams - 1; + ms->ost.type = type; ms->ost.class = &output_stream_class; @@ -422,8 +423,6 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, OutputStream *ost) { - AVStream *st = ost->st; - if (ost->filters_script && ost->filters) { av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n"); exit_program(1); @@ -434,8 +433,7 @@ static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc, else if (ost->filters) return av_strdup(ost->filters); - return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? - "null" : "anull"); + return av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull"); } static void check_streamcopy_filters(const OptionsContext *o, AVFormatContext *oc, @@ -1594,7 +1592,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; ost->sq_idx_encode = -1; ost->sq_idx_mux = -1; @@ -1628,7 +1626,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (!IS_AV_ENC(ost, type)) continue; @@ -1657,7 +1655,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u for (int i = 0; i < oc->nb_streams; i++) { OutputStream *ost = of->streams[i]; MuxStream *ms = ms_from_ost(ost); - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (!IS_INTERLEAVED(type)) continue; @@ -2113,7 +2111,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - nb_streams[ost->st->codecpar->codec_type]++; + nb_streams[ost->type]++; MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); @@ -2123,7 +2121,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) ost->st->disposition = ost->ist->st->disposition; if (ost->st->disposition & AV_DISPOSITION_DEFAULT) - have_default[ost->st->codecpar->codec_type] = 1; + have_default[ost->type] = 1; } } @@ -2146,7 +2144,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) // "Suitable" means the first of that type, skipping attached pictures. for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - enum AVMediaType type = ost->st->codecpar->codec_type; + enum AVMediaType type = ost->type; if (nb_streams[type] < 2 || have_default[type] || ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC) @@ -2239,7 +2237,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st); - if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + if (!(ost->type == AVMEDIA_TYPE_VIDEO && ost->enc_ctx && forced_keyframes)) continue; -- 2.39.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".