Comments (7)
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.
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.
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.
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.
....and I've pretty much reimplemented the backend in Python. Just a couple classes left.
from pysubs2.
I Would like this function too, i have many problem wiith this too
from pysubs2.
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)
- Correction ms_to_frames/frames_to_ms/ms_to_str HOT 21
- Possible integration point with openai/whisper output HOT 4
- Support for Graphics section HOT 3
- [QA] DeprecationWarning in tests: 'alignment' attribute should be an Alignment instance
- SRT to ASS conversion cap at 10h timecode HOT 2
- tutorial.rst has a spelling issue in line 60 HOT 1
- [Feature Request] Handle WebVtt cue settings HOT 2
- Error: Framerate must be specified when writing MicroDVD. HOT 1
- ASS to SRT/WebVTT cue ordering HOT 2
- Is there a way to add braces to the SRT file? HOT 4
- microdvd parser should read fps only from first line with {1}{1} prefix HOT 11
- Python inline convert sup to srt HOT 3
- Support for OpenAI Whisper transcription from CLI HOT 2
- remove misc. events problem. HOT 1
- 4 tests fail because of the missing file subtitle_with_attached_fonts_no_events.ass HOT 1
- Incorrect time after the shift
- add format sami = smi
- Suggestion: display the help message when pysubs2 is run from CLI without any arguments HOT 2
- Timestamp rounding error results in incorrect timestamp and overlapping lines HOT 2
- UnknownFileExtensionError not properly raised upon loading a file with unsupported format HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysubs2.