28 #include <VapourSynth.h>
62 #define OFFSET(x) offsetof(VSContext, x)
63 #define A AV_OPT_FLAG_AUDIO_PARAM
64 #define D AV_OPT_FLAG_DECODING_PARAM
66 {
"max_script_size",
"set max file size supported (in bytes)",
OFFSET(max_script_size),
AV_OPT_TYPE_INT64, {.i64 = 1 * 1024 * 1024}, 0, SIZE_MAX - 1,
A|
D},
75 vsscript_freeScript(vss->
vss);
108 static const int yuv_order[4] = {0, 1, 2, 0};
109 static const int rgb_order[4] = {1, 2, 0, 0};
113 int is_rgb, is_yuv, i;
127 is_rgb = vsf->colorFamily == cmRGB;
131 is_yuv = vsf->colorFamily == cmYUV ||
132 vsf->colorFamily == cmYCoCg ||
133 vsf->colorFamily == cmGray;
134 if (!is_rgb && !is_yuv)
143 if (strncmp(pd->
name,
"xyz", 3) == 0)
149 order = is_yuv ? yuv_order : rgb_order;
153 if (order[c->
plane] != i ||
155 c->
step != vsf->bytesPerSample ||
156 c->
depth != vsf->bitsPerSample)
161 memcpy(c_order, order,
sizeof(
int[4]));
178 const VSVideoInfo *info;
195 if (!vsscript_init()) {
196 av_log(s,
AV_LOG_ERROR,
"Failed to initialize VSScript (possibly PYTHONPATH not set).\n");
201 if (vsscript_createScript(&vss_state->
vss)) {
230 "value %"PRIi64
", consider increasing the max_script_size option\n",
237 if (vsscript_evaluateScript(&vss_state->
vss, buf, s->
url, 0)) {
238 const char *msg = vsscript_getError(vss_state->
vss);
244 vs->
vsapi = vsscript_getVSApi();
245 vs->
vscore = vsscript_getCore(vss_state->
vss);
247 vs->
outnode = vsscript_getOutput(vss_state->
vss, 0);
262 if (!info->format || !info->width || !info->height) {
292 if (info->format->colorFamily == cmYCoCg)
315 res = vs->
vsapi->propGetInt(map, name, 0, &err);
316 return err || res < INT_MIN || res > INT_MAX ? def : res;
343 const VSFrameRef *vsframe;
344 const VSVideoInfo *info = vs->
vsapi->getVideoInfo(vs->
outnode);
377 ref_data->
frame = vsframe;
385 props = vs->
vsapi->getFramePropsRO(vsframe);
414 for (i = 0; i < info->format->numPlanes; i++) {
416 ptrdiff_t plane_h = frame->
height;
418 frame->
data[i] = (
void *)vs->
vsapi->getReadPtr(vsframe, p);
422 if (!frame->
buf[i]) {
431 if (i == 1 || i == 2)
487 .
name =
"vapoursynth",
495 .priv_class = &class_vs,
int plane
Which of the 4 planes contains the component.
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define LIBAVUTIL_VERSION_INT
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static const AVClass class_vs
static av_cold int read_header_vs(AVFormatContext *s)
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).
const char * av_default_item_name(void *ptr)
Return the context name.
static av_cold enum AVPixelFormat match_pixfmt(const VSFormat *vsf, int c_order[4])
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void free_vss_state(void *opaque, uint8_t *data)
int ctx_flags
Flags signalling stream properties.
enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt)
Utility function to swap the endianness of a pixel format.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
enum AVColorSpace color_space
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int get_vs_prop_int(AVFormatContext *s, const VSMap *map, const char *name, int def)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
static av_cold int end(AVCodecContext *avctx)
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
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)
#define AV_LOG_VERBOSE
Detailed information.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_seek_vs(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
static void free_vsframe_ref(void *opaque, uint8_t *data)
static void free_frame(void *opaque, uint8_t *data)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
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. ...
char * url
input or output URL.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVMediaType codec_type
General type of the encoded data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
enum AVColorSpace colorspace
YUV colorspace type.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
simple assert() macros that are a bit more flexible than ISO C assert().
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int flags
A combination of AV_PKT_FLAG values.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
uint8_t nb_components
The number of components each pixel has, (1-4)
#define AV_TIME_BASE
Internal time base represented as integer.
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
static av_cold int probe_vs(AVProbeData *p)
static av_cold int is_native_endian(enum AVPixelFormat pixfmt)
Passthrough codec, AVFrames wrapped in AVPacket.
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
the normal 2^n-1 "JPEG" YUV ranges
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const AVOption options[]
static int read_packet_vs(AVFormatContext *s, AVPacket *pkt)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVIOContext * pb
I/O context.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t * data
The data buffer.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Describe the class of an AVClass context structure.
AVInputFormat ff_vapoursynth_demuxer
const VDPAUPixFmtMap * map
This structure contains the data a format has to probe a file.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
int shift
Number of least significant bits that must be shifted away to get the value.
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
int size
Size of data in bytes.
int offset
Number of elements before the component of the first pixel.
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_cold int read_close_vs(AVFormatContext *s)
int64_t duration
Decoding: duration of the stream, in stream time base.
A reference to a data buffer.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
void * priv_data
Format private data.
enum AVPixelFormat pixfmt
enum AVColorPrimaries color_primaries
enum AVColorTransferCharacteristic color_trc
AVCodecParameters * codecpar
Codec parameters associated with this stream.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
int depth
Number of bits in the component.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int step
Number of elements between 2 horizontally consecutive pixels.
simple arithmetic expression evaluator
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
#define AV_CEIL_RSHIFT(a, b)