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 = dlsym(avs_library.library, #name); \
127 if (!continue_on_fail && !avs_library.name) \
144 #ifdef USING_AVISYNTH
175 avs->
env = avs_library.avs_create_script_environment(3);
176 if (avs_library.avs_get_error) {
177 const char *
error = avs_library.avs_get_error(avs->
env);
199 if (avs == avs_ctx_list) {
200 avs_ctx_list = avs->
next;
203 while (prev->
next != avs)
209 avs_library.avs_release_clip(avs->
clip);
213 avs_library.avs_delete_script_environment(avs->
env);
251 #ifdef USING_AVISYNTH
426 "unknown AviSynth colorspace %d\n", avs->
vi->
pixel_type);
432 #ifdef USING_AVISYNTH
435 avs->
planes = avs_planes_rgba;
439 avs->
planes = avs_planes_yuva;
443 avs->
planes = avs_planes_rgb;
527 #ifdef USING_AVISYNTH
528 char filename_ansi[MAX_PATH * 4];
529 wchar_t filename_wc[MAX_PATH * 4];
535 #ifdef USING_AVISYNTH
537 MultiByteToWideChar(CP_UTF8, 0, s->
filename, -1, filename_wc, MAX_PATH * 4);
538 WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
544 val = avs_library.avs_invoke(avs->
env,
"Import", arg, 0);
556 avs->
clip = avs_library.avs_take_clip(val, avs->
env);
557 avs->
vi = avs_library.avs_get_video_info(avs->
clip);
559 #ifdef USING_AVISYNTH
565 if (avs_library.avs_get_version(avs->
clip) < 6) {
567 "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
574 avs_library.avs_release_value(val);
609 unsigned char *dst_p;
610 const unsigned char *src_p;
611 int n, i,
plane, rowsize, planeheight, pitch,
bits;
623 #ifdef USING_AVISYNTH
626 if (GetProcAddress(avs_library.
library,
"avs_is_planar_rgb") ==
NULL)
635 bits = avs_library.avs_bits_per_pixel(avs->
vi);
643 (int64_t)avs->
vi->
height) * bits) / 8;
655 frame = avs_library.avs_get_frame(avs->
clip, n);
656 error = avs_library.avs_clip_get_error(avs->
clip);
665 for (i = 0; i < avs->
n_planes; i++) {
667 #ifdef USING_AVISYNTH
668 src_p = avs_library.avs_get_read_ptr_p(frame, plane);
669 pitch = avs_library.avs_get_pitch_p(frame, plane);
671 rowsize = avs_library.avs_get_row_size_p(frame, plane);
672 planeheight = avs_library.avs_get_height_p(frame, plane);
683 src_p = src_p + (planeheight - 1) * pitch;
687 #ifdef USING_AVISYNTH
689 if (avsplus && (avs_library.avs_is_planar_rgb(avs->
vi) ||
690 avs_library.avs_is_planar_rgba(avs->
vi))) {
691 src_p = src_p + (planeheight - 1) * pitch;
696 avs_library.avs_bit_blt(avs->
env, dst_p, rowsize, src_p, pitch,
697 rowsize, planeheight);
698 dst_p += rowsize * planeheight;
701 avs_library.avs_release_video_frame(frame);
761 avs_library.avs_get_audio(avs->
clip, pkt->
data, n, samples);
762 error = avs_library.avs_clip_get_error(avs->
clip);
830 int64_t timestamp,
int flags)
847 (timestamp > INT_MAX) ||
const char const char void * val
#define AV_PIX_FMT_YUVA422P16
static int avs_atexit_called
int avpriv_unlock_avformat(void)
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA422P10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_YUV420P12
Macro definitions for various function/variable attributes.
static const int avs_planes_yuv[3]
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int id
Format-specific stream ID.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo *p)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUVA420P16
static av_cold int avisynth_read_close(AVFormatContext *s)
AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame *p, int plane)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_F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t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=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
#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_PIX_FMT_YUVA444P16
enum AVMediaType codec_type
General type of the encoded data.
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo *p)
#define AV_PIX_FMT_GBRAP12
AVSC_INLINE int avs_has_video(const AVS_VideoInfo *p)
#define AV_PIX_FMT_YUV444P10
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int discard)
AVInputFormat ff_avisynth_demuxer
AVRational avg_frame_rate
Average framerate.
int avpriv_lock_avformat(void)
#define AV_PIX_FMT_GBRAP16
AVS_ScriptEnvironment * env
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static AviSynthLibrary avs_library
AVSC_DECLARE_FUNC(avs_bit_blt)
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
common internal API header
AVSC_INLINE int avs_is_clip(AVS_Value v)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
#define AV_PIX_FMT_GBRP16
char filename[1024]
input or output filename
#define AV_PIX_FMT_GRAY16
AVSC_INLINE AVS_Value avs_new_value_string(const char *v0)
AVSC_INLINE const char * avs_as_error(AVS_Value v)
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
static const int avs_planes_grey[1]
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_GBRP14
static void error(const char *err)
static int read_header(FFV1Context *f)
AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo *p)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define AV_PIX_FMT_YUV420P16
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
static av_cold void avisynth_atexit_handler(void)
#define AV_PIX_FMT_YUV420P14
AVSC_INLINE const unsigned char * avs_get_read_ptr_p(const AVS_VideoFrame *p, int plane)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVSC_INLINE int avs_is_error(AVS_Value v)
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
#define LOAD_AVS_FUNC(name, continue_on_fail)
#define AV_PIX_FMT_YUV420P10
Rational number (pair of numerator and denominator).
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo *p)
static int avisynth_create_stream(AVFormatContext *s)
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
static int avisynth_open_file(AVFormatContext *s)
static av_cold int avisynth_load_library(void)
int64_t duration
Decoding: duration of the stream, in stream time base.
int sample_rate
Audio only.
struct AVS_ScriptEnvironment AVS_ScriptEnvironment
static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static AviSynthContext * avs_ctx_list
planar GBRA 4:4:4:4 32bpp
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int64_t nb_frames
number of frames in this stream if known or 0
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame *p, int plane)
struct AviSynthContext * next
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static av_cold int avisynth_context_create(AVFormatContext *s)
AVCodecParameters * codecpar
static const int avs_planes_packed[1]
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame *p, int plane)
static av_cold int avisynth_read_header(AVFormatContext *s)
This structure stores compressed data.
static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pkt, int *discard)
#define AV_PIX_FMT_YUV422P16
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo *p)
int audio_samples_per_second