Skip to content

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
moixllik committed Nov 1, 2024
1 parent f992d97 commit 0823b82
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.blend*
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VER=$(shell cat ./version.txt)
DEMO=$(shell realpath ./demo.blend)

build: update
zip btt-$(VER).zip ./__init__.py ./blender_manifest.toml
Expand All @@ -9,3 +10,5 @@ update:
server:
python3 -m http.server -d ./docs/

demo:
flatpak run org.blender.Blender $(DEMO)
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
[Converter](https://moixllik.github.io/btt/converter) `.srt` and `.vtt` to `.btt`

```
file=./subtitle.btt
@channel=1;
@font_size=120.0;
@color=#ff0000ff;
@use_box=1;
@box_color=#000000ff;
file=./subtitles.btt;
start=00:00:00+0;
end=00:00:03+0;
channel=1;
font_size=120.0;
color=#ff0000ff;
location=0.3 0.3;
align_x=left;
align_y=bottom;
use_box=1;
box_color=#000000ff;
wrap_width=0.5;
Blender Video Text Tracks
Videos
Expand Down
79 changes: 48 additions & 31 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,62 @@ def subtitles_active(count):
scene["frame_final_end"] = frame_final_end
return strip

def subtitles_strip_prop(strip, name, value):
match name:
case "start":
strip.frame_start = subtitles_from_time(value)
case "end":
frame_final_end = subtitles_from_time(value)
strip.frame_final_end = frame_final_end
bpy.context.scene["frame_final_end"] = frame_final_end
case "channel":
strip.channel = int(value)
case "location":
x, y = value.split(" ")
strip.location = (float(x), float(y))
case "align_x":
strip.align_x = value.upper()
case "align_y":
strip.align_y = value.upper()
case "font_size":
strip.font_size = float(value)
case "use_box":
strip.use_box = True
case "wrap_width":
strip.wrap_width = float(value)
case "color":
strip.color = subtitles_from_rgba(value)
case "box_color":
strip.box_color = subtitles_from_rgba(value)
case _:
return True

def subtitles_scene_props(scene, strip):
for name in scene.keys():
if name[0] == '@':
value = scene[name]
subtitles_strip_prop(strip, name[1:], value)


def subtitles_props(strip, source):
scene = bpy.context.scene
props = source.split(";\n")
if isinstance(props, list):
for prop in props[:-1]:
name, value = prop.strip().split("=")
name = name.strip()
value = value.strip()
match name:
case "start":
strip.frame_start = subtitles_from_time(value)
case "end":
frame_final_end = subtitles_from_time(value)
strip.frame_final_end = frame_final_end
bpy.context.scene["frame_final_end"] = frame_final_end
case "channel":
strip.channel = int(value)
case "location":
x, y = value.split(" ")
strip.location = (float(x), float(y))
case "align_x":
strip.align_x = value.upper()
case "align_y":
strip.align_y = value.upper()
case "font_size":
strip.font_size = float(value)
case "use_box":
strip.use_box = True
case "wrap_width":
strip.wrap_width = float(value)
case "color":
strip.color = subtitles_from_rgba(value)
case "box_color":
strip.box_color = subtitles_from_rgba(value)
case _:
strip[name] = value

strip.text = props[-1]


if name[0] == '@':
scene[name] = value
elif subtitles_strip_prop(strip, name, value):
strip[name] = value

if len(props[-1]) > 0:
strip.text = props[-1]
subtitles_scene_props(scene,strip)
else:
bpy.context.scene.sequence_editor.sequences.remove(strip)

def subtitles_strip_text(count, source):
strip = subtitles_active(count)
Expand Down
15 changes: 8 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ <h1><a href="https://moixllik.github.io/btt/">Blender Video Text Tracks</a></h1>
</figure>

<h2>BTT File</h2>
For example: <code>./subtitles.btt</code>
For example: <code><a href="/subtitles.btt">./subtitles.btt</a></code>
<pre>
<code>file=./subtitles.btt
<code>@channel=1;
@font_size=120.0;
@color=#ff0000ff;
@use_box=1;
@box_color=#000000ff;

file=./subtitles.btt;
start=00:00:00+0;
end=00:00:03+0;
channel=1;
font_size=120.0;
color=#ff0000ff;
location=0.3 0.3;
align_x=left;
align_y=bottom;
use_box=1;
box_color=#000000ff;
wrap_width=0.5;
Blender Video Text Tracks
Videos
Expand Down
17 changes: 17 additions & 0 deletions docs/subtitles.btt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@channel=1;
@font_size=120.0;
@color=#ff0000ff;
@use_box=1;
@box_color=#000000ff;

file=./subtitles.btt;
start=00:00:00+0;
end=00:00:03+0;
location=0.3 0.3;
align_x=left;
align_y=bottom;
wrap_width=0.5;
Blender Video Text Tracks
Videos
with
Subtitles
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2

0 comments on commit 0823b82

Please # to comment.