From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 10/27] fftools/ffmpeg: stop allocating an encoder context when not encoding Date: Sat, 23 Jul 2022 16:09:35 +0200 Message-ID: <20220723140952.31814-10-anton@khirnov.net> (raw) In-Reply-To: <20220723140952.31814-1-anton@khirnov.net> --- fftools/ffmpeg.c | 12 +++++++++--- fftools/ffmpeg_opt.c | 36 ++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0e30f8ce01..30618c6a6a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1462,7 +1462,8 @@ static void print_final_stats(int64_t total_size) } extra_size += par->extradata_size; data_size += ost->data_size; - if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) + if (ost->enc_ctx && + (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; } @@ -1630,7 +1631,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf, "%X", av_log2(qp_histogram[j] + 1)); } - if ((enc->flags & AV_CODEC_FLAG_PSNR) && (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) { + if (enc && (enc->flags & AV_CODEC_FLAG_PSNR) && + (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) { int j; double error, error_sum = 0; double scale, scale_sum = 0; @@ -3139,6 +3141,9 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) break; } + if (ost->bitexact) + enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; + if (ost->sq_idx_encode >= 0) sq_set_tb(of->sq_encode, ost->sq_idx_encode, enc_ctx->time_base); @@ -3635,7 +3640,8 @@ static int check_keyboard_interaction(int64_t cur_time) } for(i=0;i<nb_output_streams;i++) { OutputStream *ost = output_streams[i]; - ost->enc_ctx->debug = debug; + if (ost->enc_ctx) + ost->enc_ctx->debug = debug; } if(debug) av_log_set_level(AV_LOG_DEBUG); fprintf(stderr,"debug=%d\n", debug); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 716b53d81f..f6e354355b 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1568,12 +1568,14 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e exit_program(1); } - ost->enc_ctx = avcodec_alloc_context3(ost->enc); - if (!ost->enc_ctx) { - av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); - exit_program(1); + if (ost->enc) { + ost->enc_ctx = avcodec_alloc_context3(ost->enc); + if (!ost->enc_ctx) { + av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); + exit_program(1); + } + ost->enc_ctx->codec_type = type; } - ost->enc_ctx->codec_type = type; ost->filtered_frame = av_frame_alloc(); if (!ost->filtered_frame) @@ -1622,9 +1624,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e if (o->bitexact) { - ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; ost->bitexact = 1; - } else { + } else if (ost->enc_ctx) { ost->bitexact = check_opt_bitexact(ost->enc_ctx, ost->encoder_opts, "flags", AV_CODEC_FLAG_BITEXACT); } @@ -1678,12 +1679,13 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e uint32_t tag = strtol(codec_tag, &next, 0); if (*next) tag = AV_RL32(codec_tag); - ost->st->codecpar->codec_tag = - ost->enc_ctx->codec_tag = tag; + ost->st->codecpar->codec_tag = tag; + if (ost->enc_ctx) + ost->enc_ctx->codec_tag = tag; } MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); - if (qscale >= 0) { + if (ost->enc_ctx && qscale >= 0) { ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE; ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } @@ -1700,7 +1702,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample, oc, st); - if (oc->oformat->flags & AVFMT_GLOBALHEADER) + if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0); @@ -1802,12 +1804,10 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in { AVStream *st; OutputStream *ost; - AVCodecContext *video_enc; char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL; ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); st = ost->st; - video_enc = ost->enc_ctx; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { @@ -1845,6 +1845,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); if (!ost->stream_copy) { + AVCodecContext *video_enc = ost->enc_ctx; const char *p = NULL; char *frame_size = NULL; char *frame_pix_fmt = NULL; @@ -2045,18 +2046,16 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in int n; AVStream *st; OutputStream *ost; - AVCodecContext *audio_enc; ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index); st = ost->st; - audio_enc = ost->enc_ctx; - audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); if (!ost->stream_copy) { + AVCodecContext *audio_enc = ost->enc_ctx; int channels = 0; char *layout = NULL; char *sample_fmt = NULL; @@ -2178,15 +2177,12 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, { AVStream *st; OutputStream *ost; - AVCodecContext *subtitle_enc; ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index); st = ost->st; - subtitle_enc = ost->enc_ctx; - - subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; if (!ost->stream_copy) { + AVCodecContext *subtitle_enc = ost->enc_ctx; char *frame_size = NULL; MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st); -- 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-07-23 14:13 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-23 14:09 [FFmpeg-devel] [PATCH 01/27] fftools/ffmpeg: replace AVFrame.pkt_duration with duration Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 02/27] fftools/ffmpeg: stop accessing the encoder context unnecessarily Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 03/27] fftools/ffmpeg: remove an unnecessary avcodec_close() call Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 04/27] fftools/ffmpeg_filter: remove unused function argument Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 05/27] fftools/ffmpeg_filter: do not pass the entire AVCodecContext to choose_pixel_fmt() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 06/27] fftools/ffmpeg: drop the -vol option Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 07/27] fftools/ffmpeg: drop OutputStream.ref_par Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 08/27] fftools/ffmpeg: do not use the encoder context for streamcopy Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 09/27] fftools/ffmpeg: deprecate -psnr Anton Khirnov 2022-07-23 14:09 ` Anton Khirnov [this message] 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 11/27] fftools/ffmpeg_opt: drop a redundant assignment Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 12/27] fftools/ffmpeg: drop unused hwaccel variables Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 13/27] fftools/ffmpeg: move guess_input_channel_layout() to ffmpeg_opt.c Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 14/27] fftools/ffmpeg: deprecate the -map_channel option Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 15/27] fftools/ffmpeg_filter: drop a block commented out since 2012 Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 16/27] fftools/ffmpeg_mux: move some functions closer to their only callers Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 17/27] fftools/ffmpeg: do not log to the decoder context Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 18/27] fftools/ffmpeg_opt: factor auto-mapping video out of open_output_file() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 19/27] fftools/ffmpeg_opt: reduce indentation in map_auto_video() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 20/27] fftools/ffmpeg_opt: factor auto-mapping audio out of open_output_file() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 21/27] fftools/ffmpeg_opt: reduce indentation in map_auto_audio() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 22/27] fftools/ffmpeg_opt: factor auto-mapping subtitles out of open_output_file() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 23/27] fftools/ffmpeg_opt: reduce indentation in map_auto_subtitle() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 24/27] fftools/ffmpeg_opt: factor auto-mapping data streams out of open_output_file() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 25/27] fftools/ffmpeg_opt: reindent Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 26/27] fftools/ffmpeg_opt: factor manually mapping streams out of open_output_file() Anton Khirnov 2022-07-23 14:09 ` [FFmpeg-devel] [PATCH 27/27] fftools/ffmpeg_opt: reindent Anton Khirnov 2022-07-23 15:21 ` [FFmpeg-devel] [PATCH 01/27] fftools/ffmpeg: replace AVFrame.pkt_duration with duration Andreas Rheinhardt
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=20220723140952.31814-10-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