aidanholm / mpv-easycrop

A simple mpv script for manually cropping videos with ease.
73 stars 6 forks source link

doesn't crop the right region #5

Closed ghost closed 8 years ago

ghost commented 8 years ago

I press "c" click top left click bottom right and I get a totally different region of the video cropped to (top left of the video)

bug in action: https://my.mixtape.moe/vmqkzy.webm

aidanholm commented 8 years ago

I can't reproduce this, so I'll need more information to debug:

Are there any error messages in the mpv log? After clicking top-left, there should be a clear region in the grey square indicating the region to crop to, so it's possible some intermediate error is causing this issue.

Does this issue occur with all video files? Are you using mpv directly, or are you using a wrapper GUI?

ghost commented 8 years ago

using MPV, no wrapper. log: https://i.imgur.com/dPgSZbK.png

I don't see any clear box. still crops to wrong area.

happens with MP4, not webm

aidanholm commented 8 years ago

The crop filter is being added with the correct region (the Opening video filter: [crop ...] lines). The problem appears to be the image format d3d11_nv12 and the use of hardware decoding (the d3d11va line). mpv automatically moves the crop origin to 0/0 if the image format has hardware decoding (yellow log lines). So the cropped region has the correct width and height, it's just been moved over into the top-left corner.

Could you confirm whether hardware decoding is in use for a video where cropping works properly?

ghost commented 8 years ago

log of video where the crop works: (webm format) https://i.imgur.com/eAd2ote.png

aidanholm commented 8 years ago

Yeah, that seems to be the problem then; here you're using software decoding (image format yuv420p), and the crop origin is only adjusted to the nearest even number. I'm not sure if there's any other way to fix this, apart from disabling hardware decoding :/

It may be possible to toggle hardware/software decoding as cropping is enabled/disabled. That'd at least be better than cropping to the wrong region or permanently disabling hwdec, even if it's less than ideal.

ghost commented 8 years ago

setting "hwdec=no", makes the crop work on the first (MP4) video where it wouldn't work previously. https://i.imgur.com/8faiIFd.png

but this is not a great solution, as it means I'd have to permanently disable hardware decoding

ghost commented 8 years ago

there should be a reason why the region gets reset on hardware decoding

aidanholm commented 8 years ago

It's possible/likely that the hardware is designed to decode entire pictures at a time, and that the driver APIs are limited in turn. Decoding a region of a video picture often needs pixel information from outside that region. I'm surprised that this isn't emulated at a software level, however, since it'd be trivial to do in a shader.

ghost commented 8 years ago

same issue using this script for auto cropping off black bars: https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autocrop.lua

that one also doesn't work with hardware decoding https://i.imgur.com/ZITztqK.png

aidanholm commented 8 years ago

I've added a check at 4a5d8a1 for whether hwdec without copy-back is in use, currently with a whitelist (ugh)---if cropping can't work, it'll notify with an OSD message.