Commit Graph

19 Commits

Author SHA1 Message Date
wm4 6fcb34d887 vf_vapoursynth: reset error state on seeking
When seeking, we violently destroy the filter, because vapoursynth has
no proper API for terminating a video with unknown frame count. This
looks like an error to vapoursynth, and the error is returned via the
frame callbacks. The bug is that we remember this error state across
reinitialization, so on the first filter call after reinitialization, we
thought filtering the current frame failed. This caused a shift by 1
frame on each seek.

CC: @mpv-player/stable
2014-07-05 17:07:16 +02:00
wm4 72aac9ae8a video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)

But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.

Functions whose return values changed semantics:

  mp_image_alloc
  mp_image_new_copy
  mp_image_new_ref
  mp_image_make_writeable
  mp_image_setrefp
  mp_image_to_av_frame_and_unref
  mp_image_from_av_frame
  mp_image_new_external_ref
  mp_image_new_custom_ref
  mp_image_pool_make_writeable
  mp_image_pool_get
  mp_image_pool_new_copy
  mp_vdpau_mixed_frame_create
  vf_alloc_out_image
  vf_make_out_image_writeable
  glGetWindowScreenshot
2014-06-17 22:43:43 +02:00
wm4 0128579542 vf_vapoursynth: fix debug output 2014-05-15 16:59:26 +02:00
wm4 97604ebcd2 vf_vapoursynth: add more debug output
Also, move num_requested() to where it's used. Remove newlines from VS
error messages. Remove an assert(0) on an error path.
2014-05-15 14:50:35 +02:00
wm4 daf4898668 vf_vapoursynth: avoid unnecessary waiting
It could in theory happen that the filter loop will enter a blocking
wait, even though it could make progress by emptying the list of
already-filtered images. I'm not quite sure if this could actually cause
a real issue - probably not.
2014-05-14 21:02:56 +02:00
wm4 bc6959c35d vf_vapoursynth: allow parallel processing
VapourSynth won't just filter multiple frames at once on its own. You
have to request multiple frames at once manually. This is what this
commit introduces: a sub-option controls how many frames will be
requested at once. This also changes the semantics of the maxbuffer sub-
option, now renamed to buffered-frames.
2014-05-14 20:42:04 +02:00
wm4 bc07c86da5 vf_vapoursynth: fix aspect ratio passed to vapoursynth
This was recently either changed or clarified in vapoursynth.

Pass the aspect ratio as pixel aspect to VS.
2014-05-03 15:17:13 +02:00
wm4 48587e88e0 vf_vapoursynth: add more VS frame properties
We only support them for input. The frame properties of output frames
are ignored (except frame durations).

Properties not set for now: _ChromaLocation, _Field, _FieldBased
2014-04-28 23:44:57 +02:00
wm4 6b0b8368a4 vf_vapoursynth: use frame durations instead of _AbsoluteTime
Set _DurationNum/_DurationDen on each VS frame, instead of
_AbsoluteTime. The duration is the difference between the timestamp of
the frame and the next frame, and when receiving filtered VS frames, we
convert them back to an absolute PTS by summing them.

We pass the timestamps with microsecond resolution. mpv uses double for
timestamps internally, so we don't know the "real" timebase or FPS. VS
on the other hand uses fractions for frame durations. We can't pass
through the numbers exactly, but microseconds ought to be enough to be
even safe from accumulating rounding errors.
2014-04-28 22:23:32 +02:00
wm4 062d5eea3b vf_vapoursynth: fix memory leak on error
Since this leaks video images, and the player keeps feeding new images
to the fitler even if it fails, this would probably have disastrous
consequences.
2014-04-28 22:23:32 +02:00
wm4 dffb7c2409 vf_vapoursynth: remove incorrect copyright notice
This file merely started out by copy&pasting vf_lavfi.c and removing
everything to have a basic skeleton.
2014-04-28 22:23:32 +02:00
wm4 42f65ce108 video: don't drop last frame when deinterlacing with yadif
Or in other words, add support for properly draining remaining frames
from video filters. vf_yadif is buffering at least one frame, and the
buffered frame was not retrieved on EOF.

For most filters, ignore this for now, and just adjust them to the
changed semantics of filter_ext. But for vf_lavfi (used by vf_yadif),
real support is implemented. libavfilter handles this simply by passing
a NULL frame to av_buffersrc_add_frame(), so we just have to make
mp_to_av() handle NULL arguments.

In load_next_vo_frame(), we first try to output a frame buffered in the
VO, then the filter, and then (if EOF is reached and there's still no
new frame) the VO again, with draining enabled. I guess this was
implemented slightly incorrectly before, because the filter chain still
could have had remaining output frames.
2014-04-28 22:23:31 +02:00
wm4 b20416abe3 vf_vapoursynth: use official AbsoluteTime property
I thought the "_" in "_AbsoluteTime" was part of the documentation
markup.

This still doesn't help us with VS filters that change timing;
apparently you must use frame durations instead.
2014-04-27 22:16:56 +02:00
wm4 9e47bd11cc vf_vapoursynth: keep pixel aspect ratio
Make the filter apply the pixel aspect ratio of the input to the output.
This is more useful than forcing 1:1 PAR when playing anamorphic video
such as DVDs.

VapourSynth itself actually allows passing through the aspect ratio, but
it's in a not very useful form for us: it's per video-frame instead of
constant (i.e in VSVideoInfo). As long as we don't have a way to allow a
filter to spontaneously change output parameters, we can't use this.
(And I don't really feel like making this possible.)
2014-04-27 17:05:26 +02:00
wm4 e1f1b0c275 vf_vapoursynth: handle destruction more gracefully
We were relying on vsscript_freeScript() to take care of proper
termination. But it doesn't do that: it doesn't wait for the filters to
finish and exit at all. Instead, it just destroys all objects, which
causes the worker threads to crash sometimes.

Also, we're supposed to wait for the frame callback to finish before
freeing the associated node.

Handle this by explicitly waiting as far as we can. Probably fixes
crashes on seeking, although VapourSynth itself might also need some
work to make this case completely stable.
2014-04-14 20:51:27 +02:00
wm4 7178257bb6 vf_vapoursynth: wipe vapoursynth state completely on reloading
Before this commit, the filter attempted to keep the vsscript state
(p->se) even when the script was reloaded. Change it to destroy the
script state too on reloading. Now no workaround for LoadPlugin is
necessary, and this also fixes a weird theoretical race condition when
destroying and recreating the mpv source filter.
2014-04-14 18:03:13 +02:00
wm4 7ded55f667 vf_vapoursynth: print an error if VapourSynth returns an unknown format
Apparently there is no real format negotiation, so this can actually
happen.
2014-04-13 12:30:57 +02:00
wm4 8161f4374c vf_vapoursynth: error out early if the file sub-option is not set
Instead of crashing by possibly passing a NULL pointer to VapourSynth.
2014-04-13 12:29:40 +02:00
wm4 33f822b715 video: add VapourSynth filter bridge
Mainly meant to apply simple VapourSynth filters to video at runtime.
This has various restrictions, which are listed in the manpage.

Additionally, this actually copies video frames when converting frame
references from mpv to VapourSynth, and a second time when going from
VapourSynth to mpv. This is inefficient and could probably be easily
improved. But for now, this is simpler, and in fact I'm not sure if
we even can references VapourSynth frames after the core has been
destroyed.
2014-04-12 19:31:50 +02:00