From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 15/21] fftools/ffmpeg: attach bits_per_raw_sample information to frames Date: Wed, 14 Jun 2023 18:49:02 +0200 Message-ID: <20230614164908.28712-15-anton@khirnov.net> (raw) In-Reply-To: <20230614164908.28712-1-anton@khirnov.net> This way avoids encoders reaching into filters or decoders for this information. --- fftools/ffmpeg.h | 7 ++----- fftools/ffmpeg_dec.c | 21 ++++++++++----------- fftools/ffmpeg_enc.c | 13 ++++++------- fftools/ffmpeg_filter.c | 27 ++++++++++++++++++--------- fftools/ffmpeg_mux_init.c | 14 +++++--------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 80d9ab52bc..abc1a21d73 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -315,9 +315,6 @@ typedef struct FilterGraph { int index; AVFilterGraph *graph; - // true when the filtergraph contains only meta filters - // that do not modify the frame data - int is_meta; InputFilter **inputs; int nb_inputs; @@ -339,8 +336,6 @@ typedef struct InputStream { int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */ #define DECODING_FOR_OST 1 #define DECODING_FOR_FILTER 2 - // should attach FrameData as opaque_ref after decoding - int want_frame_data; /** * Codec parameters - to be used by the decoding/streamcopy code. @@ -653,6 +648,8 @@ typedef struct FrameData { AVRational tb; AVRational frame_rate_filter; + + int bits_per_raw_sample; } FrameData; extern InputFile **input_files; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index f9053c424b..e6c6e22b04 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -472,6 +472,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) while (1) { AVFrame *frame = d->frame; + FrameData *fd; update_benchmark(NULL); ret = avcodec_receive_frame(dec, frame); @@ -508,19 +509,17 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) exit_program(1); } - if (ist->want_frame_data) { - FrameData *fd; - av_assert0(!frame->opaque_ref); - fd = frame_data(frame); - if (!fd) { - av_frame_unref(frame); - report_and_exit(AVERROR(ENOMEM)); - } - fd->pts = frame->pts; - fd->tb = dec->pkt_timebase; - fd->idx = dec->frame_num - 1; + av_assert0(!frame->opaque_ref); + fd = frame_data(frame); + if (!fd) { + av_frame_unref(frame); + report_and_exit(AVERROR(ENOMEM)); } + fd->pts = frame->pts; + fd->tb = dec->pkt_timebase; + fd->idx = dec->frame_num - 1; + fd->bits_per_raw_sample = dec->bits_per_raw_sample; frame->time_base = dec->pkt_timebase; diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 0fdf7e7c4d..f42f4055d6 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -198,6 +198,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) AVCodecContext *dec_ctx = NULL; const AVCodec *enc = enc_ctx->codec; OutputFile *of = output_files[ost->file_index]; + FrameData *fd = frame ? frame_data(frame) : NULL; int ret; if (e->opened) @@ -219,8 +220,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) if (ost->bits_per_raw_sample) enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; - else if (dec_ctx && ost->filter->graph->is_meta) - enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, + else if (fd) + enc_ctx->bits_per_raw_sample = FFMIN(fd->bits_per_raw_sample, av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase : @@ -230,10 +231,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: { AVRational fr = ost->frame_rate; - if (!fr.num && frame) { - FrameData *fd = frame_data(frame); + if (!fr.num && fd) fr = fd->frame_rate_filter; - } if (!fr.num && !ost->max_frame_rate.num) { fr = (AVRational){25, 1}; av_log(ost, AV_LOG_WARNING, @@ -282,8 +281,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) if (ost->bits_per_raw_sample) enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; - else if (dec_ctx && ost->filter->graph->is_meta) - enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, + else if (fd) + enc_ctx->bits_per_raw_sample = FFMIN(fd->bits_per_raw_sample, av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth); if (frame) { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ccde5b26ec..9e6883ccdd 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -45,6 +45,9 @@ typedef struct FilterGraphPriv { char log_name[32]; int is_simple; + // true when the filtergraph contains only meta filters + // that do not modify the frame data + int is_meta; const char *graph_desc; @@ -1566,7 +1569,7 @@ static int configure_filtergraph(FilterGraph *fg) if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0) goto fail; - fg->is_meta = graph_is_meta(fg->graph); + fgp->is_meta = graph_is_meta(fg->graph); /* limit the lists of allowed formats to the ones selected, to * make sure they stay the same if the filtergraph is reconfigured later */ @@ -1714,6 +1717,8 @@ int reap_filters(int flush) filtered_frame = fgp->frame; while (1) { + FrameData *fd; + ret = av_buffersink_get_frame_flags(filter, filtered_frame, AV_BUFFERSINK_FLAG_NO_REQUEST); if (ret < 0) { @@ -1744,16 +1749,20 @@ int reap_filters(int flush) tb.num, tb.den); } - if (ost->type == AVMEDIA_TYPE_VIDEO) { - FrameData *fd = frame_data(filtered_frame); - if (!fd) { - av_frame_unref(filtered_frame); - report_and_exit(AVERROR(ENOMEM)); - } - - fd->frame_rate_filter = av_buffersink_get_frame_rate(filter); + fd = frame_data(filtered_frame); + if (!fd) { + av_frame_unref(filtered_frame); + report_and_exit(AVERROR(ENOMEM)); } + // only use bits_per_raw_sample passed through from the decoder + // if the filtergraph did not touch the frame data + if (!fgp->is_meta) + fd->bits_per_raw_sample = 0; + + if (ost->type == AVMEDIA_TYPE_VIDEO) + fd->frame_rate_filter = av_buffersink_get_frame_rate(filter); + enc_frame(ost, filtered_frame); av_frame_unref(filtered_frame); } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index a18320fa9b..6ab541d7c5 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -365,15 +365,11 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, c->type = fmt_specs[i].type; - if (fmt_specs[i].need_input_data) { - if (ost->ist) - ost->ist->want_frame_data = 1; - else { - av_log(ost, AV_LOG_WARNING, - "Format directive '%s' is unavailable, because " - "this output stream has no associated input stream\n", - val); - } + if (fmt_specs[i].need_input_data && !ost->ist) { + av_log(ost, AV_LOG_WARNING, + "Format directive '%s' is unavailable, because " + "this output stream has no associated input stream\n", + val); } break; -- 2.40.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:[~2023-06-14 16:52 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-14 16:48 [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 02/21] fftools/ffmpeg_dec: simplify process_subtitle() Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 03/21] tests/fate: rename ffmpeg-streamloop to ffmpeg-streamloop-copy Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 04/21] tests/fate: add a test for -streamloop with transcoding video+audio Anton Khirnov 2023-06-14 16:57 ` Andreas Rheinhardt 2023-06-16 6:01 ` [FFmpeg-devel] [PATCH 04/21 v2] " Anton Khirnov 2023-06-19 10:52 ` "zhilizhao(赵志立)" 2023-06-19 12:29 ` James Almer 2023-06-19 12:34 ` "zhilizhao(赵志立)" 2023-06-19 13:22 ` James Almer 2023-06-19 13:39 ` Zhao Zhili 2023-06-19 15:48 ` Lynne 2023-06-19 20:33 ` Martin Storsjö 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 05/21] fftools/ffmpeg_demux: move the loop out of add_input_streams() Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 06/21] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 07/21] fftools/ffmpeg_hw: inline hwaccel_decode_init() into its caller Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 08/21] fftools/ffmpeg_dec: remove pointless InputStream.hwaccel_retrieve_data Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 09/21] fftools/ffmpeg_dec: move InputStream.hwaccel_pix_fmt to Decoder Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 10/21] fftools/ffmpeg_enc: move dup_warning global variable to Encoder Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 11/21] fftools/ffmpeg_filter: add an AVClass to FilterGraph Anton Khirnov 2023-06-14 16:48 ` [FFmpeg-devel] [PATCH 12/21] fftools/ffmpeg_filter: reject filtergraphs with zero outputs Anton Khirnov 2023-06-14 16:53 ` Paul B Mahol 2023-06-14 17:00 ` Anton Khirnov 2023-06-14 17:11 ` Paul B Mahol 2023-06-14 17:14 ` Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 13/21] fftools/ffmpeg_filter: make configure_filtergraph() static Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 14/21] fftools/ffmpeg_dec: stop using Decoder.pkt Anton Khirnov 2023-06-14 16:49 ` Anton Khirnov [this message] 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 16/21] fftools/ffmpeg_dec: move decoding to a separate thread Anton Khirnov 2023-06-16 20:58 ` Michael Niedermayer 2023-06-17 2:55 ` Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 17/21] fftools/ffmpeg: move fix_sub_duration_heartbeat() to ffmpeg_dec Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 18/21] fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 19/21] fftools/ffmpeg_enc: constify the subtitle passed to enc_subtitle() Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 20/21] fftools/ffmpeg: use AVFrame to pass subtitles from decoders to filters Anton Khirnov 2023-06-14 16:49 ` [FFmpeg-devel] [PATCH 21/21] fftools/ffmpeg: pass subtitle decoder dimensions to sub2video Anton Khirnov 2023-06-18 8:35 ` [FFmpeg-devel] [PATCH 01/21] fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret 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=20230614164908.28712-15-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