-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
microdvd parser should read fps only from first line with {1}{1} prefix #71
Comments
Hi @milahu, can you tell me what you wish the library did instead of raising If you want to assume a "default fps", you can do this already: try:
subs = pysubs2.SSAFile.from_string(text, format_="microdvd")
except pysubs2.exceptions.UnknownFPSError:
subs = pysubs2.SSAFile.from_string(text, format_="microdvd", fps=25) However, unless both the input and output format is MicroDVD, this will mess up timing for any subtitles that are not the assumed default (eg. 25 fps) and do not have the declaration in the first subtitle. |
|
The library internally works with milliseconds, not frames - specifying framerate is not optional when reading MicroDVD.
I'm not sure what more the library could be doing to figure out what framerate should be used. The only other option I see is to supply a default framerate in case the autodetection fails, which is already possible via the code I suggested earlier: try:
subs = pysubs2.SSAFile.from_string(text, format_="microdvd")
except pysubs2.exceptions.UnknownFPSError:
subs = pysubs2.SSAFile.from_string(text, format_="microdvd", fps=25) Maybe I'm misunderstanding the issue, feel free to tell me more about the use-case where this is a problem :) |
the parser should be more strict it should parse the FPS only from first lines like
but NOT from first lines like
sorry, my issue title was misleading |
Ah, maybe I'm beginning to understand, let's go back to your initial examples. Example 1 import pysubs2
text = """\
{10}{20}666
"""
subs = pysubs2.SSAFile.from_string(text, format_="microdvd")
# raises pysubs2.exceptions.UnknownFPSError: Framerate was not specified and cannot be read from the MicroDVD file. Example 2 text = """\
{10}{20}asdf
"""
subs = pysubs2.SSAFile.from_string(text, format_="microdvd")
# raises pysubs2.exceptions.UnknownFPSError: Framerate was not specified and cannot be read from the MicroDVD file. |
BTW, this is the relevant code: Lines 22 to 46 in f83b818
|
yes |
VLC also only parse the fps when it has this format: "{1}{1}THE_FPS" |
Thanks, I see! I will implement this. |
trivial... --- a/pysubs2/microdvd.py
+++ b/pysubs2/microdvd.py
@@ -34,6 +34,12 @@ class MicroDVDFormat(FormatBase):
# We don't know the framerate, but it is customary to include
# it as text of the first subtitle. In that case, we skip
# this auxiliary subtitle and proceed with reading.
+ if fstart != 1 or fend != 1:
+ # the first subtitle must have this format for fps=25:
+ # {1}{1}25
+ raise UnknownFPSError("Framerate was not specified and "
+ "cannot be read from "
+ "the MicroDVD file.")
try:
fps = float(text)
subs.fps = fps |
- Saving MicroDVD with `write_fps_declaration=True` (default) creates subtitle {1}{1}<fps>, not {0}{0}<fps>. - Reading MicroDVD with `strict_fps_inference=True` (default) will raise UnknownFPSError if fps is not given and the first subtitle does not have the format {1}{1}<fps>. Fixes issue #71.
Fixed in version 1.7.0. |
frame rate should be parsed from the first line
only when the first line has the format
examples
failing tests
downstream issue smacke/ffsubsync#176
The text was updated successfully, but these errors were encountered: