33 #if CONFIG_SUBTITLES_FILTER 65 #define OFFSET(x) offsetof(AssContext, x) 66 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 68 #define COMMON_OPTIONS \ 69 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \ 70 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \ 71 {"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 }, \ 72 {"fontsdir", "set the directory containing the fonts to read", OFFSET(fontsdir), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \ 73 {"alpha", "enable processing of alpha channel", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS }, \ 89 const int ass_level_clip = av_clip(ass_level, 0,
106 ass->
library = ass_library_init();
129 ass_free_track(ass->
track);
133 ass_library_done(ass->
library);
147 ass_set_frame_size (ass->
renderer, inlink->
w, inlink->
h);
149 ass_set_aspect_ratio(ass->
renderer, (
double)inlink->
w / inlink->
h,
158 #define AR(c) ( (c)>>24) 159 #define AG(c) (((c)>>16)&0xFF) 160 #define AB(c) (((c)>>8) &0xFF) 161 #define AA(c) ((0xFF-(c)) &0xFF) 164 const ASS_Image *image)
166 for (; image; image = image->next) {
167 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
173 image->bitmap, image->stride, image->w, image->h,
174 3, 0, image->dst_x, image->dst_y);
183 int detect_change = 0;
185 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
186 time_ms, &detect_change);
215 #if CONFIG_ASS_FILTER 217 static const AVOption ass_options[] = {
221 {
"simple",
"simple shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
222 {
"complex",
"complex shaping", 0,
AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX,
FLAGS,
"shaping_mode"},
242 "Could not create a libass track when reading file '%s'\n",
251 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
262 #if CONFIG_SUBTITLES_FILTER 264 static const AVOption subtitles_options[] = {
273 static const char *
const font_mimetypes[] = {
274 "application/x-truetype-font",
275 "application/vnd.ms-opentype",
276 "application/x-font-ttf",
280 static int attachment_is_font(
AVStream * st)
288 for (n = 0; font_mimetypes[
n]; n++) {
361 attachment_is_font(st)) {
374 "Font attachment has no filename, ignored.\n");
392 "Only text based subtitles are currently supported\n");
398 av_dict_set(&codec_opts,
"sub_text_format",
"ass", 0);
440 ass_set_style_overrides(ass->
library, list);
445 ass_process_codec_private(ass->
track,
460 }
else if (got_subtitle) {
468 ass_process_data(ass->
track, ass_line, strlen(ass_line));
470 ass_process_chunk(ass->
track, ass_line, strlen(ass_line),
471 start_time, duration);
489 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
491 .
init = init_subtitles,
496 .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).
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
int pix_step[4]
steps per pixel for each plane of the main output
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...
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
#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.
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
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.
const char AVS_Value args
#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 inputs[]
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.
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
Codec parameters associated with this stream.
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.