Browse code

Add sample_aspect_ratio to AVFilterLink

Signed-off-by: Mans Rullgard <mans@mansr.com>

Michael Niedermayer authored on 2011/02/03 04:39:56
Showing 4 changed files
... ...
@@ -194,6 +194,10 @@ int avfilter_config_links(AVFilterContext *filter)
194 194
                 link->time_base = link->src && link->src->input_count ?
195 195
                     link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
196 196
 
197
+            if (link->sample_aspect_ratio.num == 0 && link->sample_aspect_ratio.den == 0)
198
+                link->sample_aspect_ratio = link->src->input_count ?
199
+                    link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
200
+
197 201
             if ((config_link = link->dstpad->config_props))
198 202
                 if ((ret = config_link(link)) < 0)
199 203
                     return ret;
... ...
@@ -27,7 +27,7 @@
27 27
 #include "libavcore/samplefmt.h"
28 28
 
29 29
 #define LIBAVFILTER_VERSION_MAJOR  1
30
-#define LIBAVFILTER_VERSION_MINOR 75
30
+#define LIBAVFILTER_VERSION_MINOR 76
31 31
 #define LIBAVFILTER_VERSION_MICRO  0
32 32
 
33 33
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
... ...
@@ -580,9 +580,10 @@ struct AVFilterLink {
580 580
 
581 581
     enum AVMediaType type;      ///< filter media type
582 582
 
583
-    /* These two parameters apply only to video */
583
+    /* These parameters apply only to video */
584 584
     int w;                      ///< agreed upon image width
585 585
     int h;                      ///< agreed upon image height
586
+    AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
586 587
     /* These two parameters apply only to audio */
587 588
     int64_t channel_layout;     ///< channel layout of current buffer (see libavcore/audioconvert.h)
588 589
     int64_t sample_rate;        ///< samples per second
... ...
@@ -82,6 +82,9 @@ static int setdar_config_props(AVFilterLink *inlink)
82 82
 
83 83
     av_log(inlink->dst, AV_LOG_INFO, "w:%d h:%d -> dar:%d/%d par:%d/%d\n",
84 84
            inlink->w, inlink->h, dar.num, dar.den, aspect->aspect.num, aspect->aspect.den);
85
+
86
+    inlink->sample_aspect_ratio = aspect->aspect;
87
+
85 88
     return 0;
86 89
 }
87 90
 
... ...
@@ -108,6 +111,16 @@ AVFilter avfilter_vf_setdar = {
108 108
 #endif /* CONFIG_SETDAR_FILTER */
109 109
 
110 110
 #if CONFIG_SETSAR_FILTER
111
+/* for setdar filter, convert from frame aspect ratio to pixel aspect ratio */
112
+static int setsar_config_props(AVFilterLink *inlink)
113
+{
114
+    AspectContext *aspect = inlink->dst->priv;
115
+
116
+    inlink->sample_aspect_ratio = aspect->aspect;
117
+
118
+    return 0;
119
+}
120
+
111 121
 AVFilter avfilter_vf_setsar = {
112 122
     .name      = "setsar",
113 123
     .description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
... ...
@@ -118,6 +131,7 @@ AVFilter avfilter_vf_setsar = {
118 118
 
119 119
     .inputs    = (AVFilterPad[]) {{ .name             = "default",
120 120
                                     .type             = AVMEDIA_TYPE_VIDEO,
121
+                                    .config_props     = setsar_config_props,
121 122
                                     .get_video_buffer = avfilter_null_get_video_buffer,
122 123
                                     .start_frame      = start_frame,
123 124
                                     .end_frame        = avfilter_null_end_frame },
... ...
@@ -102,6 +102,11 @@ static int config_props_output(AVFilterLink *outlink)
102 102
     outlink->w = inlink->h;
103 103
     outlink->h = inlink->w;
104 104
 
105
+    if (inlink->sample_aspect_ratio.num){
106
+        outlink->sample_aspect_ratio = av_div_q((AVRational){1,1}, inlink->sample_aspect_ratio);
107
+    } else
108
+        outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
109
+
105 110
     av_log(ctx, AV_LOG_INFO, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n",
106 111
            inlink->w, inlink->h, trans->dir, outlink->w, outlink->h,
107 112
            trans->dir == 1 || trans->dir == 3 ? "clockwise" : "counterclockwise",