History

avfilter/vf_subtitles: Respect YCbCr Matrix header

As specified in libass's ass_types.h, the colors or ASS_Images should be converted to YCbCr using the matrix/range specified in the track's YCbCrMatrix field (unless that field is set to YCBCR_NONE, and defaulting to TV.601 if the header is missing). This does not affect any subtitles generated or transcoded by ffmpeg, since these contain a 'YCbCrMatrix: None' header.

arch1t3cht committed 2 years ago

Commit 72e53811 parent c98810a1 file · +37 −1Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_subtitles.c+37−1
@@ -88,6 +88,40 @@ static const int ass_libavfilter_log_level_map[] = { · 87 unmodified lines
8888 [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
8989 };
9090
91+static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space) {
92+ switch (ass_matrix) {
93+ case YCBCR_NONE: return inlink_space;
94+ case YCBCR_SMPTE240M_TV:
95+ case YCBCR_SMPTE240M_PC: return AVCOL_SPC_SMPTE240M;
96+ case YCBCR_FCC_TV:
97+ case YCBCR_FCC_PC: return AVCOL_SPC_FCC;
98+ case YCBCR_BT709_TV:
99+ case YCBCR_BT709_PC: return AVCOL_SPC_BT709;
100+ case YCBCR_BT601_TV:
101+ case YCBCR_BT601_PC:
102+ case YCBCR_DEFAULT:
103+ case YCBCR_UNKNOWN:
104+ default: return AVCOL_SPC_SMPTE170M;
105+ }
106+}
107+
108+static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range) {
109+ switch (ass_matrix) {
110+ case YCBCR_NONE: return inlink_range;
111+ case YCBCR_SMPTE240M_PC:
112+ case YCBCR_FCC_PC:
113+ case YCBCR_BT709_PC:
114+ case YCBCR_BT601_PC: return AVCOL_RANGE_JPEG;
115+ case YCBCR_SMPTE240M_TV:
116+ case YCBCR_FCC_TV:
117+ case YCBCR_BT709_TV:
118+ case YCBCR_BT601_TV:
119+ case YCBCR_DEFAULT:
120+ case YCBCR_UNKNOWN:
121+ default: return AVCOL_RANGE_MPEG;
122+ }
123+}
124+
91125 static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
92126 {
93127 const int ass_level_clip = av_clip(ass_level, 0,
@@ -150,7 +184,9 @@ static int config_input(AVFilterLink *inlink) · 56 unmodified lines
150184 {
151185 AssContext *ass = inlink->dst->priv;
152186
153− ff_draw_init2(&ass->draw, inlink->format, inlink->colorspace, inlink->color_range,
187+ ff_draw_init2(&ass->draw, inlink->format,
188+ ass_get_color_space(ass->track->YCbCrMatrix, inlink->colorspace),
189+ ass_get_color_range(ass->track->YCbCrMatrix, inlink->color_range),
154190 ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
155191
156192 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t