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

Unified · Split

libavfilter/vf_subtitles.c+37−1
@@ -88,6 +88,40 @@ static const int ass_libavfilter_log_level_map[] = { · 87 unmodified lines
88 [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */88 [7] = AV_LOG_DEBUG, /* MSGL_DBG2 */
89};89};
90 90
91static 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
108static 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
91static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)125static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
92{126{
93 const int ass_level_clip = av_clip(ass_level, 0,127 const int ass_level_clip = av_clip(ass_level, 0,
@@ -150,7 +184,9 @@ static int config_input(AVFilterLink *inlink) · 56 unmodified lines
150{184{
151 AssContext *ass = inlink->dst->priv;185 AssContext *ass = inlink->dst->priv;
152 186
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),
154 ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);190 ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
155 191
156 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);192 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