28 #define AVSC_NO_DECLSPEC
43 #include <avisynth/avisynth_c.h>
44 #define AVISYNTH_LIB "avisynth"
45 #define USING_AVISYNTH
48 #include <avxsynth/avxsynth_c.h>
49 #if defined (__APPLE__)
50 #define AVISYNTH_LIB "libavxsynth.dylib"
52 #define AVISYNTH_LIB "libavxsynth.so"
55 #define LoadLibrary(x) dlopen(x, RTLD_NOW | RTLD_GLOBAL)
56 #define GetProcAddress dlsym
57 #define FreeLibrary dlclose
62 #define AVSC_DECLARE_FUNC(name) name ## _func name
77 #undef AVSC_DECLARE_FUNC
81 AVS_ScriptEnvironment *
env;
83 const AVS_VideoInfo *
vi;
120 #define LOAD_AVS_FUNC(name, continue_on_fail) \
122 (void *)GetProcAddress(avs_library.library, #name); \
123 if (!continue_on_fail && !avs_library.name) \
162 avs->
env = avs_library.avs_create_script_environment(3);
163 if (avs_library.avs_get_error) {
164 const char *
error = avs_library.avs_get_error(avs->
env);
186 if (avs == avs_ctx_list) {
187 avs_ctx_list = avs->
next;
190 while (prev->
next != avs)
196 avs_library.avs_release_clip(avs->
clip);
200 avs_library.avs_delete_script_environment(avs->
env);
231 avs->
vi->fps_numerator };
233 avs->
vi->fps_denominator };
238 switch (avs->
vi->pixel_type) {
239 #ifdef USING_AVISYNTH
276 "unknown AviSynth colorspace %d\n", avs->
vi->pixel_type);
305 avs->
vi->audio_samples_per_second };
308 switch (avs->
vi->sample_type) {
309 case AVS_SAMPLE_INT8:
312 case AVS_SAMPLE_INT16:
315 case AVS_SAMPLE_INT24:
318 case AVS_SAMPLE_INT32:
321 case AVS_SAMPLE_FLOAT:
326 "unknown AviSynth sample type %d\n", avs->
vi->sample_type);
340 if (avs_has_video(avs->
vi)) {
348 if (avs_has_audio(avs->
vi)) {
364 #ifdef USING_AVISYNTH
365 char filename_ansi[MAX_PATH * 4];
366 wchar_t filename_wc[MAX_PATH * 4];
372 #ifdef USING_AVISYNTH
374 MultiByteToWideChar(CP_UTF8, 0, s->
filename, -1, filename_wc, MAX_PATH * 4);
375 WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
377 arg = avs_new_value_string(filename_ansi);
379 arg = avs_new_value_string(s->
filename);
381 val = avs_library.avs_invoke(avs->
env,
"Import", arg, 0);
382 if (avs_is_error(val)) {
387 if (!avs_is_clip(val)) {
393 avs->
clip = avs_library.avs_take_clip(val, avs->
env);
394 avs->
vi = avs_library.avs_get_video_info(avs->
clip);
396 #ifdef USING_AVISYNTH
401 if (avs_library.avs_get_version(avs->
clip) == 3) {
403 "AviSynth 2.5.8 not supported. Please upgrade to 2.6.\n");
410 avs_library.avs_release_value(val);
444 AVS_VideoFrame *frame;
445 unsigned char *dst_p;
446 const unsigned char *src_p;
447 int n, i, plane, rowsize, planeheight, pitch,
bits;
458 #ifdef USING_AVISYNTH
463 if (avs_is_yv24(avs->
vi))
465 else if (avs_is_yv16(avs->
vi))
467 else if (avs_is_yv411(avs->
vi))
469 else if (avs_is_y8(avs->
vi))
473 bits = avs_bits_per_pixel(avs->
vi);
477 pkt->
size = (((int64_t)avs->
vi->width *
478 (int64_t)avs->
vi->height) * bits) / 8;
490 frame = avs_library.avs_get_frame(avs->
clip, n);
491 error = avs_library.avs_clip_get_error(avs->
clip);
500 for (i = 0; i < avs->
n_planes; i++) {
502 src_p = avs_get_read_ptr_p(frame, plane);
503 pitch = avs_get_pitch_p(frame, plane);
505 rowsize = avs_get_row_size_p(frame, plane);
506 planeheight = avs_get_height_p(frame, plane);
509 if (avs_is_rgb24(avs->
vi) || avs_is_rgb(avs->
vi)) {
510 src_p = src_p + (planeheight - 1) * pitch;
514 avs_library.avs_bit_blt(avs->
env, dst_p, rowsize, src_p, pitch,
515 rowsize, planeheight);
516 dst_p += rowsize * planeheight;
519 avs_library.avs_release_video_frame(frame);
535 fps.
num = avs->
vi->fps_numerator;
536 fps.
den = avs->
vi->fps_denominator;
537 samplerate.
num = avs->
vi->audio_samples_per_second;
540 if (avs_has_video(avs->
vi)) {
566 pkt->
size = avs_bytes_per_channel_sample(avs->
vi) *
567 samples * avs->
vi->nchannels;
579 avs_library.avs_get_audio(avs->
clip, pkt->
data, n, samples);
580 error = avs_library.avs_clip_get_error(avs->
clip);
648 int64_t timestamp,
int flags)
658 avs->
vi->fps_denominator };
659 samplerate = (
AVRational) { avs->
vi->audio_samples_per_second, 1 };
664 if ((timestamp >= avs->
vi->num_frames) ||
665 (timestamp > INT_MAX) ||
669 if (avs_has_audio(avs->
vi))
672 if ((timestamp >= avs->
vi->num_audio_samples) || (timestamp < 0))
675 if (avs_has_video(avs->
vi)) {
static int avs_atexit_called
int avpriv_unlock_avformat(void)
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 AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static const int avs_planes_yuv[3]
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard)
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.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static av_cold int avisynth_read_close(AVFormatContext *s)
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.
#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. ...
void av_log(void *avcl, int level, const char *fmt,...)
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)
AVS_ScriptEnvironment * env
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static AviSynthLibrary avs_library
AVCodecContext * codec
Codec context associated with this stream.
AVSC_DECLARE_FUNC(avs_bit_blt)
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
char filename[1024]
input or output filename
int width
picture width / height.
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
static const int avs_planes_grey[1]
packed RGB 8:8:8, 24bpp, BGRBGR...
static int read_header(FFV1Context *f)
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
static av_cold void avisynth_atexit_handler(void)
enum AVMediaType codec_type
int sample_rate
samples per second
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
#define LOAD_AVS_FUNC(name, continue_on_fail)
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
rational number numerator/denominator
static int avisynth_create_stream(AVFormatContext *s)
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.
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
int64_t start_time
Decoding: pts of the first frame of the stream, 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.
struct AviSynthContext * next
int channels
number of audio channels
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)
static const int avs_planes_packed[1]
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...