├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── docs-feedback.md
│ ├── feature_request.md
│ └── help-wanted.md
└── pull_request_template.md
├── .gitignore
├── LICENSE
├── README-en.md
├── README.md
├── assets
├── headerDark.svg
└── headerLight.svg
├── autosv
├── __init__.py
├── autosv.py
├── calculate
│ ├── __init__.py
│ ├── selection.py
│ ├── sliding_cpu.py
│ └── sliding_gpu.py
├── cli.py
├── log
│ ├── __init__.py
│ └── logger.py
└── slice
│ ├── __init__.py
│ └── slice_video.py
├── pyproject.toml
├── requirements.txt
└── test
├── sample.ass
├── sample.mp4
└── sample2.ass
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve this project.
4 | title: "[BUG] "
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Describe the bug
11 | (A clear and concise description of what the bug is.)
12 |
13 | ## How To Reproduce
14 | Steps to reproduce the behavior:
15 | 1. Config/File changes: ...
16 | 2. Run command: ...
17 | 3. See error: ...
18 |
19 | ## Expected behavior
20 | (A clear and concise description of what you expected to happen.)
21 |
22 | ## Screenshots
23 | (If applicable, add screenshots to help explain your problem.)
24 |
25 | ## Environment Information
26 | - Operating System: [e.g. Ubuntu 20.04.5 LTS]
27 | - Python Version: [e.g. Python 3.9.15]
28 | - Driver & CUDA Version: [e.g. Driver 470.103.01 & CUDA 11.4]
29 | - Error Messages and Logs: [If applicable, provide any error messages or relevant log outputs]
30 |
31 | ## Additional context
32 | (Add any other context about the problem here.)
33 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/docs-feedback.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Docs feedback
3 | about: Improve documentation about this project.
4 | title: "[Docs] "
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Documentation Reference
11 | (Path/Link to the documentation file)
12 |
13 | ## Feedback on documentation
14 | (Your suggestions to the documentation. e.g., accuracy, complex explanations, structural organization, practical examples, technical reliability, and consistency)
15 |
16 | ## Additional context
17 | (Add any other context or screenshots about the documentation here.)
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project.
4 | title: "[Feature] "
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Is your feature request related to a problem? Please describe.
11 | (A clear and concise description of what the problem is.)
12 |
13 | ## Describe the solution you'd like
14 | (A clear and concise description of what you want to happen.)
15 |
16 | ## Describe alternatives you've considered
17 | (A clear and concise description of any alternative solutions or features you've considered.)
18 |
19 | ## Additional context
20 | (Add any other context or screenshots about the feature request here.)
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/help-wanted.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Help wanted
3 | about: Want help from this project team.
4 | title: "[Help] "
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Problem Overview
11 | (Briefly and clearly describe the issue you're facing and seeking help with.)
12 |
13 | ## Steps Taken
14 | (Detail your attempts to resolve the issue, including any relevant steps or processes.)
15 | 1. Config/File changes: ...
16 | 2. Run command: ...
17 | 3. See errors: ...
18 |
19 | ## Expected Outcome
20 | (A clear and concise description of what you expected to happen.)
21 |
22 | ## Screenshots
23 | (If applicable, add screenshots to help explain your problem.)
24 |
25 | ## Environment Information
26 | - Operating System: [e.g. Ubuntu 20.04.5 LTS]
27 | - Python Version: [e.g. Python 3.9.15]
28 | - Driver & CUDA Version: [e.g. Driver 470.103.01 & CUDA 11.4]
29 | - Error Messages and Logs: [If applicable, provide any error messages or relevant log outputs]
30 |
31 | ## Additional context
32 | (Add any other context about the problem here.)
33 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
2 | ## Description
3 |
4 | [Please describe the background, purpose, changes made, and how to test this PR]
5 |
6 | ## Related Issues
7 |
8 | [List the issue numbers related to this PR]
9 |
10 | ## Changes Proposed
11 |
12 | - [ ] change1
13 | - [ ] ...
14 |
15 | ## Who Can Review?
16 |
17 | [Please use the '@' symbol to mention any community member who is free to review the PR once the tests have passed. Feel free to tag members or contributors who might be interested in your PR.]
18 |
19 | ## TODO
20 |
21 | - [ ] task1
22 | - [ ] ...
23 |
24 | ## Checklist
25 |
26 | - [ ] Code has been reviewed
27 | - [ ] Code complies with the project's code standards and best practices
28 | - [ ] Code has passed all tests
29 | - [ ] Code does not affect the normal use of existing features
30 | - [ ] Code has been commented properly
31 | - [ ] Documentation has been updated (if applicable)
32 | - [ ] Demo/checkpoint has been attached (if applicable)
33 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.toptal.com/developers/gitignore/api/intellij+all,python,pycharm+all,macos,windows
2 | # Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,python,pycharm+all,macos,windows
3 |
4 | ### Intellij+all ###
5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7 |
8 | # User-specific stuff
9 | .idea/**/workspace.xml
10 | .idea/**/tasks.xml
11 | .idea/**/usage.statistics.xml
12 | .idea/**/dictionaries
13 | .idea/**/shelf
14 |
15 | # Generated files
16 | .idea/**/contentModel.xml
17 |
18 | # Sensitive or high-churn files
19 | .idea/**/dataSources/
20 | .idea/**/dataSources.ids
21 | .idea/**/dataSources.local.xml
22 | .idea/**/sqlDataSources.xml
23 | .idea/**/dynamic.xml
24 | .idea/**/uiDesigner.xml
25 | .idea/**/dbnavigator.xml
26 |
27 | # Gradle
28 | .idea/**/gradle.xml
29 | .idea/**/libraries
30 |
31 | # Gradle and Maven with auto-import
32 | # When using Gradle or Maven with auto-import, you should exclude module files,
33 | # since they will be recreated, and may cause churn. Uncomment if using
34 | # auto-import.
35 | # .idea/artifacts
36 | # .idea/compiler.xml
37 | # .idea/jarRepositories.xml
38 | # .idea/modules.xml
39 | # .idea/*.iml
40 | # .idea/modules
41 | # *.iml
42 | # *.ipr
43 |
44 | # CMake
45 | cmake-build-*/
46 |
47 | # Mongo Explorer plugin
48 | .idea/**/mongoSettings.xml
49 |
50 | # File-based project format
51 | *.iws
52 |
53 | # IntelliJ
54 | out/
55 |
56 | # mpeltonen/sbt-idea plugin
57 | .idea_modules/
58 |
59 | # JIRA plugin
60 | atlassian-ide-plugin.xml
61 |
62 | # Cursive Clojure plugin
63 | .idea/replstate.xml
64 |
65 | # Crashlytics plugin (for Android Studio and IntelliJ)
66 | com_crashlytics_export_strings.xml
67 | crashlytics.properties
68 | crashlytics-build.properties
69 | fabric.properties
70 |
71 | # Editor-based Rest Client
72 | .idea/httpRequests
73 |
74 | # Android studio 3.1+ serialized cache file
75 | .idea/caches/build_file_checksums.ser
76 |
77 | ### Intellij+all Patch ###
78 | # Ignores the whole .idea folder and all .iml files
79 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
80 |
81 | .idea/
82 |
83 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
84 |
85 | *.iml
86 | modules.xml
87 | .idea/misc.xml
88 | *.ipr
89 |
90 | # Sonarlint plugin
91 | .idea/sonarlint
92 |
93 | ### macOS ###
94 | # General
95 | .DS_Store
96 | .AppleDouble
97 | .LSOverride
98 |
99 | # Icon must end with two \r
100 | Icon
101 |
102 |
103 | # Thumbnails
104 | ._*
105 |
106 | # Files that might appear in the root of a volume
107 | .DocumentRevisions-V100
108 | .fseventsd
109 | .Spotlight-V100
110 | .TemporaryItems
111 | .Trashes
112 | .VolumeIcon.icns
113 | .com.apple.timemachine.donotpresent
114 |
115 | # Directories potentially created on remote AFP share
116 | .AppleDB
117 | .AppleDesktop
118 | Network Trash Folder
119 | Temporary Items
120 | .apdisk
121 |
122 | ### PyCharm+all ###
123 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
124 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
125 |
126 | # User-specific stuff
127 |
128 | # Generated files
129 |
130 | # Sensitive or high-churn files
131 |
132 | # Gradle
133 |
134 | # Gradle and Maven with auto-import
135 | # When using Gradle or Maven with auto-import, you should exclude module files,
136 | # since they will be recreated, and may cause churn. Uncomment if using
137 | # auto-import.
138 | # .idea/artifacts
139 | # .idea/compiler.xml
140 | # .idea/jarRepositories.xml
141 | # .idea/modules.xml
142 | # .idea/*.iml
143 | # .idea/modules
144 | # *.iml
145 | # *.ipr
146 |
147 | # CMake
148 |
149 | # Mongo Explorer plugin
150 |
151 | # File-based project format
152 |
153 | # IntelliJ
154 |
155 | # mpeltonen/sbt-idea plugin
156 |
157 | # JIRA plugin
158 |
159 | # Cursive Clojure plugin
160 |
161 | # Crashlytics plugin (for Android Studio and IntelliJ)
162 |
163 | # Editor-based Rest Client
164 |
165 | # Android studio 3.1+ serialized cache file
166 |
167 | ### PyCharm+all Patch ###
168 | # Ignores the whole .idea folder and all .iml files
169 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
170 |
171 |
172 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
173 |
174 |
175 | # Sonarlint plugin
176 |
177 | ### Python ###
178 | # Byte-compiled / optimized / DLL files
179 | __pycache__/
180 | *.py[cod]
181 | *$py.class
182 |
183 | # C extensions
184 | *.so
185 |
186 | # Distribution / packaging
187 | .Python
188 | build/
189 | develop-eggs/
190 | dist/
191 | downloads/
192 | eggs/
193 | .eggs/
194 | parts/
195 | sdist/
196 | var/
197 | wheels/
198 | pip-wheel-metadata/
199 | share/python-wheels/
200 | *.egg-info/
201 | .installed.cfg
202 | *.egg
203 | MANIFEST
204 |
205 | # PyInstaller
206 | # Usually these files are written by a python script from a template
207 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
208 | *.manifest
209 | *.spec
210 |
211 | # Installer logs
212 | pip-log.txt
213 | pip-delete-this-directory.txt
214 |
215 | # Unit test / coverage reports
216 | htmlcov/
217 | .tox/
218 | .nox/
219 | .coverage
220 | .coverage.*
221 | .cache
222 | nosetests.xml
223 | coverage.xml
224 | *.cover
225 | *.py,cover
226 | .hypothesis/
227 | .pytest_cache/
228 | pytestdebug.log
229 |
230 | # Translations
231 | *.mo
232 | *.pot
233 |
234 | # Django stuff:
235 | *.log
236 | local_settings.py
237 | db.sqlite3
238 | db.sqlite3-journal
239 |
240 | # Flask stuff:
241 | instance/
242 | .webassets-cache
243 |
244 | # Scrapy stuff:
245 | .scrapy
246 |
247 | # Sphinx documentation
248 | docs/_build/
249 | doc/_build/
250 |
251 | # PyBuilder
252 | target/
253 |
254 | # Jupyter Notebook
255 | .ipynb_checkpoints
256 |
257 | # IPython
258 | profile_default/
259 | ipython_config.py
260 |
261 | # pyenv
262 | .python-version
263 |
264 | # pipenv
265 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
266 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
267 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
268 | # install all needed dependencies.
269 | #Pipfile.lock
270 |
271 | # poetry
272 | #poetry.lock
273 |
274 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
275 | __pypackages__/
276 |
277 | # Celery stuff
278 | celerybeat-schedule
279 | celerybeat.pid
280 |
281 | # SageMath parsed files
282 | *.sage.py
283 |
284 | # Environments
285 | # .env
286 | .env/
287 | .venv/
288 | env/
289 | venv/
290 | ENV/
291 | env.bak/
292 | venv.bak/
293 | pythonenv*
294 |
295 | # Spyder project settings
296 | .spyderproject
297 | .spyproject
298 |
299 | # Rope project settings
300 | .ropeproject
301 |
302 | # mkdocs documentation
303 | /site
304 |
305 | # mypy
306 | .mypy_cache/
307 | .dmypy.json
308 | dmypy.json
309 |
310 | # Pyre type checker
311 | .pyre/
312 |
313 | # pytype static type analyzer
314 | .pytype/
315 |
316 | # operating system-related files
317 | *.DS_Store #file properties cache/storage on macOS
318 | Thumbs.db #thumbnail cache on Windows
319 |
320 | # profiling data
321 | .prof
322 |
323 |
324 | ### Windows ###
325 | # Windows thumbnail cache files
326 | Thumbs.db
327 | Thumbs.db:encryptable
328 | ehthumbs.db
329 | ehthumbs_vista.db
330 |
331 | # Dump file
332 | *.stackdump
333 |
334 | # Folder config file
335 | [Dd]esktop.ini
336 |
337 | # Recycle Bin used on file shares
338 | $RECYCLE.BIN/
339 |
340 | # Windows Installer files
341 | *.cab
342 | *.msi
343 | *.msix
344 | *.msm
345 | *.msp
346 |
347 | # Windows shortcuts
348 | *.lnk
349 |
350 | # End of https://www.toptal.com/developers/gitignore/api/intellij+all,python,pycharm+all,macos,windows
351 |
352 | printdens.py
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2025 John Howe
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.
22 |
--------------------------------------------------------------------------------
/README-en.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | **Auto slice the highlight shorts** based on the density of danmaku.
8 |
9 | English | [简体中文](./README-zh.md)
10 |
11 |
12 |
13 | ## Introduction
14 |
15 | > If you think the project is good, welcome ⭐ also welcome PR cooperation, if you have any questions, please raise an issue for discussion.
16 |
17 | A video automatic slicing tool that supports GPU acceleration calculation, command line usage, and API usage.
18 |
19 | ## Features
20 |
21 | - Detect the dense period of danmaku based on the sliding window algorithm.
22 | - Slice the video based on the density of danmaku.
23 | - Support GPU accelerated calculation.([Automatically choose whether to use GPU acceleration](#why-i-cannot-use-the-gpu-acceleration))
24 | - Support custom quantity slicing videos.
25 | - Support custom slice duration.
26 | - Add detailed log information.
27 | - Support cli usage and api usage.
28 |
29 | ## Demo
30 |
31 | 
32 |
33 | As shown above, extract 3 highlight videos from a video, each video is 300 seconds long, and the maximum overlap is 60 seconds. Then calculate and slice out 3 highlight videos. The format is `xxxs_original video name`, `xxx` represents the starting time of the slice in the original video, which is convenient for the user to locate.
34 |
35 | ## Installation
36 |
37 | To use this tool, you need to install ffmpeg first.
38 |
39 | - Windows: `choco install ffmpeg` (via [Chocolatey](https://chocolatey.org/)) or other methods.
40 | - macOS: `brew install ffmpeg` (via [Homebrew](https://brew.sh/)).
41 | - Linux: `sudo apt install ffmpeg` (Debian/Ubuntu).
42 |
43 | More OS please refer to the [official website](https://ffmpeg.org/download.html).
44 |
45 | Then install the `autosv` package.
46 |
47 | ```bash
48 | pip install autosv
49 | ```
50 |
51 | ## Usage
52 |
53 | ### cli usage
54 |
55 | ```bash
56 | # eg. The default parameters are shown in autosv -h
57 | autosv -a sample.ass -v sample.mp4
58 | autosv -a sample.ass -v sample.mp4 -d 300 -n 3 --overlap 60 --step 1
59 | autosv -h
60 | # optional arguments:
61 | # -h, --help show this help message and exit
62 | # -V, --version Print version information
63 | # -a ASS, --ass ASS The input ass file of the danmaku
64 | # -v VIDEO, --video VIDEO
65 | # The input video file
66 | # -d DURATION, --duration DURATION
67 | # The duration(seconds) of the sliced highlight video, default is 60
68 | # -n TOP_N, --top_n TOP_N
69 | # The number of the top dense periods to return, default is 1
70 | # --overlap OVERLAP The overlapped(seconds) between the sliced highlight videos, default is 30
71 | # --step STEP The step(seconds) of the sliding window, default is 1
72 | ```
73 |
74 | ### api usage
75 |
76 | ```python
77 | from autosv import slice_video_by_danmaku
78 | # The default parameters are the same as the cli usage
79 | slice_video_by_danmaku(ass_path, video_path, duration=300, top_n=3, max_overlap=60, step=1)
80 | ```
81 |
82 | ## common issues
83 |
84 | ### What is the difference between cpu and gpu implementation?
85 |
86 | Generally speaking, the gpu implementation is faster and more efficient than the cpu implementation due to the parallel computing. In my practice, when the input data is around 30k(Try `test/sample2.ass`), the gpu implementation only takes 2 seconds, while the cpu implementation takes 33 seconds, which is 16.5 times faster with only 55 MB VRAM occupied.
87 |
88 | ### Why I cannot use the gpu acceleration?
89 |
90 | The autosv will detect whether the cuda is available on the machine via `nvcc -V`, if your machine has nvidia gpu, please make sure your driver is installed and the cuda is available. Meanwhile, make sure you have installed the `numba` and `numpy` with the right version.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |