92 #define OFFSET(x) offsetof(RotContext, x)
93 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
159 float sinx = sin(angle);
160 float cosx = cos(angle);
162 return FFMAX(0, inh * sinx) +
FFMAX(0, -inw * cosx) +
171 float sinx = sin(angle);
172 float cosx = cos(angle);
174 return FFMAX(0, -inh * cosx) +
FFMAX(0, -inw * sinx) +
178 static double (*
const func1[])(
void *, double) = {
220 "Error occurred parsing angle expression '%s'\n", rot->
angle_expr_str);
224 #define SET_SIZE_EXPR(name, opt_name) do { \
225 ret = av_expr_parse_and_eval(&res, expr = rot->name##_expr_str, \
226 var_names, rot->var_values, \
227 func1_names, func1, NULL, NULL, rot, 0, ctx); \
228 if (ret < 0 || isnan(res) || isinf(res) || res <= 0) { \
229 av_log(ctx, AV_LOG_ERROR, \
230 "Error parsing or evaluating expression for option %s: " \
231 "invalid expression '%s' or non-positive or indefinite value %f\n", \
232 opt_name, expr, res); \
241 rot->
outw = res + 0.5;
244 rot->
outh = res + 0.5;
249 rot->
outw = res + 0.5;
253 outlink->
w = rot->
outw;
254 outlink->
h = rot->
outh;
259 #define FIXP2 (1<<20)
260 #define INT_PI 3294199 //(M_PI * FIXP2)
278 for (i = 2; i < 11; i += 2) {
280 a = -a*a2 / (
FIXP2*i*(i+1));
290 const uint8_t *
src,
int src_linesize,
int src_linestep,
291 int x,
int y,
int max_x,
int max_y)
293 int int_x = av_clip(x>>16, 0, max_x);
294 int int_y = av_clip(y>>16, 0, max_y);
295 int frac_x = x&0xFFFF;
296 int frac_y = y&0xFFFF;
298 int int_x1 =
FFMIN(int_x+1, max_x);
299 int int_y1 =
FFMIN(int_y+1, max_y);
301 for (i = 0; i < src_linestep; i++) {
302 int s00 = src[src_linestep * int_x + i + src_linesize * int_y ];
303 int s01 = src[src_linestep * int_x1 + i + src_linesize * int_y ];
304 int s10 = src[src_linestep * int_x + i + src_linesize * int_y1];
305 int s11 = src[src_linestep * int_x1 + i + src_linesize * int_y1];
306 int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01);
307 int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11);
309 dst_color[i] = ((int64_t)((1<<16) - frac_y)*s0 + (int64_t)frac_y*
s1) >> 32;
323 *((uint16_t *)pout) = *((uint16_t *)pin);
330 *((uint32_t *)pout) = *((uint32_t *)pin);
333 memcpy(pout, pin, elem_size);
343 memcpy(dst, src, elem_size * len);
346 for (i = 0; i<
len; i++)
347 copy_elem(dst + i*elem_size, src + (len-i-1)*src_linesize, elem_size);
350 for (i = 0; i<
len; i++)
351 copy_elem(dst + i*elem_size, src + (len-i-1)*elem_size, elem_size);
354 for (i = 0; i<
len; i++)
355 copy_elem(dst + i*elem_size, src + i*src_linesize, elem_size);
371 #define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
379 const int outw = td->
outw, outh = td->
outh;
380 const int inw = td->
inw, inh = td->
inh;
382 const int xi = td->
xi, yi = td->
yi;
383 const int c = td->
c,
s = td->
s;
384 const int start = (outh * job ) / nb_jobs;
385 const int end = (outh * (job+1)) / nb_jobs;
386 int xprime = td->
xprime + start *
s;
387 int yprime = td->
yprime + start *
c;
390 for (j = start; j <
end; j++) {
391 x = xprime + xi +
FIXP*(inw-1)/2;
392 y = yprime + yi +
FIXP*(inh-1)/2;
394 if (fabs(rot->
angle - 0) < FLT_EPSILON && outw == inw && outh == inh) {
398 }
else if (fabs(rot->
angle -
M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
402 }
else if (fabs(rot->
angle -
M_PI) < FLT_EPSILON && outw == inw && outh == inh) {
406 }
else if (fabs(rot->
angle - 3*
M_PI/2) < FLT_EPSILON && outw == inh && outh == inw) {
412 for (i = 0; i < outw; i++) {
420 if (x1 >= -1 && x1 <= inw && y1 >= -1 && y1 <= inh) {
428 int x2 = av_clip(x1, 0, inw-1);
429 int y2 = av_clip(y1, 0, inh-1);
437 *((uint16_t *)pout) = *((uint16_t *)pin);
444 *((uint32_t *)pout) = *((uint32_t *)pin);
485 angle_int = res *
FIXP * 16;
492 0, 0, outlink->
w, outlink->
h);
494 for (plane = 0; plane < rot->
nb_planes; plane++) {
495 int hsub = plane == 1 || plane == 2 ? rot->
hsub : 0;
496 int vsub = plane == 1 || plane == 2 ? rot->
vsub : 0;
502 .outh = outh, .outw = outw,
503 .xi = -(outw-1) * c / 2, .yi = (outw-1) * s / 2,
504 .xprime = -(outh-1) * s / 2,
505 .yprime = -(outh-1) * c / 2,
506 .plane =
plane, .c =
c, .s = s };
517 char *res,
int res_len,
int flags)
522 if (!strcmp(cmd,
"angle") || !strcmp(cmd,
"a")) {
528 "Error when parsing the expression '%s' for angle command\n", args);
567 .priv_class = &rotate_class,
static av_always_inline void simple_rotate(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
static av_cold int init(AVFilterContext *ctx)
static const char *const func1_names[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const AVFilterPad outputs[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
int h
agreed upon image height
static const AVOption rotate_options[]
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t fillcolor[4]
color expressed either in YUVA or RGBA colorspace for the padding area
static av_always_inline void simple_rotate_internal(uint8_t *dst, const uint8_t *src, int src_linesize, int angle, int elem_size, int len)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static const AVFilterPad rotate_inputs[]
struct AVFilterGraph * graph
filtergraph this filter belongs to
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
int nb_threads
Maximum number of threads used by filters in this graph.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
static av_cold void uninit(AVFilterContext *ctx)
A filter pad used for either input or output.
A link between two filters.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static double(*const func1[])(void *, double)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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...
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int w
agreed upon image width
static int query_formats(AVFilterContext *ctx)
static uint8_t * interpolate_bilinear(uint8_t *dst_color, const uint8_t *src, int src_linesize, int src_linestep, int x, int y, int max_x, int max_y)
Interpolate the color in src at position x and y using bilinear interpolation.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int config_props(AVFilterLink *outlink)
#define FF_CEIL_RSHIFT(a, b)
AVFILTER_DEFINE_CLASS(rotate)
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterContext * src
source filter
static int64_t int_sin(int64_t a)
Compute the sin of a using integer values.
AVExpr * angle_expr
parsed expression for the angle
int format
agreed upon media format
static const AVFilterPad rotate_outputs[]
char * angle_expr_str
expression for the angle
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
static double get_rotated_h(void *opaque, double angle)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
#define SET_SIZE_EXPR(name, opt_name)
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
const char * name
Filter name.
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
static av_always_inline void copy_elem(uint8_t *pout, const uint8_t *pin, int elem_size)
AVFilterLink ** outputs
array of pointers to output links
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar GBRA 4:4:4:4 32bpp
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
avfilter_execute_func * execute
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
AVFilterContext * dst
dest filter
int pixelstep[MAX_PLANES]
static double get_rotated_w(void *opaque, double angle)
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
double var_values[VAR_VARS_NB]
static const char *const var_names[]
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVPixelFormat
Pixel format.
int64_t frame_count
Number of past frames sent through the link.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
simple arithmetic expression evaluator