Skip to content

Commit 62c64d9

Browse files
committed
Use avfilter.scale as the fallback in color_transform
avfilter.colorspace was not working with mlt_image_format=rgba(64)
1 parent 72400cc commit 62c64d9

File tree

3 files changed

+11
-97
lines changed

3 files changed

+11
-97
lines changed

src/modules/avformat/blacklist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ repeatfields
6666
replaygain
6767
resample
6868
reverse
69-
scale
7069
scale2ref
7170
sendcmd
7271
separatefields

src/modules/core/filter_color_transform.c

Lines changed: 7 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <framework/mlt_log.h>
2525
#include <framework/mlt_profile.h>
2626

27-
#include <stdio.h>
28-
#include <stdlib.h>
2927
#include <string.h>
3028

3129
static const char *av_trc_str(mlt_color_trc trc)
@@ -72,82 +70,8 @@ static const char *av_trc_str(mlt_color_trc trc)
7270
return "unknown";
7371
}
7472

75-
static const char *av_colorspace_str(mlt_colorspace colorspace, int height)
76-
{
77-
switch (colorspace) {
78-
case mlt_colorspace_rgb:
79-
return "gbr";
80-
case mlt_colorspace_bt709:
81-
return "bt709";
82-
case mlt_colorspace_fcc:
83-
return "fcc";
84-
case mlt_colorspace_bt470bg:
85-
return "bt470bg";
86-
case mlt_colorspace_smpte170m:
87-
return "smpte170m";
88-
case mlt_colorspace_smpte240m:
89-
return "smpte240m";
90-
case mlt_colorspace_ycgco:
91-
return "ycgco";
92-
case mlt_colorspace_bt2020_ncl:
93-
return "bt2020nc";
94-
case mlt_colorspace_bt2020_cl:
95-
return "bt2020c";
96-
case mlt_colorspace_smpte2085:
97-
return "smpte2085";
98-
case mlt_colorspace_bt601:
99-
return height < 576 ? "smpte170m" : "bt470bg";
100-
case mlt_colorspace_invalid:
101-
case mlt_colorspace_unspecified:
102-
case mlt_colorspace_reserved:
103-
break;
104-
}
105-
// Guess a reasonable default
106-
if (height < 576) {
107-
return "smpte170m";
108-
} else if (height < 720) {
109-
return "bt470bg";
110-
}
111-
return "bt709";
112-
}
113-
114-
static const char *av_color_primaries_str(mlt_color_primaries primaries, int height)
115-
{
116-
switch (primaries) {
117-
case mlt_color_pri_bt709:
118-
return "bt709";
119-
case mlt_color_pri_bt470m:
120-
return "bt470m";
121-
case mlt_color_pri_bt470bg:
122-
return "bt470bg";
123-
case mlt_color_pri_smpte170m:
124-
return "smpte170m";
125-
case mlt_color_pri_film:
126-
return "film";
127-
case mlt_color_pri_bt2020:
128-
return "bt2020";
129-
case mlt_color_pri_smpte428:
130-
return "smpte428";
131-
case mlt_color_pri_smpte431:
132-
return "smpte431";
133-
case mlt_color_pri_smpte432:
134-
return "smpte432";
135-
case mlt_color_pri_none:
136-
case mlt_color_pri_invalid:
137-
break;
138-
}
139-
// Guess a reasonable default
140-
if (height < 576) {
141-
return "smpte170m";
142-
} else if (height < 720) {
143-
return "bt470bg";
144-
}
145-
return "bt709";
146-
}
147-
14873
static void create_t_filter(mlt_filter self, mlt_frame frame, mlt_color_trc out_trc)
14974
{
150-
mlt_properties frame_properties = MLT_FRAME_PROPERTIES(frame);
15175
mlt_profile profile = mlt_service_profile(MLT_FILTER_SERVICE(self));
15276
mlt_properties filter_properties = MLT_FILTER_PROPERTIES(self);
15377
const char *method = mlt_properties_get(filter_properties, "method");
@@ -158,17 +82,8 @@ static void create_t_filter(mlt_filter self, mlt_frame frame, mlt_color_trc out_
15882
mlt_properties cs_properties = MLT_FILTER_PROPERTIES(t_filter);
15983
if (!strcmp(method, "avfilter.zscale")) {
16084
mlt_properties_set(cs_properties, "av.t", av_trc_str(out_trc));
161-
} else if (!strcmp(method, "avfilter.colorspace")) {
162-
const char *colorspace_str = mlt_properties_get(frame_properties, "consumer.colorspace");
163-
if (!colorspace_str)
164-
colorspace_str = mlt_properties_get(frame_properties, "colorspace");
165-
mlt_colorspace colorspace = mlt_image_colorspace_id(colorspace_str);
166-
int height = mlt_properties_get_int(frame_properties, "height");
167-
const char *primaries_str = mlt_properties_get(frame_properties, "consumer.color_primaries");
168-
mlt_color_primaries primaries = mlt_image_color_pri_id(primaries_str);
169-
mlt_properties_set(cs_properties, "av.space", av_colorspace_str(colorspace, height));
170-
mlt_properties_set(cs_properties, "av.primaries", av_color_primaries_str(primaries, height));
171-
mlt_properties_set(cs_properties, "av.trc", av_trc_str(out_trc));
85+
} else if (!strcmp(method, "avfilter.scale")) {
86+
mlt_properties_set(cs_properties, "av.out_transfer", av_trc_str(out_trc));
17287
}
17388
mlt_service_cache_put(MLT_FILTER_SERVICE(self),
17489
"t_filter",
@@ -295,7 +210,7 @@ static int filter_get_image(mlt_frame frame,
295210
// Process the cloned frame. The cloned frame references the same image
296211
// as the original frame.
297212
mlt_filter_process(t_filter, clone_frame);
298-
ret = mlt_frame_get_image(clone_frame, image, format, width, height, writable);
213+
ret = mlt_frame_get_image(clone_frame, image, format, width, height, 0);
299214
mlt_cache_item_close(cache_item);
300215
mlt_service_unlock(MLT_FILTER_SERVICE(self));
301216

@@ -334,13 +249,13 @@ mlt_filter filter_color_transform_init(mlt_profile profile,
334249
if (!strcmp(method, "auto")) {
335250
if ((test_filter = mlt_factory_filter(profile, "avfilter.zscale", NULL))) {
336251
method = "avfilter.zscale";
337-
} else if ((test_filter = mlt_factory_filter(profile, "avfilter.colorspace", NULL))) {
338-
method = "avfilter.colorspace";
252+
} else if ((test_filter = mlt_factory_filter(profile, "avfilter.scale", NULL))) {
253+
method = "avfilter.scale";
339254
}
340255
} else if (!strcmp(method, "avfilter.zscale")) {
341256
test_filter = mlt_factory_filter(profile, "avfilter.zscale", NULL);
342-
} else if (!strcmp(method, "avfilter.colorspace")) {
343-
test_filter = mlt_factory_filter(profile, "avfilter.colorspace", NULL);
257+
} else if (!strcmp(method, "avfilter.scale")) {
258+
test_filter = mlt_factory_filter(profile, "avfilter.scale", NULL);
344259
}
345260
if (!test_filter) {
346261
mlt_log_error(NULL, "[filter_color_transform] unable to create filter %s\n", method);

src/modules/core/filter_color_transform.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ tags:
1010
- Video
1111
- Hidden
1212
description: >
13-
Convert the image colorspace to whatever was requested by the consumer.
13+
Convert the image color to whatever was requested by the consumer.
1414
This filter is designed for use as a normalizer for the loader producer.
1515
If the "force_trc" property is set on this filter, the filter will force
1616
the output trc to be "force_trc";
17-
Otherwise, if a property "consumer.mlt_color_trc" exists on the frame, then colorspace
17+
Otherwise, if a property "consumer.mlt_color_trc" exists on the frame, then it
1818
normalizes the image to the trc requested by the consumer.
1919
parameters:
2020
- identifier: method
@@ -24,13 +24,13 @@ parameters:
2424
values:
2525
- auto # Choose best available
2626
- avfilter.zscale
27-
- avfilter.colorspace
27+
- avfilter.scale
2828
description: |
2929
The underlying conversion method to use. The method is based on the
3030
encapsulated filter that is used. 'auto' will choose the best available
3131
in this order:
3232
* avfilter.zscale
33-
* avfilter.colorspace
33+
* avfilter.scale
3434
required: no
3535
readonly: no
3636
mutable: no

0 commit comments

Comments
 (0)