Skip to content

Commit dd5966d

Browse files
committed
lavc/libaribb24: add a default style that has correct PlayResX/Y
As well as font size.
1 parent 553f5a3 commit dd5966d

File tree

1 file changed

+76
-5
lines changed

1 file changed

+76
-5
lines changed

libavcodec/libaribb24.c

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,83 @@ static void libaribb24_log(void *p, const char *msg)
4444
av_log((AVCodecContext *)p, AV_LOG_INFO, "%s\n", msg);
4545
}
4646

47+
static int libaribb24_generate_ass_header(AVCodecContext *avctx)
48+
{
49+
unsigned int plane_width = 0;
50+
unsigned int plane_height = 0;
51+
unsigned int font_size = 0;
52+
53+
switch (avctx->profile) {
54+
case FF_PROFILE_ARIB_PROFILE_A:
55+
plane_width = 960;
56+
plane_height = 540;
57+
font_size = 36;
58+
break;
59+
case FF_PROFILE_ARIB_PROFILE_C:
60+
plane_width = 320;
61+
plane_height = 180;
62+
font_size = 18;
63+
break;
64+
default:
65+
av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n");
66+
return AVERROR(EINVAL);
67+
}
68+
69+
avctx->subtitle_header = av_asprintf(
70+
"[Script Info]\r\n"
71+
"; Script generated by FFmpeg/Lavc%s\r\n"
72+
"ScriptType: v4.00+\r\n"
73+
"PlayResX: %d\r\n"
74+
"PlayResY: %d\r\n"
75+
"\r\n"
76+
"[V4+ Styles]\r\n"
77+
78+
/* ASSv4 header */
79+
"Format: Name, "
80+
"Fontname, Fontsize, "
81+
"PrimaryColour, SecondaryColour, OutlineColour, BackColour, "
82+
"Bold, Italic, Underline, StrikeOut, "
83+
"ScaleX, ScaleY, "
84+
"Spacing, Angle, "
85+
"BorderStyle, Outline, Shadow, "
86+
"Alignment, MarginL, MarginR, MarginV, "
87+
"Encoding\r\n"
88+
89+
"Style: "
90+
"Default," /* Name */
91+
"%s,%d," /* Font{name,size} */
92+
"&H%x,&H%x,&H%x,&H%x," /* {Primary,Secondary,Outline,Back}Colour */
93+
"%d,%d,%d,0," /* Bold, Italic, Underline, StrikeOut */
94+
"100,100," /* Scale{X,Y} */
95+
"0,0," /* Spacing, Angle */
96+
"%d,1,0," /* BorderStyle, Outline, Shadow */
97+
"%d,10,10,10," /* Alignment, Margin[LRV] */
98+
"0\r\n" /* Encoding */
99+
100+
"\r\n"
101+
"[Events]\r\n"
102+
"Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n",
103+
!(avctx->flags & AV_CODEC_FLAG_BITEXACT) ? AV_STRINGIFY(LIBAVCODEC_VERSION) : "",
104+
plane_width, plane_height,
105+
ASS_DEFAULT_FONT, font_size, ASS_DEFAULT_COLOR,
106+
ASS_DEFAULT_COLOR, ASS_DEFAULT_BACK_COLOR, ASS_DEFAULT_BACK_COLOR,
107+
-ASS_DEFAULT_BOLD, -ASS_DEFAULT_ITALIC, -ASS_DEFAULT_UNDERLINE,
108+
ASS_DEFAULT_BORDERSTYLE, ASS_DEFAULT_ALIGNMENT);
109+
110+
if (!avctx->subtitle_header)
111+
return AVERROR(ENOMEM);
112+
113+
avctx->subtitle_header_size = strlen(avctx->subtitle_header);
114+
115+
return 0;
116+
}
117+
47118
static int libaribb24_init(AVCodecContext *avctx)
48119
{
49120
Libaribb24Context *b24 = avctx->priv_data;
50121
void(* arib_dec_init)(arib_decoder_t* decoder) = NULL;
51122
int ret_code = AVERROR_EXTERNAL;
52123

53-
if (ff_ass_subtitle_header_default(avctx) < 0) {
54-
ret_code = AVERROR(ENOMEM);
55-
goto init_fail;
56-
}
57-
58124
if (!(b24->lib_instance = arib_instance_new(avctx))) {
59125
av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n");
60126
goto init_fail;
@@ -92,6 +158,11 @@ static int libaribb24_init(AVCodecContext *avctx)
92158

93159
arib_dec_init(b24->decoder);
94160

161+
if (libaribb24_generate_ass_header(avctx) < 0) {
162+
ret_code = AVERROR(ENOMEM);
163+
goto init_fail;
164+
}
165+
95166
return 0;
96167

97168
init_fail:

0 commit comments

Comments
 (0)