Go to the documentation of this file.
32 #define AVSC_NO_DECLSPEC
39 #define AVISYNTH_LIB "avisynth"
40 #define USING_AVISYNTH
44 #define AVISYNTH_NAME "libavxsynth"
45 #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
50 #define AVSC_DECLARE_FUNC(name) name ## _func name
74 #undef AVSC_DECLARE_FUNC
100 #ifdef USING_AVISYNTH
125 #define LOAD_AVS_FUNC(name, continue_on_fail) \
126 avs_library.name = (name ## _func) \
127 dlsym(avs_library.library, #name); \
128 if (!continue_on_fail && !avs_library.name) \
145 #ifdef USING_AVISYNTH
204 while (prev->
next != avs)
252 #ifdef USING_AVISYNTH
458 "unknown AviSynth colorspace %d\n", avs->
vi->
pixel_type);
464 #ifdef USING_AVISYNTH
467 avs->
planes = avs_planes_rgba;
471 avs->
planes = avs_planes_yuva;
475 avs->
planes = avs_planes_rgb;
559 #ifdef USING_AVISYNTH
560 char filename_ansi[MAX_PATH * 4];
561 wchar_t filename_wc[MAX_PATH * 4];
567 #ifdef USING_AVISYNTH
569 MultiByteToWideChar(CP_UTF8, 0,
s->filename, -1, filename_wc, MAX_PATH * 4);
570 WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
591 #ifdef USING_AVISYNTH
599 "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
641 unsigned char *dst_p;
642 const unsigned char *src_p;
643 int n,
i,
plane, rowsize, planeheight, pitch,
bits;
655 #ifdef USING_AVISYNTH
699 #ifdef USING_AVISYNTH
715 src_p = src_p + (planeheight - 1) * pitch;
719 #ifdef USING_AVISYNTH
723 src_p = src_p + (planeheight - 1) * pitch;
729 rowsize, planeheight);
730 dst_p += rowsize * planeheight;
862 int64_t timestamp,
int flags)
875 st =
s->streams[stream_index];
879 (timestamp > INT_MAX) ||
#define AV_PIX_FMT_YUVA422P16
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PIX_FMT_GBRAP16
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static av_cold void avisynth_atexit_handler(void)
enum AVMediaType codec_type
General type of the encoded data.
static av_cold int avisynth_load_library(void)
AVInputFormat ff_avisynth_demuxer
AVSC_INLINE int avs_is_error(AVS_Value v)
#define AVERROR_EOF
End of file.
AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame *p, int plane)
static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo *p)
#define AV_PIX_FMT_YUVA420P16
static int avs_atexit_called
#define AV_PIX_FMT_YUVA420P10
static const int avs_planes_yuv[3]
AVRational avg_frame_rate
Average framerate.
const AVSC_INLINE unsigned char * avs_get_read_ptr_p(const AVS_VideoFrame *p, int plane)
#define AV_PIX_FMT_YUV420P10
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame *p, int plane)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
AVSC_INLINE AVS_Value avs_new_value_string(const char *v0)
#define AV_PIX_FMT_GBRP10
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define AV_PIX_FMT_YUVA444P16
static av_cold int read_close(AVFormatContext *ctx)
#define AV_PIX_FMT_GRAY16
int64_t duration
Decoding: duration of the stream, in stream time base.
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
#define AV_PIX_FMT_YUV444P10
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_GBRAP10
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC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PLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_PIX_FMT_GBRAP12
#define LOAD_AVS_FUNC(name, continue_on_fail)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
static av_cold int avisynth_read_close(AVFormatContext *s)
AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame *p, int plane)
static AviSynthContext * avs_ctx_list
#define AV_PIX_FMT_YUV420P16
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo *p)
#define AV_PIX_FMT_GRAY14
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
struct AVS_ScriptEnvironment AVS_ScriptEnvironment
static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pkt, int *discard)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAY10
@ AVDISCARD_ALL
discard all
AVS_ScriptEnvironment * env
#define AV_PIX_FMT_GBRP16
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Rational number (pair of numerator and denominator).
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard)
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo *p)
static av_cold int avisynth_read_header(AVFormatContext *s)
static AviSynthLibrary avs_library
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int sample_rate
Audio only.
static void error(const char *err)
int64_t nb_frames
number of frames in this stream if known or 0
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int discard)
static int avisynth_create_stream(AVFormatContext *s)
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV422P12
AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo *p)
#define AV_PIX_FMT_YUV444P12
const char const char void * val
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
AVSC_INLINE int avs_has_video(const AVS_VideoInfo *p)
const AVSC_INLINE char * avs_as_error(AVS_Value v)
static const int avs_planes_grey[1]
#define AV_PIX_FMT_BGRA64
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_PIX_FMT_GBRP12
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
int id
Format-specific stream ID.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo *p)
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
AVSC_INLINE int avs_is_clip(AVS_Value v)
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_GBRAPF32
Filter the word “frame” indicates either a video frame or a group of audio samples
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
struct AviSynthContext * next
#define flags(name, subs,...)
AVSC_DECLARE_FUNC(avs_bit_blt)
static av_cold int avisynth_context_create(AVFormatContext *s)
#define AV_PIX_FMT_YUV444P14
static int avisynth_open_file(AVFormatContext *s)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
#define AV_PIX_FMT_GRAY12
static const int avs_planes_packed[1]
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
int audio_samples_per_second