1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

vf_vapoursynth: factor stuff

This commit is contained in:
wm4 2014-10-11 18:16:09 +02:00
parent 54e2ca809c
commit 46b16cf206

View File

@ -114,8 +114,8 @@ static int mp_from_vs(VSPresetFormat vs)
return pfNone; return pfNone;
} }
static void copy_mp_to_vs_frame_props(struct vf_priv_s *p, VSMap *map, static void copy_mp_to_vs_frame_props_map(struct vf_priv_s *p, VSMap *map,
struct mp_image *img) struct mp_image *img)
{ {
struct mp_image_params *params = &img->params; struct mp_image_params *params = &img->params;
if (params->d_w > 0 && params->d_h > 0) { if (params->d_w > 0 && params->d_h > 0) {
@ -151,6 +151,25 @@ static void copy_mp_to_vs_frame_props(struct vf_priv_s *p, VSMap *map,
!!(img->fields & MP_IMGFIELD_TOP_FIRST), 0); !!(img->fields & MP_IMGFIELD_TOP_FIRST), 0);
} }
static int set_vs_frame_props(struct vf_priv_s *p, VSFrameRef *frame,
struct mp_image *img, int dur_num, int dur_den)
{
VSMap *map = p->vsapi->getFramePropsRW(frame);
if (!map)
return -1;
p->vsapi->propSetInt(map, "_DurationNum", dur_num, 0);
p->vsapi->propSetInt(map, "_DurationDen", dur_den, 0);
copy_mp_to_vs_frame_props_map(p, map, img);
return 0;
}
static VSFrameRef *alloc_vs_frame(struct vf_priv_s *p, struct mp_image_params *fmt)
{
const VSFormat *vsfmt =
p->vsapi->getFormatPreset(mp_to_vs(fmt->imgfmt), p->vscore);
return p->vsapi->newVideoFrame(vsfmt, fmt->w, fmt->h, NULL, p->vscore);
}
static struct mp_image map_vs_frame(struct vf_priv_s *p, const VSFrameRef *ref, static struct mp_image map_vs_frame(struct vf_priv_s *p, const VSFrameRef *ref,
bool w) bool w)
{ {
@ -406,23 +425,16 @@ static const VSFrameRef *VS_CC infiltGetFrame(int frameno, int activationReason,
} }
if (frameno < p->in_frameno + p->num_buffered) { if (frameno < p->in_frameno + p->num_buffered) {
struct mp_image *img = p->buffered[frameno - p->in_frameno]; struct mp_image *img = p->buffered[frameno - p->in_frameno];
const VSFormat *vsfmt = ret = alloc_vs_frame(p, &img->params);
vsapi->getFormatPreset(mp_to_vs(img->imgfmt), core);
ret = vsapi->newVideoFrame(vsfmt, img->w, img->h, NULL, core);
if (!ret) { if (!ret) {
p->vsapi->setFilterError("Could not allocate VS frame", frameCtx); p->vsapi->setFilterError("Could not allocate VS frame", frameCtx);
break; break;
} }
struct mp_image vsframe = map_vs_frame(p, ret, true); struct mp_image vsframe = map_vs_frame(p, ret, true);
mp_image_copy(&vsframe, img); mp_image_copy(&vsframe, img);
VSMap *map = p->vsapi->getFramePropsRW(ret); int res = 1e6;
if (map) { int dur = img->pts * res + 0.5;
int res = 1e6; set_vs_frame_props(p, ret, img, dur, res);
int dur = img->pts * res + 0.5;
p->vsapi->propSetInt(map, "_DurationNum", dur, 0);
p->vsapi->propSetInt(map, "_DurationDen", res, 0);
copy_mp_to_vs_frame_props(p, map, img);
}
break; break;
} }
pthread_cond_wait(&p->wakeup, &p->lock); pthread_cond_wait(&p->wakeup, &p->lock);