GithubHelp home page GithubHelp logo

Comments (7)

tkarabela avatar tkarabela commented on May 28, 2024

Would something like this help? :)

def resize_subs(subs, res_x_dest=1920):
	res_x_src = int(subs.info["PlayResX"])
	res_y_src = int(subs.info["PlayResY"])
	scale = res_x_dest / float(res_x_src)
	res_y_dest = int(scale * res_y_src)

	# metadata
	subs.info["PlayResX"] = str(res_x_dest)
	subs.info["PlayResY"] = str(res_y_dest)

	# styles
	for style in subs.styles.values():
		style.fontsize *= scale
		style.marginl *= scale
		style.marginr *= scale
		style.marginv *= scale
		style.outline *= scale
		style.shadow *= scale
		style.spacing *= scale

	# events
	# XXX

If you have override tags in individual subtitles, fixing those would be more tricky, though perhaps fixing \pos and \fs via regular expressions would be good enough? pysubs2 does not really have a good way of working with override tags, apart from pysubs2.substation.parse_tags().

Aegisub's resolution resampler is implemented in C++ ( https://github.com/Aegisub/Aegisub/blob/ce658d070925effea8c626b2ada2f819d01ab4fb/src/resolution_resampler.cpp ) and is not exposed in its Lua API, as far as i can tell ( http://docs.aegisub.org/3.2/Automation/ ).

from pysubs2.

knaik95 avatar knaik95 commented on May 28, 2024

Yeah that's more or less what I have. It's the individual subtitle tags that I'm having an issue with. I can set up the regex but I have to find all the tags I have to scale. So far I just have \pos being scaled up. The sample .ass file I'm using has sparkles that are supposed to be behind the song lyrics (karaoke) but after scaling \pos, the sparkles stay where they were.

The tags look like this: \fad(1000,0)\an5\pos(381,35\fscx100\fscy100).

I'm not really sure what the \fad, \an, \fscx, and \fscy even do so I don't know if they need scaling and/or what to scale them by.

There are also \move tags in other subtitles. I scaled those up and the text got stretched. \move has 4 parameters. Do I scale every other one?

I downloaded the aegisub source code from the github and want to send the needed parameters to resolution_resampler.cpp to scale everything before running the main script but can't get C++ (clang) to work with VSCode.

from pysubs2.

tkarabela avatar tkarabela commented on May 28, 2024

Aegisub docs have a list of ASS override tags and their parameters: http://docs.aegisub.org/manual/ASS_Tags

You should scale everything which is given in pixels: font size and spacing, outline, shadow, margins, \pos, \org, first four parameters of \move, and coordinates for vector drawing stuff (\p) if you have that, too. At that point, it may be more simple to do the resizing the other way around, keeping the effects as they are.

If I remember correctly, the resolution given in ASS info section is virtual, anyway; during playback, the renderer rasterizes it depending on the actual video resolution (with some supersampling, 2x or 4x I think). So even if you have 640x480 ASS subtitles, they should not look blocky with full HD video. At least that was my experience with MPC-HC some years back.

The C++ code I linked more for reference, it would most likely be faster to reimplement it from scratch in Python than frankenstein the backend of a monolithic C++ app to do something useful :)

from pysubs2.

knaik95 avatar knaik95 commented on May 28, 2024

The issue I'm facing is that one .ass file is 720p and another is 1080p, so when I bring the styles and subs from 720 into 1080, all the 720 ones are drawn in a 1080 window, meaning they're essentially in their own little 720p layer on top of the already present 1080p subs.

Re-implementing the C++ in Python requires knowing the C++ syntax :(

Most of the syntax is easy enough but other parts are a bit confusing. For example:

enum class YCbCrMatrix : int {
	rgb,
	tv_601,
	pc_601,
	tv_709,
	pc_709,
	tv_fcc,
	pc_fcc,
	tv_240m,
	pc_240m
};

What does the : int in the first line mean?

from pysubs2.

knaik95 avatar knaik95 commented on May 28, 2024

....and I've pretty much reimplemented the backend in Python. Just a couple classes left.

from pysubs2.

fagnerpatricio avatar fagnerpatricio commented on May 28, 2024

I Would like this function too, i have many problem wiith this too

from pysubs2.

tkarabela avatar tkarabela commented on May 28, 2024

If anyone wants to implement this, please feel free to open a pull request. Sketch of the implementation is in #29 (comment) but it would also need to support \pos tags, drawing tags, etc. It should be a new method of SSAFile.

from pysubs2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.