vid2vtf 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vid2vtf-0.0.0/PKG-INFO ADDED
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: vid2vtf
3
+ Version: 0.0.0
4
+ Author: theredenemy
5
+ Project-URL: Repository, https://github.com/theredenemy/vid2vtf.git
6
+ Project-URL: Issues, https://github.com/theredenemy/vid2vtf/issues
7
+ Requires-Python: >=3.8
8
+ Requires-Dist: attrs==25.4.0
9
+ Requires-Dist: av==16.0.1
10
+ Requires-Dist: pillow==12.0.0
11
+ Requires-Dist: srctools==2.6.2
12
+ Requires-Dist: typing_extensions==4.15.0
13
+ Requires-Dist: useful_types==0.2.1
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vid2vtf"
7
+ dynamic = ["dependencies", "version"]
8
+ authors = [{name = "theredenemy"}]
9
+ requires-python = ">= 3.8"
10
+
11
+ [project.urls]
12
+ Repository = "https://github.com/theredenemy/vid2vtf.git"
13
+ Issues = "https://github.com/theredenemy/vid2vtf/issues"
14
+
15
+ [tool.setuptools.dynamic]
16
+ dependencies = {file = ["requirements.txt"]}
17
+
18
+ [project.scripts]
19
+ vid2vtf-cli = "vid2vtf.cli:main"
@@ -0,0 +1,6 @@
1
+ attrs==25.4.0
2
+ av==16.0.1
3
+ pillow==12.0.0
4
+ srctools==2.6.2
5
+ typing_extensions==4.15.0
6
+ useful_types==0.2.1
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from vid2vtf.vid2vtf import video_to_vtf
@@ -0,0 +1,4 @@
1
+ from vid2vtf.cli import main
2
+
3
+ if __name__ == '__main__':
4
+ main()
@@ -0,0 +1,17 @@
1
+ import argparse
2
+ import sys
3
+ from vid2vtf.vid2vtf import video_to_vtf
4
+ def main():
5
+ if len(sys.argv) > 1:
6
+ parser = argparse.ArgumentParser()
7
+ parser.add_argument("--video")
8
+ parser.add_argument("--fps", default=3)
9
+ parser.add_argument("--width", default=256)
10
+ parser.add_argument("--height", default=128)
11
+
12
+ args = parser.parse_args()
13
+
14
+ video_to_vtf(args.video, fps=int(args.fps), width=int(args.width), height=int(args.height))
15
+
16
+ if __name__ == '__main__':
17
+ main()
@@ -0,0 +1,91 @@
1
+ import srctools.vtf as vtf
2
+ from srctools.vmt import Material
3
+ from srctools.keyvalues import Keyvalues
4
+ import av
5
+ import pathlib
6
+ import os
7
+ import shutil
8
+ import time
9
+ import sys
10
+ from PIL import Image
11
+ def video_to_vtf(video, fps=3, width=256, height=128):
12
+ ext = pathlib.Path(video).suffix
13
+ name = pathlib.Path(video).stem
14
+ maindir = os.getcwd()
15
+ size = [width, height]
16
+ fileeditname = f"{name}_256128{ext}"
17
+ if os.path.isfile(fileeditname):
18
+ os.remove(fileeditname)
19
+ #os.system(f"ffmpeg -i {video} -r {fps}/1 -vf scale={width}:{height} -async 1 {fileeditname} -y")
20
+ #os.system(f'ffmpeg -i {video} -ar 11025 {name}.wav -y')
21
+ audio_container = av.open(video)
22
+ audio_stream = audio_container.streams.audio[0]
23
+ output_wav = av.open(f"{maindir}\\sound\\{name}.wav", mode='w')
24
+ output_audio_stream = output_wav.add_stream('pcm_s16le', rate=11025)
25
+ if os.path.isdir(f"{maindir}\\materials"):
26
+ shutil.rmtree(f"{maindir}\\materials")
27
+ os.mkdir(f"{maindir}\\materials")
28
+ if os.path.isdir(f"{maindir}\\sound"):
29
+ shutil.rmtree(f"{maindir}\\sound")
30
+ os.mkdir(f"{maindir}\\sound")
31
+ if os.path.isfile(f"{maindir}\\materials\\{name}.vtf"):
32
+ os.remove(f"{maindir}\\materials\\{name}.vtf")
33
+ if os.path.isfile(f"{maindir}\\materials\\{name}.vmt"):
34
+ os.remove(f"{maindir}\\materials\\{name}.vmt")
35
+ if os.path.isfile(f"{maindir}\\sound\\{name}.wav"):
36
+ os.remove(f"{maindir}\\sound\\{name}.wav")
37
+
38
+ for frame in audio_container.decode(audio_stream):
39
+
40
+ for packet in output_audio_stream.encode(frame):
41
+ output_wav.mux(packet)
42
+
43
+ for packet in output_audio_stream.encode(None):
44
+ output_wav.mux(packet)
45
+
46
+ audio_container.close()
47
+ vmt_proxy_data = Keyvalues('AnimatedTexture', [
48
+ Keyvalues("animatedTextureVar", "$basetexture"),
49
+ Keyvalues("animatedTextureFrameNumVar", "$frame"),
50
+ Keyvalues("animatedTextureFrameRate", str(fps))
51
+
52
+ ])
53
+
54
+
55
+ mat = Material(
56
+ shader="LightmappedGeneric",
57
+ params={
58
+ "$basetexture": name
59
+ },
60
+ proxies=[vmt_proxy_data]
61
+ )
62
+ with open(f"{maindir}\\materials\\{name}.vmt", 'w', encoding='utf-8') as f:
63
+ mat.export(f)
64
+ print("wait")
65
+ time.sleep(3)
66
+ container = av.open(video)
67
+ stream = container.streams.video[0]
68
+ original_fps = float(stream.average_rate)
69
+
70
+ interval = max(1, round(original_fps / fps))
71
+ frames = []
72
+
73
+ for i, frame in enumerate(container.decode(stream)):
74
+ if i % interval == 0:
75
+ img = frame.to_image().resize(size).convert("RGB")
76
+ frames.append(img.tobytes())
77
+ print(len(frames))
78
+ texture = vtf.VTF(width=width, height=height, frames=len(frames), fmt=vtf.ImageFormats.DXT1, version=(7, 2))
79
+
80
+ for i, data in enumerate(frames):
81
+ print(i, end='\r')
82
+ vtf_frame = texture.get(frame=i)
83
+ vtf_frame.copy_from(data, format=vtf.ImageFormats.RGB888)
84
+ print("\n")
85
+ texture.compute_mipmaps()
86
+
87
+ with open(f"{maindir}\\materials\\{name}.vtf", 'wb') as f:
88
+ texture.save(f)
89
+ container.close()
90
+ return True
91
+
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: vid2vtf
3
+ Version: 0.0.0
4
+ Author: theredenemy
5
+ Project-URL: Repository, https://github.com/theredenemy/vid2vtf.git
6
+ Project-URL: Issues, https://github.com/theredenemy/vid2vtf/issues
7
+ Requires-Python: >=3.8
8
+ Requires-Dist: attrs==25.4.0
9
+ Requires-Dist: av==16.0.1
10
+ Requires-Dist: pillow==12.0.0
11
+ Requires-Dist: srctools==2.6.2
12
+ Requires-Dist: typing_extensions==4.15.0
13
+ Requires-Dist: useful_types==0.2.1
@@ -0,0 +1,12 @@
1
+ pyproject.toml
2
+ requirements.txt
3
+ src/vid2vtf/__init__.py
4
+ src/vid2vtf/__main__.py
5
+ src/vid2vtf/cli.py
6
+ src/vid2vtf/vid2vtf.py
7
+ src/vid2vtf.egg-info/PKG-INFO
8
+ src/vid2vtf.egg-info/SOURCES.txt
9
+ src/vid2vtf.egg-info/dependency_links.txt
10
+ src/vid2vtf.egg-info/entry_points.txt
11
+ src/vid2vtf.egg-info/requires.txt
12
+ src/vid2vtf.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ vid2vtf-cli = vid2vtf.cli:main
@@ -0,0 +1,6 @@
1
+ attrs==25.4.0
2
+ av==16.0.1
3
+ pillow==12.0.0
4
+ srctools==2.6.2
5
+ typing_extensions==4.15.0
6
+ useful_types==0.2.1
@@ -0,0 +1 @@
1
+ vid2vtf