Go to the documentation of this file.
32 #include "config_components.h"
33 #if CONFIG_SUBTITLES_FILTER
48 #define FF_ASS_FEATURE_WRAP_UNICODE (LIBASS_VERSION >= 0x01600010)
69 #define OFFSET(x) offsetof(AssContext, x)
70 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
72 #define COMMON_OPTIONS \
73 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
74 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
75 {"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS }, \
76 {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
77 {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \
93 case YCBCR_NONE:
return inlink_space;
94 case YCBCR_SMPTE240M_TV:
109 switch (ass_matrix) {
110 case YCBCR_NONE:
return inlink_range;
111 case YCBCR_SMPTE240M_PC:
115 case YCBCR_SMPTE240M_TV:
125 static void ass_log(
int ass_level,
const char *fmt, va_list args,
void *
ctx)
127 const int ass_level_clip =
av_clip(ass_level, 0,
144 ass->
library = ass_library_init();
152 ass_set_extract_fonts(ass->
library, 1);
168 ass_free_track(ass->
track);
172 ass_library_done(ass->
library);
207 #define AR(c) ( (c)>>24)
208 #define AG(c) (((c)>>16)&0xFF)
209 #define AB(c) (((c)>>8) &0xFF)
210 #define AA(c) ((0xFF-(c)) &0xFF)
213 const ASS_Image *image)
215 for (; image; image = image->next) {
216 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
222 image->bitmap, image->stride, image->w, image->h,
223 3, 0, image->dst_x, image->dst_y);
232 int detect_change = 0;
234 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
235 time_ms, &detect_change);
255 #if CONFIG_ASS_FILTER
257 static const AVOption ass_options[] = {
261 {
"simple",
"simple shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX,
FLAGS, .unit =
"shaping_mode"},
262 {
"complex",
"complex shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX,
FLAGS, .unit =
"shaping_mode"},
282 "Could not create a libass track when reading file '%s'\n",
291 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
302 #if CONFIG_SUBTITLES_FILTER
304 static const AVOption subtitles_options[] = {
310 #if FF_ASS_FEATURE_WRAP_UNICODE
311 {
"wrap_unicode",
"break lines according to the Unicode Line Breaking Algorithm",
OFFSET(wrap_unicode),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
FLAGS },
316 static const char *
const font_mimetypes[] = {
322 "application/font-sfnt",
323 "application/font-woff",
324 "application/x-truetype-font",
325 "application/vnd.ms-opentype",
326 "application/x-font-ttf",
330 static int attachment_is_font(
AVStream * st)
338 for (n = 0; font_mimetypes[n]; n++) {
411 attachment_is_font(st)) {
424 "Font attachment has no filename, ignored.\n");
443 "Only text based subtitles are currently supported\n");
474 #if FF_ASS_FEATURE_WRAP_UNICODE
479 ret = ass_track_set_feature(ass->
track, ASS_FEATURE_WRAP_UNICODE, 1);
482 "libass wasn't built with ASS_FEATURE_WRAP_UNICODE support\n");
509 ass_process_codec_private(ass->
track,
521 }
else if (got_subtitle) {
528 ass_process_chunk(ass->
track, ass_line, strlen(ass_line),
546 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
548 .
init = init_subtitles,
553 .priv_class = &subtitles_class,
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
static enum AVColorSpace ass_get_color_space(ASS_YCbCrMatrix ass_matrix, enum AVColorSpace inlink_space)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
static AVCodecContext * dec_ctx
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
enum AVMediaType codec_type
General type of the encoded data.
static enum AVColorRange ass_get_color_range(ASS_YCbCrMatrix ass_matrix, enum AVColorRange inlink_range)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int config_input(AVFilterLink *inlink)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
AVStream ** streams
A list of all streams in the file.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
@ AVCOL_RANGE_JPEG
Full range content.
uint8_t * subtitle_header
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
char * ass
0 terminated ASS/SSA compatible event line.
A filter pad used for either input or output.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
This struct describes the properties of a single codec described by an AVCodecID.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
static double av_q2d(AVRational a)
Convert an AVRational to a double.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int64_t pts
Same as packet pts, in AV_TIME_BASE.
#define FILTER_OUTPUTS(array)
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
int subtitle_header_size
Header containing style information for text subtitles.
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 list
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define AVFILTER_DEFINE_CLASS(fname)
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int extradata_size
Size of the extradata content in bytes.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVDictionary * codec_opts
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, unsigned flags)
Init a draw context.
static int64_t start_time
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static AVRational av_make_q(int num, int den)
Create an AVRational.
int pix_step[4]
steps per pixel for each plane of the main output
uint32_t end_display_time
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_LOG_INFO
Standard information.
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define i(width, name, range_min, range_max)
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
AVColorSpace
YUV colorspace type.
#define FILTER_QUERY_FUNC2(func)
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
const char * name
Pad name.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
const AVFilter ff_vf_subtitles
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
static const int ass_libavfilter_log_level_map[]
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
main external API structure.
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AV_OPT_TYPE_INT
Underlying C type is int.
static av_cold int init(AVFilterContext *ctx)
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
static void overlay_ass_image(AssContext *ass, AVFrame *picref, const ASS_Image *image)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static av_cold void uninit(AVFilterContext *ctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
@ 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...
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
AVColorRange
Visual content value range.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const AVFilterPad ass_inputs[]