mixing 0.0.2__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.
mixing-0.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mixing-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.1
2
+ Name: mixing
3
+ Version: 0.0.2
4
+ Summary: Tools for video and audio editing
5
+ Home-page: https://github.com/thorwhalen/mixing
6
+ Author: Thor Whalen
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+
12
+
13
+ # mixing
14
+ Tools for video and audio editing
15
+
16
+
17
+ To install: ```pip install mixing```
18
+
19
+
20
+ # Examples
21
+
22
+ ## mixing.video
23
+
24
+ ### write_subtitles_in_video
25
+
26
+
27
+ Write subtitles in a video.
28
+
29
+ Example usage:
30
+
31
+ ```python
32
+ >>> from mixing import write_subtitles_in_video
33
+ >>> output_path = write_subtitles_in_video("~/Downloads/some_video.mp4")
34
+ ```
35
+
36
+ Which is syntactic sugar for the more explicit:
37
+
38
+ ```python
39
+ >>> output_path = write_subtitles_in_video(
40
+ ... "~/Downloads/some_video.mp4",
41
+ ... subtitles="~/Downloads/some_video.srt",
42
+ ... output_video="~/Downloads/some_video.mp4"
43
+ ... )
44
+ ```
45
+
46
+
47
+ # Further requirements
48
+
49
+ ## FFmpeg
50
+
51
+ Many of the tools also require `ffmeg`.
52
+
53
+ To install FFmpeg on your system, follow the instructions for your operating system below.
54
+
55
+ ### macOS
56
+
57
+ 1. **Using Homebrew:**
58
+ - Open Terminal.
59
+ - Run the following command:
60
+ ```bash
61
+ brew install ffmpeg
62
+ ```
63
+
64
+ For more details, visit the [FFmpeg installation page for macOS](https://ffmpeg.org/download.html#build-mac).
65
+
66
+ ### Linux
67
+
68
+ 1. **Using the package manager:**
69
+ - For Debian/Ubuntu-based distributions, run:
70
+ ```bash
71
+ sudo apt update
72
+ sudo apt install ffmpeg
73
+ ```
74
+ - For Fedora, run:
75
+ ```bash
76
+ sudo dnf install ffmpeg
77
+ ```
78
+ - For Arch Linux, run:
79
+ ```bash
80
+ sudo pacman -S ffmpeg
81
+ ```
82
+
83
+ For more details, visit the [FFmpeg installation page for Linux](https://ffmpeg.org/download.html#build-linux).
84
+
85
+ ### Windows
86
+
87
+ 1. **Using Windows builds:**
88
+ - Download the executable from [FFmpeg for Windows](https://ffmpeg.org/download.html#build-windows).
89
+ - Extract the downloaded files and add the `bin` directory to your system's PATH.
90
+
91
+ For more details, visit the [FFmpeg installation page for Windows](https://ffmpeg.org/download.html#build-windows).
mixing-0.0.2/README.md ADDED
@@ -0,0 +1,80 @@
1
+
2
+ # mixing
3
+ Tools for video and audio editing
4
+
5
+
6
+ To install: ```pip install mixing```
7
+
8
+
9
+ # Examples
10
+
11
+ ## mixing.video
12
+
13
+ ### write_subtitles_in_video
14
+
15
+
16
+ Write subtitles in a video.
17
+
18
+ Example usage:
19
+
20
+ ```python
21
+ >>> from mixing import write_subtitles_in_video
22
+ >>> output_path = write_subtitles_in_video("~/Downloads/some_video.mp4")
23
+ ```
24
+
25
+ Which is syntactic sugar for the more explicit:
26
+
27
+ ```python
28
+ >>> output_path = write_subtitles_in_video(
29
+ ... "~/Downloads/some_video.mp4",
30
+ ... subtitles="~/Downloads/some_video.srt",
31
+ ... output_video="~/Downloads/some_video.mp4"
32
+ ... )
33
+ ```
34
+
35
+
36
+ # Further requirements
37
+
38
+ ## FFmpeg
39
+
40
+ Many of the tools also require `ffmeg`.
41
+
42
+ To install FFmpeg on your system, follow the instructions for your operating system below.
43
+
44
+ ### macOS
45
+
46
+ 1. **Using Homebrew:**
47
+ - Open Terminal.
48
+ - Run the following command:
49
+ ```bash
50
+ brew install ffmpeg
51
+ ```
52
+
53
+ For more details, visit the [FFmpeg installation page for macOS](https://ffmpeg.org/download.html#build-mac).
54
+
55
+ ### Linux
56
+
57
+ 1. **Using the package manager:**
58
+ - For Debian/Ubuntu-based distributions, run:
59
+ ```bash
60
+ sudo apt update
61
+ sudo apt install ffmpeg
62
+ ```
63
+ - For Fedora, run:
64
+ ```bash
65
+ sudo dnf install ffmpeg
66
+ ```
67
+ - For Arch Linux, run:
68
+ ```bash
69
+ sudo pacman -S ffmpeg
70
+ ```
71
+
72
+ For more details, visit the [FFmpeg installation page for Linux](https://ffmpeg.org/download.html#build-linux).
73
+
74
+ ### Windows
75
+
76
+ 1. **Using Windows builds:**
77
+ - Download the executable from [FFmpeg for Windows](https://ffmpeg.org/download.html#build-windows).
78
+ - Extract the downloaded files and add the `bin` directory to your system's PATH.
79
+
80
+ For more details, visit the [FFmpeg installation page for Windows](https://ffmpeg.org/download.html#build-windows).
@@ -0,0 +1,5 @@
1
+ """
2
+ Various video and audio editing utilities.
3
+ """
4
+
5
+ from mixing.video import write_subtitles_in_video
@@ -0,0 +1,119 @@
1
+ """
2
+ Video tools
3
+
4
+ """
5
+
6
+ from typing import Optional
7
+ import moviepy.editor as mp
8
+ from moviepy.editor import TextClip, CompositeVideoClip
9
+ from pathlib import Path
10
+ import os
11
+
12
+
13
+ def to_srt_time(seconds):
14
+ """
15
+ Convert seconds to SRT time format.
16
+
17
+ Example usage:
18
+
19
+ >>> to_srt_time(1.5)
20
+ '00:00:01,500'
21
+
22
+ """
23
+ milliseconds = int((seconds - int(seconds)) * 1000)
24
+ minutes, seconds = divmod(int(seconds), 60)
25
+ hours, minutes = divmod(minutes, 60)
26
+ return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
27
+
28
+
29
+ def generate_subtitle_clips(subtitles, video_clip, fontsize=24, color='white'):
30
+ subtitle_clips = []
31
+ for subtitle in subtitles.split('\n\n'):
32
+ lines = subtitle.split('\n')
33
+ if len(lines) >= 3:
34
+ time_info = lines[1].split(' --> ')
35
+ start_time = time_info[0].replace(',', '.')
36
+ end_time = time_info[1].replace(',', '.')
37
+ text = ' '.join(lines[2:])
38
+ txt_clip = TextClip(
39
+ text,
40
+ fontsize=fontsize,
41
+ color=color,
42
+ size=(video_clip.w, None),
43
+ method='caption',
44
+ )
45
+ txt_clip = (
46
+ txt_clip.set_start(start_time)
47
+ .set_end(end_time)
48
+ .set_position(('center', 'bottom'))
49
+ )
50
+ subtitle_clips.append(txt_clip)
51
+ return subtitle_clips
52
+
53
+
54
+ Filepath = str
55
+
56
+
57
+ def process_path(path: Filepath) -> Path:
58
+ return Path(path).expanduser().resolve()
59
+
60
+
61
+ def write_subtitles_in_video(
62
+ video: Filepath, subtitles: Optional[str] = None, output_video: Optional[str] = None
63
+ ):
64
+ """
65
+ Write subtitles in a video.
66
+
67
+ Example usage:
68
+
69
+ >>> output_path = write_subtitles_in_video("~/Downloads/some_video.mp4") # doctest: +SKIP
70
+
71
+ Which is syntactic sugar for the more explicit:
72
+
73
+ >>> output_path = write_subtitles_in_video(
74
+ ... "~/Downloads/some_video.mp4",
75
+ ... subtitles="~/Downloads/Ssome_video.srt",
76
+ ... output_video="~/Downloads/some_video.mp4"
77
+ ... ) # doctest: +SKIP
78
+
79
+ """
80
+ video_path = process_path(video)
81
+
82
+ srt_content, output_video_path = _process_inputs(
83
+ subtitles, output_video, video_path
84
+ )
85
+
86
+ # Load the video file
87
+ video_clip = mp.VideoFileClip(str(video_path))
88
+
89
+ # Generate subtitle clips
90
+ subtitle_clips = generate_subtitle_clips(srt_content, video_clip)
91
+
92
+ # Create a composite video with subtitles
93
+ video_with_subtitles = CompositeVideoClip([video_clip] + subtitle_clips)
94
+
95
+ # Export the video with subtitles
96
+ video_with_subtitles.write_videofile(
97
+ str(output_video_path), codec="libx264", fps=video_clip.fps
98
+ )
99
+
100
+ return output_video_path
101
+
102
+
103
+ def _process_inputs(subtitles, output_video, video_path):
104
+ if subtitles is None:
105
+ subtitles_path = video_path.with_suffix('.srt')
106
+ srt_content = subtitles_path.read_text()
107
+ elif os.path.isfile(subtitles):
108
+ subtitles_path = process_path(subtitles)
109
+ srt_content = subtitles_path.read_text()
110
+ else:
111
+ assert isinstance(subtitles, str), "subtitles should be a string"
112
+ srt_content = subtitles
113
+
114
+ if output_video is None:
115
+ output_video_path = video_path.with_stem(video_path.stem + '_with_subtitles')
116
+ output_video_path = output_video_path.with_suffix(video_path.suffix)
117
+ else:
118
+ output_video_path = Path(output_video)
119
+ return srt_content, output_video_path
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.1
2
+ Name: mixing
3
+ Version: 0.0.2
4
+ Summary: Tools for video and audio editing
5
+ Home-page: https://github.com/thorwhalen/mixing
6
+ Author: Thor Whalen
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+
12
+
13
+ # mixing
14
+ Tools for video and audio editing
15
+
16
+
17
+ To install: ```pip install mixing```
18
+
19
+
20
+ # Examples
21
+
22
+ ## mixing.video
23
+
24
+ ### write_subtitles_in_video
25
+
26
+
27
+ Write subtitles in a video.
28
+
29
+ Example usage:
30
+
31
+ ```python
32
+ >>> from mixing import write_subtitles_in_video
33
+ >>> output_path = write_subtitles_in_video("~/Downloads/some_video.mp4")
34
+ ```
35
+
36
+ Which is syntactic sugar for the more explicit:
37
+
38
+ ```python
39
+ >>> output_path = write_subtitles_in_video(
40
+ ... "~/Downloads/some_video.mp4",
41
+ ... subtitles="~/Downloads/some_video.srt",
42
+ ... output_video="~/Downloads/some_video.mp4"
43
+ ... )
44
+ ```
45
+
46
+
47
+ # Further requirements
48
+
49
+ ## FFmpeg
50
+
51
+ Many of the tools also require `ffmeg`.
52
+
53
+ To install FFmpeg on your system, follow the instructions for your operating system below.
54
+
55
+ ### macOS
56
+
57
+ 1. **Using Homebrew:**
58
+ - Open Terminal.
59
+ - Run the following command:
60
+ ```bash
61
+ brew install ffmpeg
62
+ ```
63
+
64
+ For more details, visit the [FFmpeg installation page for macOS](https://ffmpeg.org/download.html#build-mac).
65
+
66
+ ### Linux
67
+
68
+ 1. **Using the package manager:**
69
+ - For Debian/Ubuntu-based distributions, run:
70
+ ```bash
71
+ sudo apt update
72
+ sudo apt install ffmpeg
73
+ ```
74
+ - For Fedora, run:
75
+ ```bash
76
+ sudo dnf install ffmpeg
77
+ ```
78
+ - For Arch Linux, run:
79
+ ```bash
80
+ sudo pacman -S ffmpeg
81
+ ```
82
+
83
+ For more details, visit the [FFmpeg installation page for Linux](https://ffmpeg.org/download.html#build-linux).
84
+
85
+ ### Windows
86
+
87
+ 1. **Using Windows builds:**
88
+ - Download the executable from [FFmpeg for Windows](https://ffmpeg.org/download.html#build-windows).
89
+ - Extract the downloaded files and add the `bin` directory to your system's PATH.
90
+
91
+ For more details, visit the [FFmpeg installation page for Windows](https://ffmpeg.org/download.html#build-windows).
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ mixing/__init__.py
6
+ mixing.egg-info/PKG-INFO
7
+ mixing.egg-info/SOURCES.txt
8
+ mixing.egg-info/dependency_links.txt
9
+ mixing.egg-info/not-zip-safe
10
+ mixing.egg-info/requires.txt
11
+ mixing.egg-info/top_level.txt
12
+ mixing/video/__init__.py
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ moviepy
@@ -0,0 +1 @@
1
+ mixing
mixing-0.0.2/setup.cfg ADDED
@@ -0,0 +1,26 @@
1
+ [metadata]
2
+ name = mixing
3
+ version = 0.0.2
4
+ url = https://github.com/thorwhalen/mixing
5
+ platforms = any
6
+ description_file = README.md
7
+ root_url = https://github.com/thorwhalen/
8
+ license = mit
9
+ author = Thor Whalen
10
+ description = Tools for video and audio editing
11
+ long_description = file:README.md
12
+ long_description_content_type = text/markdown
13
+ keywords =
14
+ display_name = mixing
15
+
16
+ [options]
17
+ packages = find:
18
+ include_package_data = True
19
+ zip_safe = False
20
+ install_requires =
21
+ moviepy
22
+
23
+ [egg_info]
24
+ tag_build =
25
+ tag_date = 0
26
+
mixing-0.0.2/setup.py ADDED
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup() # Note: Everything should be in the local setup.cfg