33 #if CONFIG_SUBTITLES_FILTER
63 #define OFFSET(x) offsetof(AssContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
66 #define COMMON_OPTIONS \
67 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
68 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
69 {"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
85 const int ass_level_clip = av_clip(ass_level, 0,
102 ass->
library = ass_library_init();
123 ass_free_track(ass->
track);
127 ass_library_done(ass->
library);
141 ass_set_frame_size (ass->
renderer, inlink->
w, inlink->
h);
143 ass_set_aspect_ratio(ass->
renderer, (
double)inlink->
w / inlink->
h,
152 #define AR(c) ( (c)>>24)
153 #define AG(c) (((c)>>16)&0xFF)
154 #define AB(c) (((c)>>8) &0xFF)
155 #define AA(c) ((0xFF-(c)) &0xFF)
158 const ASS_Image *image)
160 for (; image; image = image->next) {
161 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
167 image->bitmap, image->stride, image->w, image->h,
168 3, 0, image->dst_x, image->dst_y);
177 int detect_change = 0;
179 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
180 time_ms, &detect_change);
209 #if CONFIG_ASS_FILTER
211 static const AVOption ass_options[] = {
215 {
"simple",
"simple shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
216 {
"complex",
"complex shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
236 "Could not create a libass track when reading file '%s'\n",
245 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
256 #if CONFIG_SUBTITLES_FILTER
258 static const AVOption subtitles_options[] = {
267 static const char *
const font_mimetypes[] = {
268 "application/x-truetype-font",
269 "application/vnd.ms-opentype",
270 "application/x-font-ttf",
274 static int attachment_is_font(
AVStream * st)
282 for (n = 0; font_mimetypes[
n]; n++) {
355 attachment_is_font(st)) {
368 "Font attachment has no filename, ignored.\n");
387 "Only text based subtitles are currently supported\n");
414 ass_set_style_overrides(ass->
library, list);
419 ass_process_codec_private(ass->
track,
434 }
else if (got_subtitle) {
439 ass_process_data(ass->
track, ass_line, strlen(ass_line));
458 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
460 .
init = init_subtitles,
465 .priv_class = &subtitles_class,
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, 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.
static void overlay_ass_image(AssContext *ass, AVFrame *picref, const ASS_Image *image)
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
static int config_input(AVFilterLink *inlink)
void av_free_packet(AVPacket *pkt)
Free a packet.
This structure describes decoded (raw) audio or video data.
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
Main libavfilter public API header.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int h
agreed upon image height
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
#define FF_ARRAY_ELEMS(a)
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int query_formats(AVFilterContext *ctx)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream ** streams
A list of all streams in the file.
static double av_q2d(AVRational a)
Convert rational to double.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
A link between two filters.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Libavcodec external API header.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
AVCodecContext * codec
Codec context associated with this stream.
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
int w
agreed upon image width
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Opaque data information usually sparse.
int format
agreed upon media format
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_LOG_INFO
Standard information.
enum AVMediaType codec_type
static const int ass_libavfilter_log_level_map[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
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...
const char * name
Filter name.
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
AVFilterLink ** outputs
array of pointers to output links
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
This struct describes the properties of a single codec described by an AVCodecID. ...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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()...
static av_cold int init(AVFilterContext *ctx)
AVDictionary * codec_opts
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
static AVCodecContext * dec_ctx
static const AVFilterPad ass_inputs[]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static av_cold void uninit(AVFilterContext *ctx)
AVFilterContext * dst
dest filter
#define AVFILTER_DEFINE_CLASS(fname)
char * ass
0 terminated ASS/SSA compatible event line.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
This structure stores compressed data.
static const AVFilterPad ass_outputs[]
uint8_t * subtitle_header
Header containing style information for text subtitles.