33 #if CONFIG_SUBTITLES_FILTER
34 # include "libavcodec/avcodec.h"
35 # include "libavformat/avformat.h"
37 #include "libavutil/avstring.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/parseutils.h"
60 #define OFFSET(x) offsetof(AssContext, x)
61 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
63 #define COMMON_OPTIONS \
64 {"filename", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
65 {"f", "set the filename of file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, \
66 {"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 }, \
97 ass->
library = ass_library_init();
110 ass_set_fonts(ass->
renderer, NULL, NULL, 1, NULL, 1);
119 ass_free_track(ass->
track);
123 ass_library_done(ass->
library);
138 ass_set_frame_size (ass->
renderer, inlink->
w, inlink->
h);
140 ass_set_aspect_ratio(ass->
renderer, (
double)inlink->
w / inlink->
h,
147 #define AR(c) ( (c)>>24)
148 #define AG(c) (((c)>>16)&0xFF)
149 #define AB(c) (((c)>>8) &0xFF)
150 #define AA(c) ((0xFF-c) &0xFF)
153 const ASS_Image *image)
155 for (; image; image = image->next) {
156 uint8_t rgba_color[] = {
AR(image->color),
AG(image->color),
AB(image->color),
AA(image->color)};
162 image->bitmap, image->stride, image->w, image->h,
163 3, 0, image->dst_x, image->dst_y);
172 int detect_change = 0;
174 ASS_Image *image = ass_render_frame(ass->
renderer, ass->
track,
175 time_ms, &detect_change);
204 #if CONFIG_ASS_FILTER
206 static const AVOption ass_options[] = {
224 "Could not create a libass track when reading file '%s'\n",
233 .description =
NULL_IF_CONFIG_SMALL(
"Render ASS subtitles onto input video using the libass library."),
240 .priv_class = &ass_class,
244 #if CONFIG_SUBTITLES_FILTER
246 static const AVOption subtitles_options[] = {
307 "Only text based subtitles are currently supported\n");
318 ass_process_codec_private(ass->
track,
333 }
else if (got_subtitle) {
338 ass_process_data(ass->
track, ass_line, strlen(ass_line));
357 .description =
NULL_IF_CONFIG_SMALL(
"Render text subtitles onto input video using the libass library."),
359 .
init = init_subtitles,
364 .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.
#define AVERROR_PATCHWELCOME
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)
const char * name
Filter name.
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
uint8_t * subtitle_header
Header containing style information for text subtitles.
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
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
AVCodecContext * codec
Codec context associated with this stream.
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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.
#define AV_LOG_QUIET
Print no output.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int query_formats(AVFilterContext *ctx)
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
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).
static double av_q2d(AVRational a)
Convert rational to double.
#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...
#define av_err2str(errnum)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
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...
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
int w
agreed upon image width
char * ass
0 terminated ASS/SSA compatible event line.
int format
agreed upon media format
Main libavfilter public API header.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
AVFilterLink ** outputs
array of pointers to output links
#define AV_LOG_INFO
Standard information.
static const int ass_libavfilter_log_level_map[]
main external API structure.
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 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...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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.
AVFilterContext * dst
dest filter
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. ...
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 const AVFilterPad ass_inputs[]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
static AVCodecContext * dec_ctx
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_DEFINE_CLASS(fname)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const AVFilterPad ass_outputs[]