From patchwork Mon Jun 8 08:58:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 20198 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 65DC844B837 for ; Mon, 8 Jun 2020 12:02:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3CE0E6882D5; Mon, 8 Jun 2020 12:02:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4022A6809B4 for ; Mon, 8 Jun 2020 12:02:51 +0300 (EEST) IronPort-SDR: zESIxQ+89GRv2jVamLjbvjvFlvieUlzRGhSXJx1S5KGhvYCLrcsCtiLi6phcyXKUAQA7yxS4fb 57d5S4O1u+Nw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 02:02:48 -0700 IronPort-SDR: vVXm4SBGbrHUACgpUbVwXHOeI5NSdfkpv6jGKAYEqhvTNVcBhTbIY9JjqTB3OIJHILjb9T0IyN le1lt1WJwzwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="472625244" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by fmsmga005.fm.intel.com with ESMTP; 08 Jun 2020 02:02:47 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Jun 2020 16:58:03 +0800 Message-Id: <1591606685-4450-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/avcodec: Add caps for the support of variable dimension encoding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" And declare AV_CODEC_CAP_VARIABLE_DIMENSIONS for rawvideo and wrapped_avframe. Signed-off-by: Linjie Fu --- doc/APIchanges | 3 +++ fftools/cmdutils.c | 2 ++ libavcodec/avcodec.h | 4 +++- libavcodec/codec.h | 5 +++++ libavcodec/rawenc.c | 1 + libavcodec/version.h | 2 +- libavcodec/wrapped_avframe.c | 1 + 7 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index c7e4ce3..f4d350c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2020-06-xx - xxxxxxxxxx - lavc 58.90.101 - codec.h + Add AV_CODEC_CAP_VARIABLE_DIMENSIONS. + 2020-06-xx - xxxxxxxxxx - lavu 56.50.100 - buffer.h Passing NULL as alloc argument to av_buffer_pool_init2() is now allowed. diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 13567a7..e0469cd 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1424,6 +1424,8 @@ static void print_codec(const AVCodec *c) printf("hardware "); if (c->capabilities & AV_CODEC_CAP_HYBRID) printf("hybrid "); + if (c->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS) + printf("multidimension "); if (!c->capabilities) printf("none"); printf("\n"); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c91b2fd..b435ce6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -97,7 +97,9 @@ * - For decoding, call avcodec_send_packet() to give the decoder raw * compressed data in an AVPacket. * - For encoding, call avcodec_send_frame() to give the encoder an AVFrame - * containing uncompressed audio or video. + * containing uncompressed audio or video. Video encoder requires input + * frames to be in constant dimensions unless it declare the capability + * of AV_CODEC_CAP_VARIABLE_DIMENSIONS. * * In both cases, it is recommended that AVPackets and AVFrames are * refcounted, or libavcodec might have to copy the input data. (libavformat diff --git a/libavcodec/codec.h b/libavcodec/codec.h index 1fda619..9855477 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -169,6 +169,11 @@ * remain pending. */ #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21) +/** + * Codec supports variable dimensions encoding. This indicates that input frames are + * allowed to be in variable dimensions/resolutions, otherwise they have to keep constant. + */ +#define AV_CODEC_CAP_VARIABLE_DIMENSIONS (1 << 22) /** * AVProfile. diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c index d181b74..486c0d7 100644 --- a/libavcodec/rawenc.c +++ b/libavcodec/rawenc.c @@ -92,4 +92,5 @@ AVCodec ff_rawvideo_encoder = { .id = AV_CODEC_ID_RAWVIDEO, .init = raw_encode_init, .encode2 = raw_encode, + .capabilities = AV_CODEC_CAP_VARIABLE_DIMENSIONS, }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 524fbc3..4e2cc5d 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 90 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c index 85ff32d..ae29328 100644 --- a/libavcodec/wrapped_avframe.c +++ b/libavcodec/wrapped_avframe.c @@ -116,6 +116,7 @@ AVCodec ff_wrapped_avframe_encoder = { .id = AV_CODEC_ID_WRAPPED_AVFRAME, .encode2 = wrapped_avframe_encode, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, + .capabilities = AV_CODEC_CAP_VARIABLE_DIMENSIONS, }; AVCodec ff_wrapped_avframe_decoder = { From patchwork Mon Jun 8 08:58:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 20199 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 53577441387 for ; Mon, 8 Jun 2020 12:03:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 363CB68B199; Mon, 8 Jun 2020 12:03:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EACC68B05E for ; Mon, 8 Jun 2020 12:03:02 +0300 (EEST) IronPort-SDR: phB1YCgnJHPcINrYo2Zs66S4RcKxpNNPS8j9pgAqW9mMqQFJH+mspHqeTzyN6CRRBQgdKQAhyd LBrEthKOqq7w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 02:02:59 -0700 IronPort-SDR: 4XNI+ypXRfmE2TVc3ztb6zbjlp/GmUsNBK7qGYb/AfXzMDoeYmov8UbjfLhoKBcl10uj2I0Xcs +hUp4syQEQgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="472625290" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by fmsmga005.fm.intel.com with ESMTP; 08 Jun 2020 02:02:58 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Jun 2020 16:58:04 +0800 Message-Id: <1591606685-4450-2-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591606685-4450-1-git-send-email-linjie.fu@intel.com> References: <1591606685-4450-1-git-send-email-linjie.fu@intel.com> Subject: [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg: check caps of encoders for encoding with variable dimension X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This ensures that an encoder is able to cope with input frames with resolution changing only if it declares the capability of AV_CODEC_CAP_VARIABLE_DIMENSIONS. Signed-off-by: Linjie Fu --- fftools/ffmpeg.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448e..5859781 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1056,6 +1056,15 @@ static void do_video_out(OutputFile *of, InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; + if (next_picture && (enc->width != next_picture->width || + enc->height != next_picture->height)) { + if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) { + av_log(NULL, AV_LOG_ERROR, "Variable dimension encoding " + "is not supported by %s.\n", enc->codec->name); + goto error; + } + } + if (ost->source_index >= 0) ist = input_streams[ost->source_index]; From patchwork Mon Jun 8 08:58:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 20200 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0F53C44A640 for ; Mon, 8 Jun 2020 12:03:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F08E368B1AE; Mon, 8 Jun 2020 12:03:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C3DA68B05E for ; Mon, 8 Jun 2020 12:03:09 +0300 (EEST) IronPort-SDR: 61gcNSYqKdYPBkGt4joHr6TCsckI2z+uvDRqu+OM9stwZEhvSaUSfb82n0wCGD7gAof9vvVCML qawUND61kFvg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 02:03:06 -0700 IronPort-SDR: Sd8pthmrqnHq1Uq27lCZg6nME2b/zaJIRcfuES8ySO/Vc/J5vBGbfcqWiH6Eo4pfUhYzfA8DSV Hrg36QxOqGew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="472625331" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by fmsmga005.fm.intel.com with ESMTP; 08 Jun 2020 02:03:04 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Jun 2020 16:58:05 +0800 Message-Id: <1591606685-4450-3-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591606685-4450-1-git-send-email-linjie.fu@intel.com> References: <1591606685-4450-1-git-send-email-linjie.fu@intel.com> Subject: [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Linjie Fu , "U . Artie Eoff" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Currently, ffmpeg inserts scale filter by default in the filter graph to force the whole decoded stream to scale into the same size with the first frame. It's not quite make sense in resolution changing cases if user wants the rawvideo without any scale. Using autoscale/noautoscale as an output option to indicate whether auto inserting the scale filter in the filter graph: -noautoscale or -autoscale 0: disable the default auto scale filter inserting. ffmpeg -y -i input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv Update docs. Suggested-by: Mark Thompson Reviewed-by: Nicolas George Signed-off-by: U. Artie Eoff Signed-off-by: Linjie Fu --- doc/ffmpeg.texi | 16 ++++++++++++---- fftools/ffmpeg.h | 3 +++ fftools/ffmpeg_filter.c | 2 +- fftools/ffmpeg_opt.c | 6 ++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 76fafdc..34221b4 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -734,10 +734,6 @@ ffmpeg -dump_attachment:t "" -i INPUT Technical note -- attachments are implemented as codec extradata, so this option can actually be used to extract extradata from any stream, not just attachments. - -@item -noautorotate -Disable automatically rotating video based on file metadata. - @end table @section Video Options @@ -819,6 +815,18 @@ Create the filtergraph specified by @var{filtergraph} and use it to filter the stream. This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter option}. + +@item -autorotate +Automatically rotate the video according to file metadata. Enabled by +default, use @option{-noautorotate} to disable it. + +@item -autoscale +Automatically scale the video according to the resolution of first frame. +Enabled by default, use @option{-noautoscale} to disable it. When autoscale is +disabled, all output frames of filter graph might not be in the same resolution +and may be inadequate for some encoder/muxer. Therefore, it is not recommended +to disable it unless you really know what you are doing. +Disable autoscale at your own risk. @end table @section Advanced Video options diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 828cb2a..6e3f254 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -229,6 +229,8 @@ typedef struct OptionsContext { int nb_time_bases; SpecifierOpt *enc_time_bases; int nb_enc_time_bases; + SpecifierOpt *autoscale; + int nb_autoscale; } OptionsContext; typedef struct InputFilter { @@ -479,6 +481,7 @@ typedef struct OutputStream { int force_fps; int top_field_first; int rotate_overridden; + int autoscale; double rotate_override_value; AVRational frame_aspect_ratio; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 422e126..4784e8a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -470,7 +470,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, if (ret < 0) return ret; - if (ofilter->width || ofilter->height) { + if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) { char args[255]; AVFilterContext *filter; AVDictionaryEntry *e = NULL; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 2eb4e1c..9d1489c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -62,6 +62,7 @@ static const char *opt_name_hwaccels[] = {"hwaccel", NULL}; static const char *opt_name_hwaccel_devices[] = {"hwaccel_device", NULL}; static const char *opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL}; static const char *opt_name_autorotate[] = {"autorotate", NULL}; +static const char *opt_name_autoscale[] = {"autoscale", NULL}; static const char *opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL}; static const char *opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL}; static const char *opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL}; @@ -1462,6 +1463,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc); MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); + ost->autoscale = 1; + MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st); if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { do { buf = get_line(s); @@ -3664,6 +3667,9 @@ const OptionDef options[] = { { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) }, "automatically insert correct rotate filters" }, + { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC | + OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) }, + "automatically insert a scale filter at the end of the filter graph" }, /* audio options */ { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },