29 #include "libavutil/avstring.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/bprint.h"
37 char *f = strchr(s, c);
38 return f ? (f -
s) : -1;
50 #define MICRODVD_PERSISTENT_OFF 0
51 #define MICRODVD_PERSISTENT_ON 1
52 #define MICRODVD_PERSISTENT_OPENED 2
55 #define MICRODVD_TAGS "cfshyYpo"
63 memcpy(&tags[tag_index], &tag,
sizeof(tag));
67 #define MICRODVD_STYLES "ibus"
73 char tag_char = *(s + 1);
76 if (!tag_char || *(s + 2) !=
':')
86 while (*s && *s !=
'}') {
90 tag.
data1 |= (1 << style_index);
106 tag.
data1 = strtol(s, &s, 16) & 0x00ffffff;
130 tag.
data1 = strtol(s, &s, 10);
152 tag.
data1 = (*s++ ==
'1');
161 tag.
data1 = strtol(s, &s, 10);
165 tag.
data2 = strtol(s, &s, 10);
190 switch (tags[i].
key) {
194 if (tags[i].
data1 & (1 << sidx))
208 av_bprintf(new_line,
"{\\fs%d}", tags[i].data1);
212 if (tags[i].data1 == 0)
218 tags[i].data1, tags[i].
data2);
234 switch (tags[i].
key) {
238 if (tags[i].
data1 & (1 << sidx))
267 struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}};
269 if (avpkt->
size <= 0)
273 if (sscanf(line,
"{%*d}{%*[0123456789]}%c", &c) == 1 &&
274 line[avpkt->
size - 1] ==
'\n') {
276 "information and a trailing line break). You need to upgrade "
277 "your libavformat or sanitize your packet.\n");
284 while (line < end && *line) {
291 while (line < end && *line && *line !=
'|') {
297 if (line < end && *line ==
'|') {
318 *got_sub_ptr = sub->num_rects > 0;
332 struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}};
343 if (tags[i].
data1 & (1 << sidx)) {
345 case 'i': italic = 1;
break;
346 case 'b': bold = 1;
break;
347 case 'u': underline = 1;
break;
353 case 'c': color = tags[i].
data1;
break;
354 case 's': font_size = tags[i].
data1;
break;
355 case 'p': alignment = 8;
break;
367 underline, alignment);
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
static void microdvd_set_tag(struct microdvd_tag *tags, struct microdvd_tag tag)
AVCodec ff_microdvd_decoder
#define MICRODVD_PERSISTENT_ON
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int microdvd_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt)
static char * microdvd_load_tags(struct microdvd_tag *tags, char *s)
#define MICRODVD_PERSISTENT_OFF
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define ASS_DEFAULT_ALIGNMENT
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static av_cold int end(AVCodecContext *avctx)
const char * name
Name of the codec implementation.
static int av_tolower(int c)
Locale-independent conversion of ASCII characters to lowercase.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int ff_ass_subtitle_header(AVCodecContext *avctx, const char *font, int font_size, int color, int back_color, int bold, int italic, int underline, int alignment)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
#define ASS_DEFAULT_BACK_COLOR
#define ASS_DEFAULT_UNDERLINE
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Libavcodec external API header.
#define ASS_DEFAULT_FONT_SIZE
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int ts_start, int duration, int raw)
Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect.
static void microdvd_open_tags(AVBPrint *new_line, struct microdvd_tag *tags)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Buffer to print data progressively.
static void microdvd_close_no_persistent_tags(AVBPrint *new_line, struct microdvd_tag *tags)
static int microdvd_init(AVCodecContext *avctx)
#define AV_BPRINT_SIZE_AUTOMATIC
#define MICRODVD_PERSISTENT_OPENED
main external API structure.
rational number numerator/denominator
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static int indexof(const char *s, int c)
#define ASS_DEFAULT_COLOR
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
#define ASS_DEFAULT_ITALIC
#define AVERROR_INVALIDDATA
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...