Go to the documentation of this file.
33 #include "config_components.h"
34 #if CONFIG_SUBTITLES_FILTER
49 #define FF_ASS_FEATURE_WRAP_UNICODE (LIBASS_VERSION >= 0x01600010)
70 #define OFFSET(x) offsetof(AssContext, x)
71 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
73 #define COMMON_OPTIONS \
74 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
75 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
76 {"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 }, \
77 {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, \
78 {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \
92 static void ass_log(
int ass_level,
const char *fmt, va_list args,
void *
ctx)
94 const int ass_level_clip =
av_clip(ass_level, 0,
111 ass->
library = ass_library_init();
119 ass_set_extract_fonts(ass->
library, 1);
135 ass_free_track(ass->
track);
139 ass_library_done(ass->
library);
169 #define AR(c) ( (c)>>24)
170 #define AG(c) (((c)>>16)&0xFF)
171 #define AB(c) (((c)>>8) &0xFF)
172 #define AA(c) ((0xFF-(c)) &0xFF)
175 const ASS_Image *image)
177 for (; image; image = image->next) {
178 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
184 image->bitmap, image->stride, image->w, image->h,
185 3, 0, image->dst_x, image->dst_y);
194 int detect_change = 0;
196 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
197 time_ms, &detect_change);
217 #if CONFIG_ASS_FILTER
219 static const AVOption ass_options[] = {
223 {
"simple",
"simple shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX,
FLAGS, .unit =
"shaping_mode"},
224 {
"complex",
"complex shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX,
FLAGS, .unit =
"shaping_mode"},
244 "Could not create a libass track when reading file '%s'\n",
253 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
264 #if CONFIG_SUBTITLES_FILTER
266 static const AVOption subtitles_options[] = {
272 #if FF_ASS_FEATURE_WRAP_UNICODE
273 {
"wrap_unicode",
"break lines according to the Unicode Line Breaking Algorithm",
OFFSET(wrap_unicode),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
FLAGS },
278 static const char *
const font_mimetypes[] = {
284 "application/font-sfnt",
285 "application/font-woff",
286 "application/x-truetype-font",
287 "application/vnd.ms-opentype",
288 "application/x-font-ttf",
292 static int attachment_is_font(
AVStream * st)
300 for (n = 0; font_mimetypes[n]; n++) {
373 attachment_is_font(st)) {
386 "Font attachment has no filename, ignored.\n");
405 "Only text based subtitles are currently supported\n");
436 #if FF_ASS_FEATURE_WRAP_UNICODE
441 ret = ass_track_set_feature(ass->
track, ASS_FEATURE_WRAP_UNICODE, 1);
444 "libass wasn't built with ASS_FEATURE_WRAP_UNICODE support\n");
471 ass_process_codec_private(ass->
track,
483 }
else if (got_subtitle) {
490 ass_process_chunk(ass->
track, ass_line, strlen(ass_line),
508 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
510 .
init = init_subtitles,
515 .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.
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.
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.
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).
#define FILTER_QUERY_FUNC(func)
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.
static int query_formats(AVFilterContext *ctx)
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.
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_INPUTS(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.
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
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.
#define AVFILTER_DEFINE_CLASS(fname)
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.
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
const char * name
Pad name.
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.
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.
#define FILTER_OUTPUTS(array)
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)
static const AVFilterPad ass_inputs[]
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.