29#include <aribb24/aribb24.h>
30#include <aribb24/parser.h>
31#include <aribb24/decoder.h>
74 unsigned int plane_width = 0;
75 unsigned int plane_height = 0;
76 unsigned int font_size = 0;
100 "; Script generated by FFmpeg/Lavc%s\n"
101 "ScriptType: v4.00+\n"
109 "Fontname, Fontsize, "
110 "PrimaryColour, SecondaryColour, OutlineColour, BackColour, "
111 "Bold, Italic, Underline, StrikeOut, "
114 "BorderStyle, Outline, Shadow, "
115 "Alignment, MarginL, MarginR, MarginV, "
121 "&H%x,&H%x,&H%x,&H%x,"
131 "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n",
133 plane_width, plane_height,
150 void(* arib_dec_init)(arib_decoder_t*
decoder) =
NULL;
181 arib_dec_init = arib_initialize_decoder_a_profile;
184 arib_dec_init = arib_initialize_decoder_c_profile;
205 arib_finalize_decoder(b24->
decoder);
213#define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
218 const arib_buf_region_t *region = arib_decoder_get_regions(b24->
decoder);
226 ptrdiff_t region_length = region->p_end - region->p_start;
227 unsigned int ruby_region =
228 region->i_fontheight == (profile_font_size / 2);
231 int foreground_bgr_color =
RGB_TO_BGR(region->i_foreground_color);
232 int background_bgr_color =
RGB_TO_BGR(region->i_background_color);
234 if (region_length < 0) {
246 av_bprintf(&buf,
"{\\1c&H%06x&}", foreground_bgr_color);
248 if (region->i_foreground_alpha != 0)
249 av_bprintf(&buf,
"{\\1a&H%02x&}", region->i_foreground_alpha);
252 av_bprintf(&buf,
"{\\3c&H%06x&}", background_bgr_color);
254 if (region->i_background_alpha != 0)
255 av_bprintf(&buf,
"{\\3a&H%02x&}", region->i_background_alpha);
258 if (region->i_fontwidth != profile_font_size ||
259 region->i_fontheight != profile_font_size) {
260 av_bprintf(&buf,
"{\\fscx%"PRId64
"\\fscy%"PRId64
"}",
274 region = region->p_next;
298 size_t parsed_data_size = 0;
299 size_t decoded_subtitle_size = 0;
300 const unsigned char *parsed_data =
NULL;
301 char *decoded_subtitle =
NULL;
302 time_t subtitle_duration = 0;
310 parsed_data = arib_parser_get_data(b24->
parser,
312 if (!parsed_data || !parsed_data_size) {
314 "packet (dts: %"PRId64
", pts: %"PRId64
").\n",
319 decoded_subtitle_size = parsed_data_size * 4;
320 if (!(decoded_subtitle =
av_mallocz(decoded_subtitle_size + 1))) {
322 "Failed to allocate buffer for decoded subtitle!\n");
326 decoded_subtitle_size = arib_decode_buffer(b24->
decoder,
330 decoded_subtitle_size);
332 subtitle_duration = arib_decoder_get_time(b24->
decoder);
345 "Result: '%s' (size: %zu, pkt_pts: %"PRId64
", sub_pts: %"PRId64
" "
346 "duration: %"PRIu32
", pkt_timebase: %d/%d, time_base: %d/%d')\n",
347 decoded_subtitle ? decoded_subtitle :
"<no subtitle>",
348 decoded_subtitle_size,
354 if (decoded_subtitle)
363 arib_finalize_decoder(b24->
decoder);
365 return ret < 0 ? ret :
pkt->size;
375#define OFFSET(x) offsetof(Libaribb24Context, x)
376#define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
378 {
"aribb24-base-path",
"set the base path for the libaribb24 library",
380 {
"aribb24-skip-ruby-text",
"skip ruby text blocks during decoding",
382 {
"default_profile",
"default profile to use if not specified in the stream parameters",
390 .class_name =
"libaribb24 decoder",
397 .p.name =
"libaribb24",
402 .p.wrapper_name =
"libaribb24",
const FFCodec ff_libaribb24_decoder
static av_cold void close(AVCodecParserContext *s)
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int readorder, int layer, const char *style, const char *speaker)
Add an ASS dialog to a subtitle.
#define ASS_DEFAULT_ALIGNMENT
#define ASS_DEFAULT_COLOR
#define ASS_DEFAULT_BORDERSTYLE
#define ASS_DEFAULT_BACK_COLOR
#define ASS_DEFAULT_UNDERLINE
#define ASS_DEFAULT_ITALIC
Libavcodec external API header.
char * av_asprintf(const char *fmt,...)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_DECODE_SUB_CB(func)
#define AV_PROFILE_ARIB_PROFILE_A
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_ARIB_PROFILE_C
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
@ AV_CODEC_ID_ARIB_CAPTION
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
static void libaribb24_flush(AVCodecContext *avctx)
static av_cold int libaribb24_init(AVCodecContext *avctx)
static int libaribb24_generate_ass_header(AVCodecContext *avctx)
static void libaribb24_log(void *p, const char *msg)
static av_cold int libaribb24_close(AVCodecContext *avctx)
static int libaribb24_decode(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *pkt)
static unsigned int get_profile_font_size(AVCodecContext *avctx)
static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub)
static const AVClass aribb24_class
static const chunk_decoder decoder[8]
#define LIBAVCODEC_VERSION
Memory handling functions.
Describe the class of an AVClass context structure.
main external API structure.
int subtitle_header_size
Header containing style information for text subtitles.
int flags2
AV_CODEC_FLAG2_*.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
uint8_t * subtitle_header
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
arib_instance_t * lib_instance
unsigned int aribb24_skip_ruby