33 #if CONFIG_SUBTITLES_FILTER
64 #define OFFSET(x) offsetof(AssContext, x)
65 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
67 #define COMMON_OPTIONS \
68 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
69 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
70 {"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 }, \
71 {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
87 const int ass_level_clip = av_clip(ass_level, 0,
104 ass->
library = ass_library_init();
127 ass_free_track(ass->
track);
131 ass_library_done(ass->
library);
145 ass_set_frame_size (ass->
renderer, inlink->
w, inlink->
h);
147 ass_set_aspect_ratio(ass->
renderer, (
double)inlink->
w / inlink->
h,
156 #define AR(c) ( (c)>>24)
157 #define AG(c) (((c)>>16)&0xFF)
158 #define AB(c) (((c)>>8) &0xFF)
159 #define AA(c) ((0xFF-(c)) &0xFF)
162 const ASS_Image *image)
164 for (; image; image = image->next) {
165 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
171 image->bitmap, image->stride, image->w, image->h,
172 3, 0, image->dst_x, image->dst_y);
181 int detect_change = 0;
183 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
184 time_ms, &detect_change);
213 #if CONFIG_ASS_FILTER
215 static const AVOption ass_options[] = {
219 {
"simple",
"simple shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
220 {
"complex",
"complex shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
240 "Could not create a libass track when reading file '%s'\n",
249 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
260 #if CONFIG_SUBTITLES_FILTER
262 static const AVOption subtitles_options[] = {
271 static const char *
const font_mimetypes[] = {
272 "application/x-truetype-font",
273 "application/vnd.ms-opentype",
274 "application/x-font-ttf",
278 static int attachment_is_font(
AVStream * st)
286 for (n = 0; font_mimetypes[
n]; n++) {
359 attachment_is_font(st)) {
372 "Font attachment has no filename, ignored.\n");
390 "Only text based subtitles are currently supported\n");
396 av_dict_set(&codec_opts,
"sub_text_format",
"ass", 0);
438 ass_set_style_overrides(ass->
library, list);
443 ass_process_codec_private(ass->
track,
458 }
else if (got_subtitle) {
466 ass_process_data(ass->
track, ass_line, strlen(ass_line));
468 ass_process_chunk(ass->
track, ass_line, strlen(ass_line),
469 start_time, duration);
487 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
489 .
init = init_subtitles,
494 .priv_class = &subtitles_class,
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)
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.
Main libavfilter public API header.
int h
agreed upon image height
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
void av_codec_set_pkt_timebase(AVCodecContext *avctx, AVRational val)
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
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 int64_t start_time
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).
#define LIBAVCODEC_VERSION_INT
AVStream ** streams
A list of all streams in the file.
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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. ...
enum AVMediaType codec_type
General type of the encoded data.
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...
#define AV_VERSION_INT(a, b, c)
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
int extradata_size
Size of the extradata content in bytes.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
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.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
#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.
static const AVFilterPad outputs[]
int format
agreed upon media format
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
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.
#define AV_LOG_INFO
Standard information.
static const AVFilterPad inputs[]
Libavcodec external API header.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static const int ass_libavfilter_log_level_map[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static AVRational av_make_q(int num, int den)
Create an AVRational.
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
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.
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.
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
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.
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
AVCodecParameters * codecpar
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
static const AVFilterPad ass_outputs[]
uint8_t * subtitle_header
Header containing style information for text subtitles.