MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ttml_encode_frame

Function ttml_encode_frame

libavcodec/ttmlenc.c:79–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77};
78
79static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf,
80 int bufsize, const AVSubtitle *sub)
81{
82 TTMLContext *s = avctx->priv_data;
83 ASSDialog *dialog;
84 int i;
85
86 av_bprint_init_for_buffer(&s->buffer, buf, bufsize);
87
88 for (i=0; i<sub->num_rects; i++) {
89 const char *ass = sub->rects[i]->ass;
90 int ret;
91
92 if (sub->rects[i]->type != SUBTITLE_ASS) {
93 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
94 return AVERROR(EINVAL);
95 }
96
97 dialog = ff_ass_split_dialog(s->ass_ctx, ass);
98 if (!dialog)
99 return AVERROR(ENOMEM);
100
101 if (dialog->style) {
102 av_bprintf(&s->buffer, "<span region=\"");
103 av_bprint_escape(&s->buffer, dialog->style, NULL,
104 AV_ESCAPE_MODE_XML,
105 AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
106 av_bprintf(&s->buffer, "\">");
107 }
108
109 ret = ff_ass_split_override_codes(&ttml_callbacks, s, dialog->text);
110 if (ret < 0) {
111 int log_level = (ret != AVERROR_INVALIDDATA ||
112 avctx->err_recognition & AV_EF_EXPLODE) ?
113 AV_LOG_ERROR : AV_LOG_WARNING;
114 av_log(avctx, log_level,
115 "Splitting received ASS dialog text %s failed: %s\n",
116 dialog->text,
117 av_err2str(ret));
118
119 if (log_level == AV_LOG_ERROR) {
120 ff_ass_free_dialog(&dialog);
121 return ret;
122 }
123 }
124
125 if (dialog->style)
126 av_bprintf(&s->buffer, "</span>");
127
128 ff_ass_free_dialog(&dialog);
129 }
130
131 if (!s->buffer.len)
132 return 0;
133 if (!av_bprint_is_complete(&s->buffer)) {
134 av_log(avctx, AV_LOG_ERROR, "Buffer too small for TTML event.\n");
135 return AVERROR_BUFFER_TOO_SMALL;
136 }

Callers

nothing calls this directly

Calls 8

av_logFunction · 0.85
ff_ass_split_dialogFunction · 0.85
av_bprintfFunction · 0.85
av_bprint_escapeFunction · 0.85
ff_ass_free_dialogFunction · 0.85
av_bprint_is_completeFunction · 0.85

Tested by

no test coverage detected