Dudemanguy / mpv-manga-reader

Manga reading script for mpv
GNU General Public License v3.0
119 stars 4 forks source link

Continuous reading mode #1

Closed Waiifu closed 4 years ago

Waiifu commented 4 years ago

Hey, I was wondering what your thoughts on a continuous reading mode would be? I'm not very knowledgeable on mpv's Lua API, but I would imagine if there was some way to detect/calculate the video-pan Y location, you could append a couple pages ahead with a worker, then switch to an image that has a couple pages ahead appended vertically (and set video-pan to an appropriate spot), hopefully smoothly enough so that it doesn't seem noticeable when it makes the switch?

Or are there no mpv functions with which you could keep track of video-pan / set it?

Does any of this seem viably realistic?

Dudemanguy commented 4 years ago

Are you requesting pages be appended vertically and with the ability to scroll down via the pan function? It actually doesn't sound totally impossible but it would be tricky.

Waiifu commented 4 years ago

Yup! That's pretty much the idea. The lack of a continuous mode is something I nowadays deem pretty necessary for myself to read manga. The thing is, with mpv if this was possible, there's a lot of really cool stuff that could be pulled off additionally, that I don't realistically see with any other program. Such as using shader's to upscale manga pages real-time, or even possibly using a worker to Waifu2x super-scale the pages after (or before) stitching them together.

As for it being tricky, yeah I agree. But assuming pan's location can be programmatically handled, I do think it's pretty viable. If the loading of a new image would be too slow/not smooth enough with the loadfile function, I would imagine it could be loaded into cache first to make the transition hopefully pretty un-noticable.

Dudemanguy commented 4 years ago

With a combination of zoom + pan (I might have to do a PR for mpv to make those exposable properties), this should be mostly reasonable. The biggest problem, like you said, is how to handle loading new images. I'm not so sure about trying to use cache here. Assuming someone is using multiple threads for stitching pages + an entire volume of manga (~200 pages or so) + high quality scans, bad things will likely happen.

There's probably not a way around it, but the biggest drawback to this feature is that mpv would have to reload multiple times during usage (when we want to pan to a page that's farther beyond what's currently loaded). Assuming I can save the zoom+pan position before the reload, it should be possible to reload in exactly the same spot and everything. I'm just not sure how annoying/slow/etc. this would be.

This isn't a bad idea though. The more I think about it; the more I like it. And you're right, it's pretty nice reading manga with FSCRNNX or whatever fancy shader which is basically only possible with mpv.

Waiifu commented 4 years ago

So I decided to try the sluggishness of transitioning such large images, and it seems it is practically instantaneous, at least for me, and smooth.

I did the test by stitching 4 2250x3200px images into one, then copying it four times and blurring one of them. Opening all on mpv and panning down while switching files. Each 4 page stitch was 2250x12800. This is with a very mediocre CPU and GTX 1060, so I don't imagine other systems should perform much worse in general.

Here's a short clip of the test: https://streamable.com/mggxn

Dudemanguy commented 4 years ago

Well that's not quite what I meant. Image you have an entire volume of manga. Obviously this can't be all stitched together at once, that would take forever and probably eat up all your RAM. So there has to be logic that stitches new pages together as you scroll (and also cuts off some of the older pages because we can't be loading massive 40000p+ images). Double page mode works OK but it's kind of slow (just flip through pages really fast) because you're bottlenecked by the I/O (imagemagick). The same thing would happen here except even worse since the sizes of the images would be quite larger.

It's not undoable though and I'll probably add it anyway for shits and giggles, but the experience might not be very smooth.

Waiifu commented 4 years ago

Right, wouldn't that sort of be where a worker thread that keeps stitching X amount of pages ahead make it pretty smooth?

So assume when you initially start, it stitches 4 pages, then a worker stitches another 4 (into say, tmp) ahead of time, and once you're nearing the bottom of the current image, it swaps onto the next set (with loadfile), where say, the first page is the same as the last page of the previous image, then just have pan automatically be thrown to where it would've been on the last page, but on the first page. Then assuming this logic can be made to work, the swapping of image files should be pretty seamless, I'd imagine.

Although yeah I understand that switching between pages extremely quickly would be pretty impossible. But maybe resuming a manga/getting to a specific page could be done with inputting the page number? Using a input pop-up something akin to what seek-to.lua uses for example. Although obviously implementing all this would be a fair bit more effort.

Dudemanguy commented 4 years ago

Alrighty, I conjured up a continuous reading mode in dcc19ba. It's not totally perfect, but I tried to make it calculate a good zoom level, detect when the pan value gets large enough to switch pages and all that. Seems okayish to me anyway and worth pushing. Feel free to open up a new issue if you spot any problems (very likely) or something.