27 #include <aribb24/aribb24.h> 28 #include <aribb24/parser.h> 29 #include <aribb24/decoder.h> 63 unsigned int plane_width = 0;
64 unsigned int plane_height = 0;
65 unsigned int font_size = 0;
85 "; Script generated by FFmpeg/Lavc%s\r\n" 86 "ScriptType: v4.00+\r\n" 94 "Fontname, Fontsize, " 95 "PrimaryColour, SecondaryColour, OutlineColour, BackColour, " 96 "Bold, Italic, Underline, StrikeOut, " 99 "BorderStyle, Outline, Shadow, " 100 "Alignment, MarginL, MarginR, MarginV, " 106 "&H%x,&H%x,&H%x,&H%x," 116 "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n",
118 plane_width, plane_height,
162 arib_dec_init = arib_initialize_decoder_a_profile;
165 arib_dec_init = arib_initialize_decoder_c_profile;
184 arib_finalize_decoder(b24->
decoder);
197 arib_finalize_decoder(b24->
decoder);
205 #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) 210 const arib_buf_region_t *region = arib_decoder_get_regions(b24->
decoder);
212 AVBPrint buf = { 0 };
218 ptrdiff_t region_length = region->p_end - region->p_start;
219 unsigned int ruby_region =
220 region->i_fontheight == (profile_font_size / 2);
223 int foreground_bgr_color =
RGB_TO_BGR(region->i_foreground_color);
224 int background_bgr_color =
RGB_TO_BGR(region->i_background_color);
226 if (region_length < 0) {
238 av_bprintf(&buf,
"{\\1c&H%06x&}", foreground_bgr_color);
240 if (region->i_foreground_alpha != 0)
241 av_bprintf(&buf,
"{\\1a&H%02x&}", region->i_foreground_alpha);
244 av_bprintf(&buf,
"{\\3c&H%06x&}", background_bgr_color);
246 if (region->i_background_alpha != 0)
247 av_bprintf(&buf,
"{\\3a&H%02x&}", region->i_background_alpha);
250 if (region->i_fontwidth != profile_font_size ||
251 region->i_fontheight != profile_font_size) {
252 av_bprintf(&buf,
"{\\fscx%"PRId64
"\\fscy%"PRId64
"}",
266 region = region->p_next;
289 size_t parsed_data_size = 0;
290 size_t decoded_subtitle_size = 0;
291 const unsigned char *parsed_data =
NULL;
292 char *decoded_subtitle =
NULL;
293 time_t subtitle_duration = 0;
301 parsed_data = arib_parser_get_data(b24->
parser,
303 if (!parsed_data || !parsed_data_size) {
305 "packet (dts: %"PRId64
", pts: %"PRId64
").\n",
310 decoded_subtitle_size = parsed_data_size * 4;
311 if (!(decoded_subtitle =
av_mallocz(decoded_subtitle_size + 1))) {
313 "Failed to allocate buffer for decoded subtitle!\n");
317 decoded_subtitle_size = arib_decode_buffer(b24->
decoder,
321 decoded_subtitle_size);
323 subtitle_duration = arib_decoder_get_time(b24->
decoder);
336 "Result: '%s' (size: %zu, pkt_pts: %"PRId64
", sub_pts: %"PRId64
" " 337 "duration: %"PRIu32
", pkt_timebase: %d/%d, time_base: %d/%d')\n",
338 decoded_subtitle ? decoded_subtitle :
"<no subtitle>",
339 decoded_subtitle_size,
345 if (decoded_subtitle)
354 arib_finalize_decoder(b24->
decoder);
356 return ret < 0 ? ret : pkt->
size;
366 #define OFFSET(x) offsetof(Libaribb24Context, x) 367 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM 369 {
"aribb24-base-path",
"set the base path for the libaribb24 library",
371 {
"aribb24-skip-ruby-text",
"skip ruby text blocks during decoding",
384 .
name =
"libaribb24",
393 .priv_class= &aribb24_class,
394 .wrapper_name =
"libaribb24",
AVCodec ff_libaribb24_decoder
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
#define ASS_DEFAULT_BORDERSTYLE
static const AVOption options[]
arib_instance_t * lib_instance
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static const AVClass aribb24_class
const char * av_default_item_name(void *ptr)
Return the context name.
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int libaribb24_init(AVCodecContext *avctx)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static void libaribb24_flush(AVCodecContext *avctx)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define ASS_DEFAULT_ALIGNMENT
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define FF_PROFILE_ARIB_PROFILE_C
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
#define ASS_DEFAULT_BACK_COLOR
#define ASS_DEFAULT_UNDERLINE
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BPRINT_SIZE_UNLIMITED
static int libaribb24_generate_ass_header(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
char * av_asprintf(const char *fmt,...)
static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static unsigned int get_profile_font_size(int profile)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
main external API structure.
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
unsigned int aribb24_skip_ruby
static int libaribb24_decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *pkt)
#define LIBAVCODEC_VERSION
#define ASS_DEFAULT_COLOR
static int libaribb24_close(AVCodecContext *avctx)
#define FF_PROFILE_ARIB_PROFILE_A
#define ASS_DEFAULT_ITALIC
static void libaribb24_log(void *p, const char *msg)
int flags2
AV_CODEC_FLAG2_*.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static float sub(float src0, float src1)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
uint8_t * subtitle_header
Header containing style information for text subtitles.