1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * SSA/ASS common functions 3cabdff1aSopenharmony_ci * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org> 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci#ifndef AVCODEC_ASS_H 23cabdff1aSopenharmony_ci#define AVCODEC_ASS_H 24cabdff1aSopenharmony_ci 25cabdff1aSopenharmony_ci#include "avcodec.h" 26cabdff1aSopenharmony_ci#include "libavutil/bprint.h" 27cabdff1aSopenharmony_ci 28cabdff1aSopenharmony_ci#define ASS_DEFAULT_PLAYRESX 384 29cabdff1aSopenharmony_ci#define ASS_DEFAULT_PLAYRESY 288 30cabdff1aSopenharmony_ci 31cabdff1aSopenharmony_ci/** 32cabdff1aSopenharmony_ci * @name Default values for ASS style 33cabdff1aSopenharmony_ci * @{ 34cabdff1aSopenharmony_ci */ 35cabdff1aSopenharmony_ci#define ASS_DEFAULT_FONT "Arial" 36cabdff1aSopenharmony_ci#define ASS_DEFAULT_FONT_SIZE 16 37cabdff1aSopenharmony_ci#define ASS_DEFAULT_COLOR 0xffffff 38cabdff1aSopenharmony_ci#define ASS_DEFAULT_BACK_COLOR 0 39cabdff1aSopenharmony_ci#define ASS_DEFAULT_BOLD 0 40cabdff1aSopenharmony_ci#define ASS_DEFAULT_ITALIC 0 41cabdff1aSopenharmony_ci#define ASS_DEFAULT_UNDERLINE 0 42cabdff1aSopenharmony_ci#define ASS_DEFAULT_ALIGNMENT 2 43cabdff1aSopenharmony_ci#define ASS_DEFAULT_BORDERSTYLE 1 44cabdff1aSopenharmony_ci/** @} */ 45cabdff1aSopenharmony_ci 46cabdff1aSopenharmony_citypedef struct FFASSDecoderContext { 47cabdff1aSopenharmony_ci int readorder; 48cabdff1aSopenharmony_ci} FFASSDecoderContext; 49cabdff1aSopenharmony_ci 50cabdff1aSopenharmony_ci/** 51cabdff1aSopenharmony_ci * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. 52cabdff1aSopenharmony_ci * Can specify all fields explicitly 53cabdff1aSopenharmony_ci * 54cabdff1aSopenharmony_ci * @param avctx pointer to the AVCodecContext 55cabdff1aSopenharmony_ci * @param play_res_x subtitle frame width 56cabdff1aSopenharmony_ci * @param play_res_y subtitle frame height 57cabdff1aSopenharmony_ci * @param font name of the default font face to use 58cabdff1aSopenharmony_ci * @param font_size default font size to use 59cabdff1aSopenharmony_ci * @param primary_color default text color to use (ABGR) 60cabdff1aSopenharmony_ci * @param secondary_color default secondary text color to use (ABGR) 61cabdff1aSopenharmony_ci * @param outline_color default outline color to use (ABGR) 62cabdff1aSopenharmony_ci * @param back_color default background color to use (ABGR) 63cabdff1aSopenharmony_ci * @param bold 1 for bold text, 0 for normal text 64cabdff1aSopenharmony_ci * @param italic 1 for italic text, 0 for normal text 65cabdff1aSopenharmony_ci * @param underline 1 for underline text, 0 for normal text 66cabdff1aSopenharmony_ci * @param border_style 1 for outline, 3 for opaque box 67cabdff1aSopenharmony_ci * @param alignment position of the text (left, center, top...), defined after 68cabdff1aSopenharmony_ci * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top) 69cabdff1aSopenharmony_ci * @return >= 0 on success otherwise an error code <0 70cabdff1aSopenharmony_ci */ 71cabdff1aSopenharmony_ciint ff_ass_subtitle_header_full(AVCodecContext *avctx, 72cabdff1aSopenharmony_ci int play_res_x, int play_res_y, 73cabdff1aSopenharmony_ci const char *font, int font_size, 74cabdff1aSopenharmony_ci int primary_color, int secondary_color, 75cabdff1aSopenharmony_ci int outline_color, int back_color, 76cabdff1aSopenharmony_ci int bold, int italic, int underline, 77cabdff1aSopenharmony_ci int border_style, int alignment); 78cabdff1aSopenharmony_ci/** 79cabdff1aSopenharmony_ci * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. 80cabdff1aSopenharmony_ci * 81cabdff1aSopenharmony_ci * @param avctx pointer to the AVCodecContext 82cabdff1aSopenharmony_ci * @param font name of the default font face to use 83cabdff1aSopenharmony_ci * @param font_size default font size to use 84cabdff1aSopenharmony_ci * @param color default text color to use (ABGR) 85cabdff1aSopenharmony_ci * @param back_color default background color to use (ABGR) 86cabdff1aSopenharmony_ci * @param bold 1 for bold text, 0 for normal text 87cabdff1aSopenharmony_ci * @param italic 1 for italic text, 0 for normal text 88cabdff1aSopenharmony_ci * @param underline 1 for underline text, 0 for normal text 89cabdff1aSopenharmony_ci * @param alignment position of the text (left, center, top...), defined after 90cabdff1aSopenharmony_ci * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top) 91cabdff1aSopenharmony_ci * @return >= 0 on success otherwise an error code <0 92cabdff1aSopenharmony_ci */ 93cabdff1aSopenharmony_ciint ff_ass_subtitle_header(AVCodecContext *avctx, 94cabdff1aSopenharmony_ci const char *font, int font_size, 95cabdff1aSopenharmony_ci int color, int back_color, 96cabdff1aSopenharmony_ci int bold, int italic, int underline, 97cabdff1aSopenharmony_ci int border_style, int alignment); 98cabdff1aSopenharmony_ci 99cabdff1aSopenharmony_ci/** 100cabdff1aSopenharmony_ci * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS 101cabdff1aSopenharmony_ci * with default style. 102cabdff1aSopenharmony_ci * 103cabdff1aSopenharmony_ci * @param avctx pointer to the AVCodecContext 104cabdff1aSopenharmony_ci * @return >= 0 on success otherwise an error code <0 105cabdff1aSopenharmony_ci */ 106cabdff1aSopenharmony_ciint ff_ass_subtitle_header_default(AVCodecContext *avctx); 107cabdff1aSopenharmony_ci 108cabdff1aSopenharmony_ci/** 109cabdff1aSopenharmony_ci * Craft an ASS dialog string. 110cabdff1aSopenharmony_ci */ 111cabdff1aSopenharmony_cichar *ff_ass_get_dialog(int readorder, int layer, const char *style, 112cabdff1aSopenharmony_ci const char *speaker, const char *text); 113cabdff1aSopenharmony_ci 114cabdff1aSopenharmony_ci/** 115cabdff1aSopenharmony_ci * Add an ASS dialog to a subtitle. 116cabdff1aSopenharmony_ci */ 117cabdff1aSopenharmony_ciint ff_ass_add_rect(AVSubtitle *sub, const char *dialog, 118cabdff1aSopenharmony_ci int readorder, int layer, const char *style, 119cabdff1aSopenharmony_ci const char *speaker); 120cabdff1aSopenharmony_ci 121cabdff1aSopenharmony_ci/** 122cabdff1aSopenharmony_ci * Add an ASS dialog to a subtitle. 123cabdff1aSopenharmony_ci */ 124cabdff1aSopenharmony_ciint ff_ass_add_rect2(AVSubtitle *sub, const char *dialog, 125cabdff1aSopenharmony_ci int readorder, int layer, const char *style, 126cabdff1aSopenharmony_ci const char *speaker, unsigned *nb_rect_allocated); 127cabdff1aSopenharmony_ci 128cabdff1aSopenharmony_ci/** 129cabdff1aSopenharmony_ci * Helper to flush a text subtitles decoder making use of the 130cabdff1aSopenharmony_ci * FFASSDecoderContext. 131cabdff1aSopenharmony_ci */ 132cabdff1aSopenharmony_civoid ff_ass_decoder_flush(AVCodecContext *avctx); 133cabdff1aSopenharmony_ci 134cabdff1aSopenharmony_ci/** 135cabdff1aSopenharmony_ci * Escape a text subtitle using ASS syntax into an AVBPrint buffer. 136cabdff1aSopenharmony_ci * Newline characters will be escaped to \N. 137cabdff1aSopenharmony_ci * 138cabdff1aSopenharmony_ci * @param buf pointer to an initialized AVBPrint buffer 139cabdff1aSopenharmony_ci * @param p source text 140cabdff1aSopenharmony_ci * @param size size of the source text 141cabdff1aSopenharmony_ci * @param linebreaks additional newline chars, which will be escaped to \N 142cabdff1aSopenharmony_ci * @param keep_ass_markup braces and backslash will not be escaped if set 143cabdff1aSopenharmony_ci */ 144cabdff1aSopenharmony_civoid ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size, 145cabdff1aSopenharmony_ci const char *linebreaks, int keep_ass_markup); 146cabdff1aSopenharmony_ci#endif /* AVCODEC_ASS_H */ 147