Comments (9)
While pysubs2
has no particular support for WebVTT format at this time, the format is sufficiently similar to SRT that in simple cases, pysubs2
will read it just fine. If you just want to collect subtitles from multiple files without any retiming, that would be:
import pysubs2
input_files = [
"subtitle_V1-0.webvtt",
"subtitle_V1-1.webvtt",
"subtitle_V1-2.webvtt",
"subtitle_V1-3.webvtt",
]
output_subs = pysubs2.SSAFile()
for file in input_files:
subs = pysubs2.load(file)
output_subs.events.extend(subs.events)
output_subs.save("subtitle.srt")
from pysubs2.
While
pysubs2
has no particular support for WebVTT format at this time, the format is sufficiently similar to SRT that in simple cases,pysubs2
will read it just fine. If you just want to collect subtitles from multiple files without any retiming, that would be:import pysubs2 input_files = [ "subtitle_V1-0.webvtt", "subtitle_V1-1.webvtt", "subtitle_V1-2.webvtt", "subtitle_V1-3.webvtt", ] output_subs = pysubs2.SSAFile() for file in input_files: subs = pysubs2.load(file) output_subs.events.extend(subs.events) output_subs.save("subtitle.srt")
Thanks a lote
This way works for me
from pysubs2.
Hey
I tryied the same code for vtt subtitles and it not works. How can I do this to works with vtt files?
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python3.6/site-packages/pysubs2/ssafile.py", line 92, in load
return cls.from_file(fp, format_, fps=fps, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pysubs2/ssafile.py", line 145, in from_file
format_ = autodetect_format(fragment)
File "/usr/local/lib/python3.6/site-packages/pysubs2/formats.py", line 62, in autodetect_format
raise FormatAutodetectionError("No suitable formats")
pysubs2.exceptions.FormatAutodetectionError: No suitable formats
from pysubs2.
You can try to force the input format to get around autodetection:
subs = pysubs2.load("test.vtt", format_="srt")
subs.save("test.srt")
However, WebVTT is fundamentally a different format than SRT, so re-using SRT parser to load such files is a "hack". It may be necessary to implement proper WebVTT parser to read more complex files.
from pysubs2.
hmm
it not worked correctly. sad life
from pysubs2.
is it possible for me to use pysubs2 to concatenate subtitles in srt?
['sub_1.srt', 'sub_2.srt', 'sub_3.srt'] >>> subtitle.srt
from pysubs2.
Can you share the .vtt
file which could not be loaded by pysubs2
? I can have a look at it.
As for merging SRT files, yes you can do that:
import pysubs2
input_files = [
"sub_1.srt",
"sub_2.srt",
"sub_3.srt",
]
output_subs = pysubs2.SSAFile()
for file in input_files:
subs = pysubs2.load(file)
output_subs.events.extend(subs.events)
output_subs.save("subtitle.srt")
from pysubs2.
Can you share the
.vtt
file which could not be loaded bypysubs2
? I can have a look at it.As for merging SRT files, yes you can do that:
import pysubs2 input_files = [ "sub_1.srt", "sub_2.srt", "sub_3.srt", ] output_subs = pysubs2.SSAFile() for file in input_files: subs = pysubs2.load(file) output_subs.events.extend(subs.events) output_subs.save("subtitle.srt")
VTT files:
vtt_files.zip
For concatenate srt files i already tryied to use this, but it not works.
from pysubs2.
I have added explicit support for VTT files into the library and successfully merged your testing files with this script:
import pysubs2
import glob
input_files = glob.glob("SUB_*.vtt")
output_subs = pysubs2.SSAFile()
for file in input_files:
subs = pysubs2.load(file)
output_subs.events.extend(subs.events)
output_subs.save("subtitle.srt")
I will be releasing a new version of pysubs2
shortly. Relevant changes are in commit 29629fd.
from pysubs2.
Related Issues (20)
- Support timestamps without ms HOT 4
- ssaevent hashable? HOT 2
- text retuen all the content with color and other tag in pysubs2 HOT 2
- [QA] DeprecationWarning while running tests
- Doesn't work in Python 3.11 HOT 3
- 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
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.