diff mbox series

[FFmpeg-devel,2/9] avformat/avisynth: add read_frameprop_sar option

Message ID 20220829000244.71123-3-qyot27@gmail.com
State New
Headers show
Series avisynth: add user options | expand

Commit Message

Stephen Hutchinson Aug. 29, 2022, 12:02 a.m. UTC
Because SAR is much more likely to be negatively affected by
operations made in-script, given that resizing is probably far more
common than the sort of color manipulation involved in most of the
other frame properties, the safest option is to disable reading
it by default, allowing users to opt in.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
---
 libavformat/avisynth.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index d978e6ec40..d503c7ed40 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -21,6 +21,7 @@ 
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/opt.h"
 
 #include "libavcodec/internal.h"
 
@@ -86,6 +87,7 @@  typedef struct AviSynthLibrary {
 } AviSynthLibrary;
 
 typedef struct AviSynthContext {
+    const AVClass *class;
     AVS_ScriptEnvironment *env;
     AVS_Clip *clip;
     const AVS_VideoInfo *vi;
@@ -100,6 +102,9 @@  typedef struct AviSynthContext {
 
     int error;
 
+    /* (de)activate reading frame properties */
+    int frameprop_sar;
+
     /* Linked list pointers. */
     struct AviSynthContext *next;
 } AviSynthContext;
@@ -732,9 +737,11 @@  static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
         }
 
         /* Sample aspect ratio */
-        sar_num = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARNum", 0, &error);
-        sar_den = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARDen", 0, &error);
-        st->sample_aspect_ratio = (AVRational){ sar_num, sar_den };
+        if (avs->frameprop_sar) {
+            sar_num = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARNum", 0, &error);
+            sar_den = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARDen", 0, &error);
+            st->sample_aspect_ratio = (AVRational){ sar_num, sar_den };
+        }
 
         avs_library.avs_release_video_frame(frame);
     } else {
@@ -1140,6 +1147,19 @@  static int avisynth_read_seek(AVFormatContext *s, int stream_index,
     return 0;
 }
 
+#define OFFSET(x) offsetof(AviSynthContext, x)
+static const AVOption avisynth_options[] = {
+    { "read_frameprop_sar", "Read SAR from script's frame properties (AviSynth+ v3.7.1+).", OFFSET(frameprop_sar), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
+    { NULL },
+};
+
+static const AVClass avisynth_demuxer_class = {
+    .class_name = "AviSynth demuxer",
+    .item_name  = av_default_item_name,
+    .option     = avisynth_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 const AVInputFormat ff_avisynth_demuxer = {
     .name           = "avisynth",
     .long_name      = NULL_IF_CONFIG_SMALL("AviSynth script"),
@@ -1149,4 +1169,5 @@  const AVInputFormat ff_avisynth_demuxer = {
     .read_close     = avisynth_read_close,
     .read_seek      = avisynth_read_seek,
     .extensions     = "avs",
+    .priv_class     = &avisynth_demuxer_class,
 };