-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg_filter_example.py
More file actions
executable file
·145 lines (116 loc) · 4.54 KB
/
svg_filter_example.py
File metadata and controls
executable file
·145 lines (116 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
# SVG Filter Example - Demonstrates how to use the SVG filtering functionality
import os
import sys
from pathlib import Path
# Add src directory to path to import modules
sys.path.insert(0, str(Path(__file__).resolve().parent / "src"))
try:
from utils.merger import Merger, WHITE, YELLOW
except ImportError:
print("Error: Could not import merger module. Make sure you have the correct directory structure.")
sys.exit(1)
def main():
"""Demonstrate SVG filtering functionality."""
print("SVG Filtering Example")
print("====================")
# Define paths
example_stars_path = "example_stars.srt"
output_dir = "."
# Check if example file exists
if not os.path.exists(example_stars_path):
print(f"Error: {example_stars_path} does not exist.")
print("Please run the script in the same directory as example_stars.srt.")
return
# Example 1: Basic merge with SVG filtering
print("\nExample 1: Basic merge with SVG filtering")
print("----------------------------------------")
# Create merger with SVG filtering enabled
merger1 = Merger(
output_path=output_dir,
output_name="filtered_stars.srt",
output_encoding='utf-8'
)
# Enable SVG filtering
merger1.enable_svg_filtering(True)
# Add subtitle file
print(f"Adding subtitle file: {example_stars_path}")
merger1.add(
subtitle_address=example_stars_path,
codec='utf-8',
color=WHITE,
preserve_svg=True # Important: preserve SVG paths
)
# Merge subtitles
merger1.merge()
print(f"Filtered subtitle saved to: {os.path.join(output_dir, 'filtered_stars.srt')}")
# Example 2: Merge with SVG filtering and text removal
print("\nExample 2: Merge with SVG filtering and text removal")
print("--------------------------------------------------")
# Create merger with SVG filtering enabled and text removal
merger2 = Merger(
output_path=output_dir,
output_name="svg_only_stars.srt",
output_encoding='utf-8'
)
# Enable SVG filtering and text removal
merger2.enable_svg_filtering(True)
merger2.set_remove_text_entries(True)
# Add subtitle file
print(f"Adding subtitle file: {example_stars_path}")
merger2.add(
subtitle_address=example_stars_path,
codec='utf-8',
color=WHITE,
preserve_svg=True # Important: preserve SVG paths
)
# Merge subtitles
merger2.merge()
print(f"SVG-only subtitle saved to: {os.path.join(output_dir, 'svg_only_stars.srt')}")
# Example 3: Merge with another subtitle file
print("\nExample 3: Merge with another subtitle file")
print("----------------------------------------")
# Check if example subtitle file exists
example_subtitle_path = "example_subtitle.srt"
if not os.path.exists(example_subtitle_path):
print(f"Warning: {example_subtitle_path} does not exist. Skipping Example 3.")
return
# Create merger with SVG filtering enabled
merger3 = Merger(
output_path=output_dir,
output_name="merged_with_filtering.srt",
output_encoding='utf-8'
)
# Enable SVG filtering
merger3.enable_svg_filtering(True)
# Add SVG subtitle file
print(f"Adding SVG subtitle file: {example_stars_path}")
merger3.add(
subtitle_address=example_stars_path,
codec='utf-8',
color=WHITE,
preserve_svg=True # Important: preserve SVG paths
)
# Add regular subtitle file
print(f"Adding regular subtitle file: {example_subtitle_path}")
merger3.add(
subtitle_address=example_subtitle_path,
codec='utf-8',
color=YELLOW,
size=24,
bold=True,
preserve_svg=True
)
# Merge subtitles
merger3.merge()
print(f"Merged subtitle with filtering saved to: {os.path.join(output_dir, 'merged_with_filtering.srt')}")
print("\nYou can now use these subtitle files with MPV player:")
print(f"mpv --sub-file=filtered_stars.srt your_video_file.mp4")
print(f"mpv --sub-file=svg_only_stars.srt your_video_file.mp4")
print(f"mpv --sub-file=merged_with_filtering.srt your_video_file.mp4")
print("\nSVG Filtering Options:")
print("1. Enable SVG filtering: merger.enable_svg_filtering(True)")
print("2. Remove text entries: merger.set_remove_text_entries(True)")
print("3. Preserve SVG paths: add(..., preserve_svg=True)")
if __name__ == "__main__":
main()