29 #define AVSC_NO_DECLSPEC 35 #include <avisynth/avisynth_c.h> 36 #define AVISYNTH_LIB "avisynth" 37 #define USING_AVISYNTH 40 #include <avxsynth/avxsynth_c.h> 41 #define AVISYNTH_NAME "libavxsynth" 42 #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF 44 #define LoadLibrary(x) dlopen(x, RTLD_NOW | RTLD_LOCAL) 45 #define GetProcAddress dlsym 46 #define FreeLibrary dlclose 51 #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) \ 140 #ifdef USING_AVISYNTH 173 avs->
env = avs_library.avs_create_script_environment(3);
174 if (avs_library.avs_get_error) {
175 const char *
error = avs_library.avs_get_error(avs->
env);
197 if (avs == avs_ctx_list) {
198 avs_ctx_list = avs->
next;
201 while (prev->
next != avs)
207 avs_library.avs_release_clip(avs->
clip);
211 avs_library.avs_delete_script_environment(avs->
env);
242 avs->
vi->fps_numerator };
244 avs->
vi->fps_denominator };
249 switch (avs->
vi->pixel_type) {
250 #ifdef USING_AVISYNTH 287 "unknown AviSynth colorspace %d\n", avs->
vi->pixel_type);
316 avs->
vi->audio_samples_per_second };
319 switch (avs->
vi->sample_type) {
320 case AVS_SAMPLE_INT8:
323 case AVS_SAMPLE_INT16:
326 case AVS_SAMPLE_INT24:
329 case AVS_SAMPLE_INT32:
332 case AVS_SAMPLE_FLOAT:
337 "unknown AviSynth sample type %d\n", avs->
vi->sample_type);
351 if (avs_has_video(avs->
vi)) {
359 if (avs_has_audio(avs->
vi)) {
375 #ifdef USING_AVISYNTH 376 char filename_ansi[MAX_PATH * 4];
377 wchar_t filename_wc[MAX_PATH * 4];
383 #ifdef USING_AVISYNTH 385 MultiByteToWideChar(CP_UTF8, 0, s->
filename, -1, filename_wc, MAX_PATH * 4);
386 WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
388 arg = avs_new_value_string(filename_ansi);
390 arg = avs_new_value_string(s->
filename);
392 val = avs_library.avs_invoke(avs->
env,
"Import", arg, 0);
393 if (avs_is_error(val)) {
398 if (!avs_is_clip(val)) {
404 avs->
clip = avs_library.avs_take_clip(val, avs->
env);
405 avs->
vi = avs_library.avs_get_video_info(avs->
clip);
407 #ifdef USING_AVISYNTH 413 if (avs_library.avs_get_version(avs->
clip) < 6) {
415 "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
422 avs_library.avs_release_value(val);
456 AVS_VideoFrame *frame;
457 unsigned char *dst_p;
458 const unsigned char *src_p;
459 int n, i, plane, rowsize, planeheight, pitch,
bits;
470 #ifdef USING_AVISYNTH 475 if (avs_library.avs_is_yv24(avs->
vi))
477 else if (avs_library.avs_is_yv16(avs->
vi))
479 else if (avs_library.avs_is_yv411(avs->
vi))
481 else if (avs_library.avs_is_y8(avs->
vi))
484 bits = avs_library.avs_bits_per_pixel(avs->
vi);
486 bits = avs_bits_per_pixel(avs->
vi);
491 pkt->
size = (((int64_t)avs->
vi->width *
492 (int64_t)avs->
vi->height) * bits) / 8;
504 frame = avs_library.avs_get_frame(avs->
clip, n);
505 error = avs_library.avs_clip_get_error(avs->
clip);
514 for (i = 0; i < avs->
n_planes; i++) {
516 #ifdef USING_AVISYNTH 517 src_p = avs_library.avs_get_read_ptr_p(frame, plane);
518 pitch = avs_library.avs_get_pitch_p(frame, plane);
520 rowsize = avs_library.avs_get_row_size_p(frame, plane);
521 planeheight = avs_library.avs_get_height_p(frame, plane);
523 src_p = avs_get_read_ptr_p(frame, plane);
524 pitch = avs_get_pitch_p(frame, plane);
526 rowsize = avs_get_row_size_p(frame, plane);
527 planeheight = avs_get_height_p(frame, plane);
531 if (avs_is_rgb24(avs->
vi) || avs_is_rgb(avs->
vi)) {
532 src_p = src_p + (planeheight - 1) * pitch;
536 avs_library.avs_bit_blt(avs->
env, dst_p, rowsize, src_p, pitch,
537 rowsize, planeheight);
538 dst_p += rowsize * planeheight;
541 avs_library.avs_release_video_frame(frame);
557 fps.
num = avs->
vi->fps_numerator;
558 fps.
den = avs->
vi->fps_denominator;
559 samplerate.
num = avs->
vi->audio_samples_per_second;
562 if (avs_has_video(avs->
vi)) {
588 pkt->
size = avs_bytes_per_channel_sample(avs->
vi) *
589 samples * avs->
vi->nchannels;
601 avs_library.avs_get_audio(avs->
clip, pkt->
data, n, samples);
602 error = avs_library.avs_clip_get_error(avs->
clip);
670 int64_t timestamp,
int flags)
680 avs->
vi->fps_denominator };
681 samplerate = (
AVRational) { avs->
vi->audio_samples_per_second, 1 };
686 if ((timestamp >= avs->
vi->num_frames) ||
687 (timestamp > INT_MAX) ||
691 if (avs_has_audio(avs->
vi))
694 if ((timestamp >= avs->
vi->num_audio_samples) || (timestamp < 0))
697 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 AVCodecID codec_id
Specific type of the encoded data (the codec used).
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static const int avs_planes_yuv[3]
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.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
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. ...
enum AVMediaType codec_type
General type of the encoded data.
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
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
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)
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.
int sample_rate
Audio only.
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
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)
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...