mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-26 08:48:03 +00:00
Remove comfy submodule
test commit remove submodule Add ComfyUI @ c5a369a33ddb622827552716d9b0119035a2e666 Comfy upstream SHA: c5a369a33ddb622827552716d9b0119035a2e666 add custom node dependnencies add large checkpoint for comfyui
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
# VIM swap files
|
||||
*.swp
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,110 @@
|
||||
# ComfyUI-VideoHelperSuite
|
||||
Nodes related to video workflows
|
||||
|
||||
## I/O Nodes
|
||||
### Load Video
|
||||
Converts a video file into a series of images
|
||||
- video: The video file to be loaded
|
||||
- force_rate: Discards or duplicates frames as needed to hit a target frame rate. Disabled by setting to 0. This can be used to quickly match a suggested frame rate like the 8 fps of AnimateDiff.
|
||||
- force_size: Allows for quick resizing to a number of suggested sizes. Several options allow you to set only width or height and determine the other from aspect ratio.
|
||||
- frame_load_cap: The maximum number of frames which will be returned. This could also be thought of as the maximum batch size.
|
||||
- skip_first_frames: How many frames to skip from the start of the video after adjusting for a forced frame rate. By incrementing this number by the frame_load_cap, you can easily process a longer input video in parts.
|
||||
- select_every_nth: Allows for skipping a number of frames without considering the base frame rate or risking frame duplication. Often useful when working with animated gifs
|
||||
A path variant of the Load Video node exists that allows loading videos from external paths
|
||||

|
||||

|
||||
If [Advanced Previews](#advanced-previews) is enabled in the options menu of the web ui, the preview will reflect the current settings on the node.
|
||||
### Load Image Sequence
|
||||
Loads all image files from a subfolder. Options are similar to Load Video.
|
||||
- image_load_cap: The maximum number of images which will be returned. This could also be thought of as the maximum batch size.
|
||||
- skip_first_images: How many images to skip. By incrementing this number by image_load_cap, you can easily divide a long sequence of images into multiple batches.
|
||||
- select_every_nth: Allows for skipping a number of images between every returned frame.
|
||||
|
||||
A path variant of Load Image sequence also exists.
|
||||
### Video Combine
|
||||
Combines a series of images into an output video
|
||||
If the optional audio input is provided, it will also be combined into the output video
|
||||
- frame_rate: How many of the input frames are displayed per second. A higher frame rate means that the output video plays faster and has less duration. This should usually be kept to 8 for AnimateDiff, or matched to the force_rate of a Load Video node.
|
||||
- loop_count: How many additional times the video should repeat
|
||||
- filename_prefix: The base file name used for output.
|
||||
- You can save output to a subfolder: `subfolder/video`
|
||||
- Like the builtin Save Image node, you can add timestamps. `%date:yyyy-MM-ddThh:mm:ss%` might become 2023-10-31T6:45:25
|
||||
- format: The file format to use. Advanced information on configuring or adding additional video formats can be found in the [Video Formats](#video-formats) section.
|
||||
- pingpong: Causes the input to be played back in the reverse to create a clean loop.
|
||||
- save_output: Whether the image should be put into the output directory or the temp directory.
|
||||
Returns: a `VHS_FILENAMES` which consists of a boolean indicating if save_output is enabled and a list of the full filepaths of all generated outputs in the order created. Accordingly `output[1][-1]` will be the most complete output.
|
||||
|
||||
Depending on the format chosen, additional options may become available, including
|
||||
- crf: Describes the quality of the output video. A lower number gives a higher quality video and a larger file size, while a higher number gives a lower quality video with a smaller size. Scaling varies by codec, but visually lossless output generally occurs around 20.
|
||||
- save_metadata: Includes a copy of the workflow in the ouput video which can be loaded by dragging and dropping the video, just like with images.
|
||||
- pix_fmt: Changes how the pixel data is stored. `yuv420p10le` has higher color quality, but won't work on all devices
|
||||
### Load Audio
|
||||
Provides a way to load standalone audio files.
|
||||
- seek_seconds: An optional start time for the audio file in seconds.
|
||||
|
||||
## Latent/Image Nodes
|
||||
A number of utility nodes exist for managing latents. For each, there is an equivalent node which works on images.
|
||||
### Split Batch
|
||||
Divides the latents into two sets. The first `split_index` latents go to ouput A and the remainder to output B. If less then `split_index` latents are provided as input, all are passed to output A and output B is empty.
|
||||
### Merge Batch
|
||||
Combines two groups of latents into a single output. The order of the output is the latents in A followed by the latents in B.
|
||||
If the input groups are not the same size, the node provides options for rescaling the latents before merging.
|
||||
### Select Every Nth
|
||||
The first of every `select_every_nth` input is passed and the remainder are discarded
|
||||
### Get Count
|
||||
### Duplicate Batch
|
||||
|
||||
## Video Previews
|
||||
Load Video (Upload), Load Video (Path), Load Images (Upload), Load Images (Path) and Video Combine provide animated previews.
|
||||
Nodes with previews provide additional functionality when right clicked
|
||||
- Open preview
|
||||
- Save preview
|
||||
- Pause preview: Can improve performance with very large videos
|
||||
- Hide preview: Can improve performance, save space
|
||||
- Sync preview: Restarts all previews for side-by-side comparisons
|
||||
|
||||
### Advanced Previews
|
||||
Advanced Previews must be manually enabled by clicking the settings gear next to Queue Prompt and checking the box for VHS Advanced Previews.
|
||||
If enabled, videos which are displayed in the ui will be converted with ffmpeg on request. This has several benefits
|
||||
- Previews for Load Video nodes will reflect the settings on the node such as skip_first_frames and frame_load_cap
|
||||
- This makes it easy to select an exact portion of an input video and sync it with outputs
|
||||
- It can use substantially less bandwidth if running the server remotely
|
||||
- It can greatly improve the browser performance by downsizing videos to the in ui resolution, particularly useful with animated gifs
|
||||
- It allows for previews of videos that would not normally be playable in browser.
|
||||
- Can be limited to subdirectories of ComyUI if `VHS_STRICT_PATHS` is set as an environment variable.
|
||||
|
||||
This fucntionality is disabled since it comes with several downsides
|
||||
- There is a delay before videos show in the browser. This delay can become quite large if the input video is long
|
||||
- The preview videos are lower quality (The original can always be viewed with Right Click -> Open preview)
|
||||
|
||||
## Video Formats
|
||||
Those familiar with ffmpeg are able to add json files to the video_formats folders to add new output types to Video Combine.
|
||||
Consider the following example for av1-webm
|
||||
```json
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "libsvtav1",
|
||||
"-pix_fmt", "yuv420p10le",
|
||||
"-crf", ["crf","INT", {"default": 23, "min": 0, "max": 100, "step": 1}]
|
||||
],
|
||||
"audio_pass": ["-c:a", "libopus"],
|
||||
"extension": "webm",
|
||||
"environment": {"SVT_LOG": "1"}
|
||||
}
|
||||
```
|
||||
Most configuration takes place in `main_pass`, which is a list of arguments that are passed to ffmpeg.
|
||||
- `"-n"` designates that the command should fail if a file of the same name already exists. This should never happen, but if some bug were to occur, it would ensure other files aren't overwritten.
|
||||
- `"-c:v", "libsvtav1"` designates that the video should be encoded with an av1 codec using the new SVT-AV1 encoder. SVT-AV1 is much faster than libaom-av1, but may not exist in older versions of ffmpeg. Alternatively, av1_nvenc could be used for gpu encoding with newer nvidia cards.
|
||||
- `"-pix_fmt", "yuv420p10le"` designates the standard pixel format with 10-bit color. It's important that some pixel format be specified to ensure a nonconfigurable input pix_fmt isn't used.
|
||||
|
||||
`audio pass` contains a list of arguments which are passed to ffmpeg when audio is passed into Video Combine
|
||||
|
||||
`extension` designates both the file extension and the container format that is used. If some of the above options are omitted from `main_pass` it can affect what default options are chosen.
|
||||
`environment` can optionally be provided to set environment variables during execution. For av1 it's used to reduce the verbosity of logging so that only major errors are displayed.
|
||||
`input_color_depth` effects the format in which pixels are passed to the ffmpeg subprocess. Current valid options are `8bit` and `16bit`. The later will produce higher quality output, but is experimental.
|
||||
|
||||
Fields can be exposed in the webui as a widget using a format similar to what is used in the creation of custom nodes. In the above example, the argument for `-crf` will be exposed as a format widget in the webui. Format widgets are a list of up to 3 terms
|
||||
- The name of the widget that will be displayed in the web ui
|
||||
- Either a primitive such as "INT" or "BOOLEAN", or a list of string options
|
||||
- A dictionary of options
|
||||
@@ -0,0 +1,6 @@
|
||||
from .videohelpersuite.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
import folder_paths
|
||||
from .videohelpersuite.server import server
|
||||
|
||||
WEB_DIRECTORY = "./web"
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
|
||||
@@ -0,0 +1,2 @@
|
||||
opencv-python
|
||||
imageio-ffmpeg
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n",
|
||||
"-pix_fmt", "rgba64"
|
||||
],
|
||||
"input_color_depth": "16bit",
|
||||
"extension": "%03d.png"
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "prores_ks",
|
||||
"-profile:v","3",
|
||||
"-pix_fmt", "yuv422p10"
|
||||
],
|
||||
"audio_pass": ["-c:a", "pcm_s16le"],
|
||||
"extension": "mov"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "libsvtav1",
|
||||
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
|
||||
"-crf", ["crf","INT", {"default": 23, "min": 0, "max": 100, "step": 1}]
|
||||
],
|
||||
"audio_pass": ["-c:a", "libopus"],
|
||||
"input_color_depth": ["input_color_depth", ["8bit", "16bit"]],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "webm",
|
||||
"environment": {"SVT_LOG": "1"}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "libx264",
|
||||
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
|
||||
"-crf", ["crf","INT", {"default": 19, "min": 0, "max": 100, "step": 1}]
|
||||
],
|
||||
"audio_pass": ["-c:a", "aac"],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "mp4"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "libx265",
|
||||
"-vtag", "hvc1",
|
||||
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
|
||||
"-crf", ["crf","INT", {"default": 22, "min": 0, "max": 100, "step": 1}],
|
||||
"-preset", "medium",
|
||||
"-x265-params", "log-level=quiet"
|
||||
],
|
||||
"audio_pass": ["-c:a", "aac"],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "mp4"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "h264_nvenc",
|
||||
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]]
|
||||
],
|
||||
"audio_pass": ["-c:a", "aac"],
|
||||
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
|
||||
"megabit": ["megabit","BOOLEAN", {"default": true}],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "mp4"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n", "-c:v", "hevc_nvenc",
|
||||
"-vtag", "hvc1",
|
||||
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]]
|
||||
],
|
||||
"audio_pass": ["-c:a", "aac"],
|
||||
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
|
||||
"megabit": ["megabit","BOOLEAN", {"default": true}],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "mp4"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"main_pass":
|
||||
[
|
||||
"-n",
|
||||
"-pix_fmt", "yuv420p",
|
||||
"-crf", ["crf","INT", {"default": 20, "min": 0, "max": 100, "step": 1}],
|
||||
"-b:v", "0"
|
||||
],
|
||||
"audio_pass": ["-c:a", "libvorbis"],
|
||||
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
|
||||
"extension": "webm"
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import torch
|
||||
from nodes import VAEEncode
|
||||
|
||||
|
||||
class VAEDecodeBatched:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"samples": ("LATENT", ),
|
||||
"vae": ("VAE", ),
|
||||
"per_batch": ("INT", {"default": 16, "min": 1})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "decode"
|
||||
|
||||
def decode(self, vae, samples, per_batch):
|
||||
decoded = []
|
||||
for start_idx in range(0, samples["samples"].shape[0], per_batch):
|
||||
decoded.append(vae.decode(samples["samples"][start_idx:start_idx+per_batch]))
|
||||
return (torch.cat(decoded, dim=0), )
|
||||
|
||||
|
||||
class VAEEncodeBatched:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"pixels": ("IMAGE", ), "vae": ("VAE", ),
|
||||
"per_batch": ("INT", {"default": 16, "min": 1})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
|
||||
|
||||
RETURN_TYPES = ("LATENT",)
|
||||
FUNCTION = "encode"
|
||||
|
||||
def encode(self, vae, pixels, per_batch):
|
||||
t = []
|
||||
for start_idx in range(0, pixels.shape[0], per_batch):
|
||||
sub_pixels = VAEEncode.vae_encode_crop_pixels(pixels[start_idx:start_idx+per_batch])
|
||||
t.append(vae.encode(sub_pixels[:,:,:,:3]))
|
||||
return ({"samples": torch.cat(t, dim=0)}, )
|
||||
+456
@@ -0,0 +1,456 @@
|
||||
from torch import Tensor
|
||||
import torch
|
||||
|
||||
import comfy.utils
|
||||
|
||||
|
||||
class MergeStrategies:
|
||||
MATCH_A = "match A"
|
||||
MATCH_B = "match B"
|
||||
MATCH_SMALLER = "match smaller"
|
||||
MATCH_LARGER = "match larger"
|
||||
|
||||
list_all = [MATCH_A, MATCH_B, MATCH_SMALLER, MATCH_LARGER]
|
||||
|
||||
|
||||
class ScaleMethods:
|
||||
NEAREST_EXACT = "nearest-exact"
|
||||
BILINEAR = "bilinear"
|
||||
AREA = "area"
|
||||
BICUBIC = "bicubic"
|
||||
BISLERP = "bislerp"
|
||||
|
||||
list_all = [NEAREST_EXACT, BILINEAR, AREA, BICUBIC, BISLERP]
|
||||
|
||||
|
||||
class CropMethods:
|
||||
DISABLED = "disabled"
|
||||
CENTER = "center"
|
||||
|
||||
list_all = [DISABLED, CENTER]
|
||||
|
||||
|
||||
class SplitLatents:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"latents": ("LATENT",),
|
||||
"split_index": ("INT", {"default": 0, "step": 1, "min": -99999999999}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
|
||||
|
||||
RETURN_TYPES = ("LATENT", "INT", "LATENT", "INT")
|
||||
RETURN_NAMES = ("LATENT_A", "A_count", "LATENT_B", "B_count")
|
||||
FUNCTION = "split_latents"
|
||||
|
||||
def split_latents(self, latents: dict, split_index: int):
|
||||
latents = latents.copy()
|
||||
group_a = latents["samples"][:split_index]
|
||||
group_b = latents["samples"][split_index:]
|
||||
group_a_latent = {"samples": group_a}
|
||||
group_b_latent = {"samples": group_b}
|
||||
return (group_a_latent, group_a.size(0), group_b_latent, group_b.size(0))
|
||||
|
||||
|
||||
class SplitImages:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"split_index": ("INT", {"default": 0, "step": 1, "min": -99999999999}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT", "IMAGE", "INT")
|
||||
RETURN_NAMES = ("IMAGE_A", "A_count", "IMAGE_B", "B_count")
|
||||
FUNCTION = "split_images"
|
||||
|
||||
def split_images(self, images: Tensor, split_index: int):
|
||||
group_a = images[:split_index]
|
||||
group_b = images[split_index:]
|
||||
return (group_a, group_a.size(0), group_b, group_b.size(0))
|
||||
|
||||
|
||||
class SplitMasks:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"mask": ("MASK",),
|
||||
"split_index": ("INT", {"default": 0, "step": 1, "min": -99999999999}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
|
||||
|
||||
RETURN_TYPES = ("MASK", "INT", "MASK", "INT")
|
||||
RETURN_NAMES = ("MASK_A", "A_count", "MASK_B", "B_count")
|
||||
FUNCTION = "split_masks"
|
||||
|
||||
def split_masks(self, mask: Tensor, split_index: int):
|
||||
group_a = mask[:split_index]
|
||||
group_b = mask[split_index:]
|
||||
return (group_a, group_a.size(0), group_b, group_b.size(0))
|
||||
|
||||
|
||||
class MergeLatents:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"latents_A": ("LATENT",),
|
||||
"latents_B": ("LATENT",),
|
||||
"merge_strategy": (MergeStrategies.list_all,),
|
||||
"scale_method": (ScaleMethods.list_all,),
|
||||
"crop": (CropMethods.list_all,),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
|
||||
|
||||
RETURN_TYPES = ("LATENT", "INT",)
|
||||
RETURN_NAMES = ("LATENT", "count",)
|
||||
FUNCTION = "merge"
|
||||
|
||||
def merge(self, latents_A: dict, latents_B: dict, merge_strategy: str, scale_method: str, crop: str):
|
||||
latents = []
|
||||
latents_A = latents_A.copy()["samples"]
|
||||
latents_B = latents_B.copy()["samples"]
|
||||
|
||||
# if not same dimensions, do scaling
|
||||
if latents_A.shape[3] != latents_B.shape[3] or latents_A.shape[2] != latents_B.shape[2]:
|
||||
A_size = latents_A.shape[3] * latents_A.shape[2]
|
||||
B_size = latents_B.shape[3] * latents_B.shape[2]
|
||||
# determine which to use
|
||||
use_A_as_template = True
|
||||
if merge_strategy == MergeStrategies.MATCH_A:
|
||||
pass
|
||||
elif merge_strategy == MergeStrategies.MATCH_B:
|
||||
use_A_as_template = False
|
||||
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
|
||||
if A_size <= B_size:
|
||||
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
|
||||
# apply scaling
|
||||
if use_A_as_template:
|
||||
latents_B = comfy.utils.common_upscale(latents_B, latents_A.shape[3], latents_A.shape[2], scale_method, crop)
|
||||
else:
|
||||
latents_A = comfy.utils.common_upscale(latents_A, latents_B.shape[3], latents_B.shape[2], scale_method, crop)
|
||||
|
||||
latents.append(latents_A)
|
||||
latents.append(latents_B)
|
||||
|
||||
merged = {"samples": torch.cat(latents, dim=0)}
|
||||
return (merged, len(merged["samples"]),)
|
||||
|
||||
|
||||
class MergeImages:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"images_A": ("IMAGE",),
|
||||
"images_B": ("IMAGE",),
|
||||
"merge_strategy": (MergeStrategies.list_all,),
|
||||
"scale_method": (ScaleMethods.list_all,),
|
||||
"crop": (CropMethods.list_all,),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT",)
|
||||
RETURN_NAMES = ("IMAGE", "count",)
|
||||
FUNCTION = "merge"
|
||||
|
||||
def merge(self, images_A: Tensor, images_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
|
||||
images = []
|
||||
# if not same dimensions, do scaling
|
||||
if images_A.shape[3] != images_B.shape[3] or images_A.shape[2] != images_B.shape[2]:
|
||||
images_A = images_A.movedim(-1,1)
|
||||
images_B = images_B.movedim(-1,1)
|
||||
|
||||
A_size = images_A.shape[3] * images_A.shape[2]
|
||||
B_size = images_B.shape[3] * images_B.shape[2]
|
||||
# determine which to use
|
||||
use_A_as_template = True
|
||||
if merge_strategy == MergeStrategies.MATCH_A:
|
||||
pass
|
||||
elif merge_strategy == MergeStrategies.MATCH_B:
|
||||
use_A_as_template = False
|
||||
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
|
||||
if A_size <= B_size:
|
||||
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
|
||||
# apply scaling
|
||||
if use_A_as_template:
|
||||
images_B = comfy.utils.common_upscale(images_B, images_A.shape[3], images_A.shape[2], scale_method, crop)
|
||||
else:
|
||||
images_A = comfy.utils.common_upscale(images_A, images_B.shape[3], images_B.shape[2], scale_method, crop)
|
||||
images_A = images_A.movedim(1,-1)
|
||||
images_B = images_B.movedim(1,-1)
|
||||
|
||||
images.append(images_A)
|
||||
images.append(images_B)
|
||||
all_images = torch.cat(images, dim=0)
|
||||
return (all_images, all_images.size(0),)
|
||||
|
||||
|
||||
class MergeMasks:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"mask_A": ("MASK",),
|
||||
"mask_B": ("MASK",),
|
||||
"merge_strategy": (MergeStrategies.list_all,),
|
||||
"scale_method": (ScaleMethods.list_all,),
|
||||
"crop": (CropMethods.list_all,),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
|
||||
|
||||
RETURN_TYPES = ("MASK", "INT",)
|
||||
RETURN_NAMES = ("MASK", "count",)
|
||||
FUNCTION = "merge"
|
||||
|
||||
def merge(self, mask_A: Tensor, mask_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
|
||||
masks = []
|
||||
# if not same dimensions, do scaling
|
||||
if mask_A.shape[2] != mask_B.shape[2] or mask_A.shape[1] != mask_B.shape[1]:
|
||||
A_size = mask_A.shape[2] * mask_A.shape[1]
|
||||
B_size = mask_B.shape[2] * mask_B.shape[1]
|
||||
# determine which to use
|
||||
use_A_as_template = True
|
||||
if merge_strategy == MergeStrategies.MATCH_A:
|
||||
pass
|
||||
elif merge_strategy == MergeStrategies.MATCH_B:
|
||||
use_A_as_template = False
|
||||
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
|
||||
if A_size <= B_size:
|
||||
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
|
||||
# add dimension where image channels would be expected to work with common_upscale
|
||||
mask_A = torch.unsqueeze(mask_A, 1)
|
||||
mask_B = torch.unsqueeze(mask_B, 1)
|
||||
# apply scaling
|
||||
if use_A_as_template:
|
||||
mask_B = comfy.utils.common_upscale(mask_B, mask_A.shape[3], mask_A.shape[2], scale_method, crop)
|
||||
else:
|
||||
mask_A = comfy.utils.common_upscale(mask_A, mask_B.shape[3], mask_B.shape[2], scale_method, crop)
|
||||
# undo dimension increase
|
||||
mask_A = torch.squeeze(mask_A, 1)
|
||||
mask_B = torch.squeeze(mask_B, 1)
|
||||
|
||||
masks.append(mask_A)
|
||||
masks.append(mask_B)
|
||||
all_masks = torch.cat(masks, dim=0)
|
||||
return (all_masks, all_masks.size(0),)
|
||||
|
||||
|
||||
class SelectEveryNthLatent:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"latents": ("LATENT",),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
|
||||
|
||||
RETURN_TYPES = ("LATENT", "INT",)
|
||||
RETURN_NAMES = ("LATENT", "count",)
|
||||
FUNCTION = "select_latents"
|
||||
|
||||
def select_latents(self, latents: dict, select_every_nth: int):
|
||||
sub_latents = latents.copy()["samples"][0::select_every_nth]
|
||||
return ({"samples": sub_latents}, sub_latents.size(0))
|
||||
|
||||
|
||||
class SelectEveryNthImage:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT",)
|
||||
RETURN_NAMES = ("IMAGE", "count",)
|
||||
FUNCTION = "select_images"
|
||||
|
||||
def select_images(self, images: Tensor, select_every_nth: int):
|
||||
sub_images = images[0::select_every_nth]
|
||||
return (sub_images, sub_images.size(0))
|
||||
|
||||
|
||||
class SelectEveryNthMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"mask": ("MASK",),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
|
||||
|
||||
RETURN_TYPES = ("MASK", "INT",)
|
||||
RETURN_NAMES = ("MASK", "count",)
|
||||
FUNCTION = "select_masks"
|
||||
|
||||
def select_masks(self, mask: Tensor, select_every_nth: int):
|
||||
sub_mask = mask[0::select_every_nth]
|
||||
return (sub_mask, sub_mask.size(0))
|
||||
|
||||
|
||||
class GetLatentCount:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"latents": ("LATENT",),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
|
||||
|
||||
RETURN_TYPES = ("INT",)
|
||||
RETURN_NAMES = ("count",)
|
||||
FUNCTION = "count_input"
|
||||
|
||||
def count_input(self, latents: dict):
|
||||
return (latents["samples"].size(0),)
|
||||
|
||||
|
||||
class GetImageCount:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
|
||||
|
||||
RETURN_TYPES = ("INT",)
|
||||
RETURN_NAMES = ("count",)
|
||||
FUNCTION = "count_input"
|
||||
|
||||
def count_input(self, images: Tensor):
|
||||
return (images.size(0),)
|
||||
|
||||
|
||||
class GetMaskCount:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"mask": ("MASK",),
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
|
||||
|
||||
RETURN_TYPES = ("INT",)
|
||||
RETURN_NAMES = ("count",)
|
||||
FUNCTION = "count_input"
|
||||
|
||||
def count_input(self, mask: Tensor):
|
||||
return (mask.size(0),)
|
||||
|
||||
|
||||
class DuplicateLatents:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"latents": ("LATENT",),
|
||||
"multiply_by": ("INT", {"default": 1, "min": 1, "step": 1})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
|
||||
|
||||
RETURN_TYPES = ("LATENT", "INT",)
|
||||
RETURN_NAMES = ("LATENT", "count",)
|
||||
FUNCTION = "duplicate_input"
|
||||
|
||||
def duplicate_input(self, latents: dict[str, Tensor], multiply_by: int):
|
||||
new_latents = latents.copy()
|
||||
full_latents = []
|
||||
for n in range(0, multiply_by):
|
||||
full_latents.append(new_latents["samples"])
|
||||
new_latents["samples"] = torch.cat(full_latents, dim=0)
|
||||
return (new_latents, new_latents["samples"].size(0),)
|
||||
|
||||
|
||||
class DuplicateImages:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"multiply_by": ("INT", {"default": 1, "min": 1, "step": 1})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT",)
|
||||
RETURN_NAMES = ("IMAGE", "count",)
|
||||
FUNCTION = "duplicate_input"
|
||||
|
||||
def duplicate_input(self, images: Tensor, multiply_by: int):
|
||||
full_images = []
|
||||
for n in range(0, multiply_by):
|
||||
full_images.append(images)
|
||||
new_images = torch.cat(full_images, dim=0)
|
||||
return (new_images, new_images.size(0),)
|
||||
|
||||
|
||||
class DuplicateMasks:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"mask": ("MASK",),
|
||||
"multiply_by": ("INT", {"default": 1, "min": 1, "step": 1})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
|
||||
|
||||
RETURN_TYPES = ("MASK", "INT",)
|
||||
RETURN_NAMES = ("MASK", "count",)
|
||||
FUNCTION = "duplicate_input"
|
||||
|
||||
def duplicate_input(self, mask: Tensor, multiply_by: int):
|
||||
full_masks = []
|
||||
for n in range(0, multiply_by):
|
||||
full_masks.append(mask)
|
||||
new_mask = torch.cat(full_masks, dim=0)
|
||||
return (new_mask, new_mask.size(0),)
|
||||
|
||||
|
||||
# class SelectLatents:
|
||||
# @classmethod
|
||||
# def INPUT_TYPES(s):
|
||||
# return {
|
||||
# "required": {
|
||||
# "images": ("IMAGE",),
|
||||
# "select_indeces": ("STRING", {"default": ""}),
|
||||
# },
|
||||
# }
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
import os
|
||||
import hashlib
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
import folder_paths
|
||||
from comfy.k_diffusion.utils import FolderOfImages
|
||||
from .logger import logger
|
||||
from .utils import calculate_file_hash, get_sorted_dir_files_from_directory, validate_path
|
||||
|
||||
|
||||
def is_changed_load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1):
|
||||
if not os.path.isdir(directory):
|
||||
return False
|
||||
|
||||
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
|
||||
if image_load_cap != 0:
|
||||
dir_files = dir_files[:image_load_cap]
|
||||
|
||||
m = hashlib.sha256()
|
||||
for filepath in dir_files:
|
||||
m.update(calculate_file_hash(filepath).encode()) # strings must be encoded before hashing
|
||||
return m.digest().hex()
|
||||
|
||||
|
||||
def validate_load_images(directory: str):
|
||||
if not os.path.isdir(directory):
|
||||
return f"Directory '{directory}' cannot be found."
|
||||
dir_files = os.listdir(directory)
|
||||
if len(dir_files) == 0:
|
||||
return f"No files in directory '{directory}'."
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1):
|
||||
if not os.path.isdir(directory):
|
||||
raise FileNotFoundError(f"Directory '{directory} cannot be found.")
|
||||
|
||||
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
|
||||
|
||||
if len(dir_files) == 0:
|
||||
raise FileNotFoundError(f"No files in directory '{directory}'.")
|
||||
|
||||
images = []
|
||||
masks = []
|
||||
|
||||
limit_images = False
|
||||
if image_load_cap > 0:
|
||||
limit_images = True
|
||||
image_count = 0
|
||||
loaded_alpha = False
|
||||
zero_mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
|
||||
|
||||
for image_path in dir_files:
|
||||
if limit_images and image_count >= image_load_cap:
|
||||
break
|
||||
i = Image.open(image_path)
|
||||
i = ImageOps.exif_transpose(i)
|
||||
image = i.convert("RGB")
|
||||
image = np.array(image).astype(np.float32) / 255.0
|
||||
image = torch.from_numpy(image)[None,]
|
||||
if 'A' in i.getbands():
|
||||
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(mask)
|
||||
if not loaded_alpha:
|
||||
loaded_alpha = True
|
||||
zero_mask = torch.zeros((len(image[0]),len(image[0][0])), dtype=torch.float32, device="cpu")
|
||||
masks = [zero_mask] * image_count
|
||||
else:
|
||||
mask = zero_mask
|
||||
images.append(image)
|
||||
masks.append(mask)
|
||||
image_count += 1
|
||||
|
||||
if len(images) == 0:
|
||||
raise FileNotFoundError(f"No images could be loaded from directory '{directory}'.")
|
||||
|
||||
return (torch.cat(images, dim=0), torch.stack(masks, dim=0), image_count)
|
||||
|
||||
|
||||
class LoadImagesFromDirectoryUpload:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
input_dir = folder_paths.get_input_directory()
|
||||
directories = []
|
||||
for item in os.listdir(input_dir):
|
||||
if not os.path.isfile(os.path.join(input_dir, item)) and item != "clipspace":
|
||||
directories.append(item)
|
||||
return {
|
||||
"required": {
|
||||
"directory": (directories,),
|
||||
},
|
||||
"optional": {
|
||||
"image_load_cap": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"skip_first_images": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK", "INT")
|
||||
FUNCTION = "load_images"
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
|
||||
def load_images(self, directory: str, **kwargs):
|
||||
directory = folder_paths.get_annotated_filepath(directory.strip())
|
||||
return load_images(directory, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, directory: str, **kwargs):
|
||||
directory = folder_paths.get_annotated_filepath(directory.strip())
|
||||
return is_changed_load_images(directory, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(s, directory: str, **kwargs):
|
||||
directory = folder_paths.get_annotated_filepath(directory.strip())
|
||||
return validate_load_images(directory)
|
||||
|
||||
|
||||
class LoadImagesFromDirectoryPath:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"directory": ("STRING", {"default": "X://path/to/images", "vhs_path_extensions": []}),
|
||||
},
|
||||
"optional": {
|
||||
"image_load_cap": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"skip_first_images": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK", "INT")
|
||||
FUNCTION = "load_images"
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
|
||||
def load_images(self, directory: str, **kwargs):
|
||||
if directory is None or validate_load_images(directory) != True:
|
||||
raise Exception("directory is not valid: " + directory)
|
||||
|
||||
return load_images(directory, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, directory: str, **kwargs):
|
||||
if directory is None:
|
||||
return "input"
|
||||
return is_changed_load_images(directory, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(s, directory: str, **kwargs):
|
||||
if directory is None:
|
||||
return True
|
||||
return validate_load_images(directory)
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
import os
|
||||
import itertools
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image, ImageOps
|
||||
import cv2
|
||||
|
||||
import folder_paths
|
||||
from comfy.utils import common_upscale
|
||||
from .logger import logger
|
||||
from .utils import calculate_file_hash, get_sorted_dir_files_from_directory, get_audio, lazy_eval, hash_path, validate_path
|
||||
|
||||
|
||||
video_extensions = ['webm', 'mp4', 'mkv', 'gif']
|
||||
|
||||
|
||||
def is_gif(filename) -> bool:
|
||||
file_parts = filename.split('.')
|
||||
return len(file_parts) > 1 and file_parts[-1] == "gif"
|
||||
|
||||
|
||||
def target_size(width, height, force_size, custom_width, custom_height) -> tuple[int, int]:
|
||||
if force_size == "Custom":
|
||||
return (custom_width, custom_height)
|
||||
elif force_size == "Custom Height":
|
||||
force_size = "?x"+str(custom_height)
|
||||
elif force_size == "Custom Width":
|
||||
force_size = str(custom_width)+"x?"
|
||||
|
||||
if force_size != "Disabled":
|
||||
force_size = force_size.split("x")
|
||||
if force_size[0] == "?":
|
||||
width = (width*int(force_size[1]))//height
|
||||
#Limit to a multple of 8 for latent conversion
|
||||
width = int(width)+4 & ~7
|
||||
height = int(force_size[1])
|
||||
elif force_size[1] == "?":
|
||||
height = (height*int(force_size[0]))//width
|
||||
height = int(height)+4 & ~7
|
||||
width = int(force_size[0])
|
||||
else:
|
||||
width = int(force_size[0])
|
||||
height = int(force_size[1])
|
||||
return (width, height)
|
||||
|
||||
def cv_frame_generator(video, force_rate, frame_load_cap, skip_first_frames,
|
||||
select_every_nth, batch_manager=None, unique_id=None):
|
||||
try:
|
||||
video_cap = cv2.VideoCapture(video)
|
||||
if not video_cap.isOpened():
|
||||
raise ValueError(f"{video} could not be loaded with cv.")
|
||||
# set video_cap to look at start_index frame
|
||||
total_frame_count = 0
|
||||
total_frames_evaluated = -1
|
||||
frames_added = 0
|
||||
base_frame_time = 1/video_cap.get(cv2.CAP_PROP_FPS)
|
||||
width = video_cap.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
height = video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||
prev_frame = None
|
||||
if force_rate == 0:
|
||||
target_frame_time = base_frame_time
|
||||
else:
|
||||
target_frame_time = 1/force_rate
|
||||
yield (width, height, target_frame_time)
|
||||
time_offset=target_frame_time - base_frame_time
|
||||
while video_cap.isOpened():
|
||||
if time_offset < target_frame_time:
|
||||
is_returned = video_cap.grab()
|
||||
# if didn't return frame, video has ended
|
||||
if not is_returned:
|
||||
break
|
||||
time_offset += base_frame_time
|
||||
if time_offset < target_frame_time:
|
||||
continue
|
||||
time_offset -= target_frame_time
|
||||
# if not at start_index, skip doing anything with frame
|
||||
total_frame_count += 1
|
||||
if total_frame_count <= skip_first_frames:
|
||||
continue
|
||||
else:
|
||||
total_frames_evaluated += 1
|
||||
|
||||
# if should not be selected, skip doing anything with frame
|
||||
if total_frames_evaluated%select_every_nth != 0:
|
||||
continue
|
||||
|
||||
# opencv loads images in BGR format (yuck), so need to convert to RGB for ComfyUI use
|
||||
# follow up: can videos ever have an alpha channel?
|
||||
# To my testing: No. opencv has no support for alpha
|
||||
unused, frame = video_cap.retrieve()
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
# convert frame to comfyui's expected format
|
||||
# TODO: frame contains no exif information. Check if opencv2 has already applied
|
||||
frame = np.array(frame, dtype=np.float32) / 255.0
|
||||
if prev_frame is not None:
|
||||
inp = yield prev_frame
|
||||
if inp is not None:
|
||||
#ensure the finally block is called
|
||||
return
|
||||
prev_frame = frame
|
||||
frames_added += 1
|
||||
# if cap exists and we've reached it, stop processing frames
|
||||
if frame_load_cap > 0 and frames_added >= frame_load_cap:
|
||||
break
|
||||
if batch_manager is not None:
|
||||
batch_manager.inputs.pop(unique_id)
|
||||
batch_manager.has_closed_inputs = True
|
||||
if prev_frame is not None:
|
||||
yield prev_frame
|
||||
finally:
|
||||
video_cap.release()
|
||||
|
||||
def load_video_cv(video: str, force_rate: int, force_size: str,
|
||||
custom_width: int,custom_height: int, frame_load_cap: int,
|
||||
skip_first_frames: int, select_every_nth: int,
|
||||
batch_manager=None, unique_id=None):
|
||||
if batch_manager is None or unique_id not in batch_manager.inputs:
|
||||
gen = cv_frame_generator(video, force_rate, frame_load_cap, skip_first_frames,
|
||||
select_every_nth, batch_manager, unique_id)
|
||||
(width, height, target_frame_time) = next(gen)
|
||||
width = int(width)
|
||||
height = int(height)
|
||||
if batch_manager is not None:
|
||||
batch_manager.inputs[unique_id] = (gen, width, height, target_frame_time)
|
||||
else:
|
||||
(gen, width, height, target_frame_time) = batch_manager.inputs[unique_id]
|
||||
if batch_manager is not None:
|
||||
gen = itertools.islice(gen, batch_manager.frames_per_batch)
|
||||
|
||||
#Some minor wizardry to eliminate a copy and reduce max memory by a factor of ~2
|
||||
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (height, width, 3)))))
|
||||
if len(images) == 0:
|
||||
raise RuntimeError("No frames generated")
|
||||
if force_size != "Disabled":
|
||||
new_size = target_size(width, height, force_size, custom_width, custom_height)
|
||||
if new_size[0] != width or new_size[1] != height:
|
||||
s = images.movedim(-1,1)
|
||||
s = common_upscale(s, new_size[0], new_size[1], "lanczos", "center")
|
||||
images = s.movedim(1,-1)
|
||||
|
||||
#Setup lambda for lazy audio capture
|
||||
audio = lambda : get_audio(video, skip_first_frames * target_frame_time,
|
||||
frame_load_cap*target_frame_time*select_every_nth)
|
||||
return (images, len(images), lazy_eval(audio))
|
||||
|
||||
|
||||
class LoadVideoUpload:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
input_dir = folder_paths.get_input_directory()
|
||||
files = []
|
||||
for f in os.listdir(input_dir):
|
||||
if os.path.isfile(os.path.join(input_dir, f)):
|
||||
file_parts = f.split('.')
|
||||
if len(file_parts) > 1 and (file_parts[-1] in video_extensions):
|
||||
files.append(f)
|
||||
return {"required": {
|
||||
"video": (sorted(files),),
|
||||
"force_rate": ("INT", {"default": 0, "min": 0, "max": 24, "step": 1}),
|
||||
"force_size": (["Disabled", "Custom Height", "Custom Width", "Custom", "256x?", "?x256", "256x256", "512x?", "?x512", "512x512"],),
|
||||
"custom_width": ("INT", {"default": 512, "min": 0, "step": 8}),
|
||||
"custom_height": ("INT", {"default": 512, "min": 0, "step": 8}),
|
||||
"frame_load_cap": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"skip_first_frames": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
},
|
||||
"optional": {
|
||||
"batch_manager": ("VHS_BatchManager",)
|
||||
},
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID"
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT", "VHS_AUDIO", )
|
||||
RETURN_NAMES = ("IMAGE", "frame_count", "audio",)
|
||||
FUNCTION = "load_video"
|
||||
|
||||
def load_video(self, **kwargs):
|
||||
kwargs['video'] = folder_paths.get_annotated_filepath(kwargs['video'].strip("\""))
|
||||
return load_video_cv(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, video, **kwargs):
|
||||
image_path = folder_paths.get_annotated_filepath(video)
|
||||
return calculate_file_hash(image_path)
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(s, video, force_size, **kwargs):
|
||||
if not folder_paths.exists_annotated_filepath(video):
|
||||
return "Invalid video file: {}".format(video)
|
||||
return True
|
||||
|
||||
|
||||
class LoadVideoPath:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"video": ("STRING", {"default": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
|
||||
"force_rate": ("INT", {"default": 0, "min": 0, "max": 24, "step": 1}),
|
||||
"force_size": (["Disabled", "Custom Height", "Custom Width", "Custom", "256x?", "?x256", "256x256", "512x?", "?x512", "512x512"],),
|
||||
"custom_width": ("INT", {"default": 512, "min": 0, "step": 8}),
|
||||
"custom_height": ("INT", {"default": 512, "min": 0, "step": 8}),
|
||||
"frame_load_cap": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"skip_first_frames": ("INT", {"default": 0, "min": 0, "step": 1}),
|
||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "step": 1}),
|
||||
},
|
||||
"optional": {
|
||||
"batch_manager": ("VHS_BatchManager",)
|
||||
},
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID"
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "INT", "VHS_AUDIO", )
|
||||
RETURN_NAMES = ("IMAGE", "frame_count", "audio",)
|
||||
FUNCTION = "load_video"
|
||||
|
||||
def load_video(self, **kwargs):
|
||||
if kwargs['video'] is None or validate_path(kwargs['video']) != True:
|
||||
raise Exception("video is not a valid path: " + kwargs['video'])
|
||||
return load_video_cv(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, video, **kwargs):
|
||||
return hash_path(video)
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(s, video, **kwargs):
|
||||
return validate_path(video, allow_none=True)
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import copy
|
||||
import logging
|
||||
|
||||
|
||||
class ColoredFormatter(logging.Formatter):
|
||||
COLORS = {
|
||||
"DEBUG": "\033[0;36m", # CYAN
|
||||
"INFO": "\033[0;32m", # GREEN
|
||||
"WARNING": "\033[0;33m", # YELLOW
|
||||
"ERROR": "\033[0;31m", # RED
|
||||
"CRITICAL": "\033[0;37;41m", # WHITE ON RED
|
||||
"RESET": "\033[0m", # RESET COLOR
|
||||
}
|
||||
|
||||
def format(self, record):
|
||||
colored_record = copy.copy(record)
|
||||
levelname = colored_record.levelname
|
||||
seq = self.COLORS.get(levelname, self.COLORS["RESET"])
|
||||
colored_record.levelname = f"{seq}{levelname}{self.COLORS['RESET']}"
|
||||
return super().format(colored_record)
|
||||
|
||||
|
||||
# Create a new logger
|
||||
logger = logging.getLogger("VideoHelperSuite")
|
||||
logger.propagate = False
|
||||
|
||||
# Add handler if we don't have one.
|
||||
if not logger.handlers:
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(ColoredFormatter("[%(name)s] - %(levelname)s - %(message)s"))
|
||||
logger.addHandler(handler)
|
||||
|
||||
# Configure logger
|
||||
loglevel = logging.INFO
|
||||
logger.setLevel(loglevel)
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import subprocess
|
||||
import numpy as np
|
||||
import re
|
||||
from typing import List
|
||||
from PIL import Image
|
||||
from PIL.PngImagePlugin import PngInfo
|
||||
from pathlib import Path
|
||||
|
||||
import folder_paths
|
||||
from .logger import logger
|
||||
from .image_latent_nodes import *
|
||||
from .load_video_nodes import LoadVideoUpload, LoadVideoPath
|
||||
from .load_images_nodes import LoadImagesFromDirectoryUpload, LoadImagesFromDirectoryPath
|
||||
from .batched_nodes import VAEEncodeBatched, VAEDecodeBatched
|
||||
from .utils import ffmpeg_path, get_audio, hash_path, validate_path, requeue_workflow
|
||||
|
||||
folder_paths.folder_names_and_paths["VHS_video_formats"] = (
|
||||
[
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "video_formats"),
|
||||
],
|
||||
[".json"]
|
||||
)
|
||||
|
||||
def gen_format_widgets(video_format):
|
||||
for k in video_format:
|
||||
if k.endswith("_pass"):
|
||||
for i in range(len(video_format[k])):
|
||||
if isinstance(video_format[k][i], list):
|
||||
item = [video_format[k][i]]
|
||||
yield item
|
||||
video_format[k][i] = item[0]
|
||||
else:
|
||||
if isinstance(video_format[k], list):
|
||||
item = [video_format[k]]
|
||||
yield item
|
||||
video_format[k] = item[0]
|
||||
|
||||
def get_video_formats():
|
||||
formats = []
|
||||
for format_name in folder_paths.get_filename_list("VHS_video_formats"):
|
||||
format_name = format_name[:-5]
|
||||
video_format_path = folder_paths.get_full_path("VHS_video_formats", format_name + ".json")
|
||||
with open(video_format_path, 'r') as stream:
|
||||
video_format = json.load(stream)
|
||||
widgets = [w[0] for w in gen_format_widgets(video_format)]
|
||||
if (len(widgets) > 0):
|
||||
formats.append(["video/" + format_name, widgets])
|
||||
else:
|
||||
formats.append("video/" + format_name)
|
||||
return formats
|
||||
|
||||
def get_format_widget_defaults(format_name):
|
||||
video_format_path = folder_paths.get_full_path("VHS_video_formats", format_name + ".json")
|
||||
with open(video_format_path, 'r') as stream:
|
||||
video_format = json.load(stream)
|
||||
results = {}
|
||||
for w in gen_format_widgets(video_format):
|
||||
if len(w[0]) > 2 and 'default' in w[0][2]:
|
||||
default = w[0][2]['default']
|
||||
else:
|
||||
if type(w[0][1]) is list:
|
||||
default = w[0][1][0]
|
||||
else:
|
||||
#NOTE: This doesn't respect max/min, but should be good enough as a fallback to a fallback to a fallback
|
||||
default = {"BOOLEAN": False, "INT": 0, "FLOAT": 0, "STRING": ""}[w[0][1]]
|
||||
results[w[0][0]] = default
|
||||
return results
|
||||
|
||||
|
||||
def apply_format_widgets(format_name, kwargs):
|
||||
video_format_path = folder_paths.get_full_path("VHS_video_formats", format_name + ".json")
|
||||
with open(video_format_path, 'r') as stream:
|
||||
video_format = json.load(stream)
|
||||
for w in gen_format_widgets(video_format):
|
||||
assert(w[0][0] in kwargs)
|
||||
w[0] = str(kwargs[w[0][0]])
|
||||
return video_format
|
||||
|
||||
def tensor_to_int(tensor, bits):
|
||||
#TODO: investigate benefit of rounding by adding 0.5 before clip/cast
|
||||
tensor = tensor.cpu().numpy() * (2**bits-1)
|
||||
return np.clip(tensor, 0, (2**bits-1))
|
||||
def tensor_to_shorts(tensor):
|
||||
return tensor_to_int(tensor, 16).astype(np.uint16)
|
||||
def tensor_to_bytes(tensor):
|
||||
return tensor_to_int(tensor, 8).astype(np.uint8)
|
||||
|
||||
def ffmpeg_process(args, video_format, video_metadata, file_path, env):
|
||||
|
||||
res = None
|
||||
frame_data = yield
|
||||
if video_format.get('save_metadata', 'False') != 'False':
|
||||
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
|
||||
metadata = json.dumps(video_metadata)
|
||||
metadata_path = os.path.join(folder_paths.get_temp_directory(), "metadata.txt")
|
||||
#metadata from file should escape = ; # \ and newline
|
||||
metadata = metadata.replace("\\","\\\\")
|
||||
metadata = metadata.replace(";","\\;")
|
||||
metadata = metadata.replace("#","\\#")
|
||||
metadata = metadata.replace("=","\\=")
|
||||
metadata = metadata.replace("\n","\\\n")
|
||||
metadata = "comment=" + metadata
|
||||
with open(metadata_path, "w") as f:
|
||||
f.write(";FFMETADATA1\n")
|
||||
f.write(metadata)
|
||||
m_args = args[:1] + ["-i", metadata_path] + args[1:]
|
||||
with subprocess.Popen(m_args + [file_path], stderr=subprocess.PIPE,
|
||||
stdin=subprocess.PIPE, env=env) as proc:
|
||||
try:
|
||||
while frame_data is not None:
|
||||
proc.stdin.write(frame_data)
|
||||
#TODO: skip flush for increased speed
|
||||
proc.stdin.flush()
|
||||
frame_data = yield
|
||||
proc.stdin.close()
|
||||
res = proc.stderr.read()
|
||||
except BrokenPipeError as e:
|
||||
err = proc.stderr.read()
|
||||
#Check if output file exists. If it does, the re-execution
|
||||
#will also fail. This obscures the cause of the error
|
||||
#and seems to never occur concurrent to the metadata issue
|
||||
if os.path.exists(file_path):
|
||||
raise Exception("An error occured in the ffmpeg subprocess:\n" \
|
||||
+ err.decode("utf-8"))
|
||||
#Res was not set
|
||||
print(err.decode("utf-8"), end="", file=sys.stderr)
|
||||
logger.warn("An error occurred when saving with metadata")
|
||||
if res != b'':
|
||||
with subprocess.Popen(args + [file_path], stderr=subprocess.PIPE,
|
||||
stdin=subprocess.PIPE, env=env) as proc:
|
||||
try:
|
||||
while frame_data is not None:
|
||||
proc.stdin.write(frame_data)
|
||||
proc.stdin.flush()
|
||||
frame_data = yield
|
||||
proc.stdin.close()
|
||||
res = proc.stderr.read()
|
||||
except BrokenPipeError as e:
|
||||
res = proc.stderr.read()
|
||||
raise Exception("An error occured in the ffmpeg subprocess:\n" \
|
||||
+ res.decode("utf-8"))
|
||||
if len(res) > 0:
|
||||
print(res.decode("utf-8"), end="", file=sys.stderr)
|
||||
|
||||
class VideoCombine:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
#Hide ffmpeg formats if ffmpeg isn't available
|
||||
if ffmpeg_path is not None:
|
||||
ffmpeg_formats = get_video_formats()
|
||||
else:
|
||||
ffmpeg_formats = []
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"frame_rate": (
|
||||
"INT",
|
||||
{"default": 8, "min": 1, "step": 1},
|
||||
),
|
||||
"loop_count": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
"filename_prefix": ("STRING", {"default": "AnimateDiff"}),
|
||||
"format": (["image/gif", "image/webp"] + ffmpeg_formats,),
|
||||
"pingpong": ("BOOLEAN", {"default": False}),
|
||||
"save_output": ("BOOLEAN", {"default": True}),
|
||||
},
|
||||
"optional": {
|
||||
"audio": ("VHS_AUDIO",),
|
||||
"batch_manager": ("VHS_BatchManager",)
|
||||
},
|
||||
"hidden": {
|
||||
"prompt": "PROMPT",
|
||||
"extra_pnginfo": "EXTRA_PNGINFO",
|
||||
"unique_id": "UNIQUE_ID"
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("VHS_FILENAMES",)
|
||||
RETURN_NAMES = ("Filenames",)
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
FUNCTION = "combine_video"
|
||||
|
||||
def combine_video(
|
||||
self,
|
||||
images,
|
||||
frame_rate: int,
|
||||
loop_count: int,
|
||||
filename_prefix="AnimateDiff",
|
||||
format="image/gif",
|
||||
pingpong=False,
|
||||
save_output=True,
|
||||
prompt=None,
|
||||
extra_pnginfo=None,
|
||||
audio=None,
|
||||
unique_id=None,
|
||||
manual_format_widgets=None,
|
||||
batch_manager=None
|
||||
):
|
||||
# get output information
|
||||
output_dir = (
|
||||
folder_paths.get_output_directory()
|
||||
if save_output
|
||||
else folder_paths.get_temp_directory()
|
||||
)
|
||||
(
|
||||
full_output_folder,
|
||||
filename,
|
||||
_,
|
||||
subfolder,
|
||||
_,
|
||||
) = folder_paths.get_save_image_path(filename_prefix, output_dir)
|
||||
output_files = []
|
||||
|
||||
metadata = PngInfo()
|
||||
video_metadata = {}
|
||||
if prompt is not None:
|
||||
metadata.add_text("prompt", json.dumps(prompt))
|
||||
video_metadata["prompt"] = prompt
|
||||
if extra_pnginfo is not None:
|
||||
for x in extra_pnginfo:
|
||||
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
|
||||
video_metadata[x] = extra_pnginfo[x]
|
||||
|
||||
if batch_manager is not None and unique_id in batch_manager.outputs:
|
||||
(counter, output_process) = batch_manager.outputs[unique_id]
|
||||
else:
|
||||
# comfy counter workaround
|
||||
max_counter = 0
|
||||
|
||||
# Loop through the existing files
|
||||
matcher = re.compile(f"{re.escape(filename)}_(\d+)\D*\..+")
|
||||
for existing_file in os.listdir(full_output_folder):
|
||||
# Check if the file matches the expected format
|
||||
match = matcher.fullmatch(existing_file)
|
||||
if match:
|
||||
# Extract the numeric portion of the filename
|
||||
file_counter = int(match.group(1))
|
||||
# Update the maximum counter value if necessary
|
||||
if file_counter > max_counter:
|
||||
max_counter = file_counter
|
||||
|
||||
# Increment the counter by 1 to get the next available value
|
||||
counter = max_counter + 1
|
||||
output_process = None
|
||||
|
||||
# save first frame as png to keep metadata
|
||||
file = f"{filename}_{counter:05}.png"
|
||||
file_path = os.path.join(full_output_folder, file)
|
||||
Image.fromarray(tensor_to_bytes(images[0])).save(
|
||||
file_path,
|
||||
pnginfo=metadata,
|
||||
compress_level=4,
|
||||
)
|
||||
output_files.append(file_path)
|
||||
|
||||
format_type, format_ext = format.split("/")
|
||||
if format_type == "image":
|
||||
if batch_manager is not None:
|
||||
raise Exception("Pillow('image/') formats are not compatible with batched output")
|
||||
image_kwargs = {}
|
||||
if format_ext == "gif":
|
||||
image_kwargs['disposal'] = 2
|
||||
file = f"{filename}_{counter:05}.{format_ext}"
|
||||
file_path = os.path.join(full_output_folder, file)
|
||||
images = tensor_to_bytes(images)
|
||||
if pingpong:
|
||||
images = np.concatenate((images, images[-2:0:-1]))
|
||||
frames = [Image.fromarray(f) for f in images]
|
||||
# Use pillow directly to save an animated image
|
||||
frames[0].save(
|
||||
file_path,
|
||||
format=format_ext.upper(),
|
||||
save_all=True,
|
||||
append_images=frames[1:],
|
||||
duration=round(1000 / frame_rate),
|
||||
loop=loop_count,
|
||||
compress_level=4,
|
||||
**image_kwargs
|
||||
)
|
||||
output_files.append(file_path)
|
||||
else:
|
||||
# Use ffmpeg to save a video
|
||||
if ffmpeg_path is None:
|
||||
#Should never be reachable
|
||||
raise ProcessLookupError("Could not find ffmpeg")
|
||||
|
||||
#Acquire additional format_widget values
|
||||
kwargs = None
|
||||
if manual_format_widgets is None:
|
||||
if prompt is not None:
|
||||
kwargs = prompt[unique_id]['inputs']
|
||||
else:
|
||||
manual_format_widgets = {}
|
||||
if kwargs is None:
|
||||
kwargs = get_format_widget_defaults(format_ext)
|
||||
missing = {}
|
||||
for k in kwargs.keys():
|
||||
if k in manual_format_widgets:
|
||||
kwargs[k] = manual_format_widgets[k]
|
||||
else:
|
||||
missing[k] = kwargs[k]
|
||||
if len(missing) > 0:
|
||||
logger.warn("Extra format values were not provided, the following defaults will be used: " + str(kwargs) + "\nThis is likely due to usage of ComfyUI-to-python. These values can be manually set by supplying a manual_format_widgets argument")
|
||||
|
||||
video_format = apply_format_widgets(format_ext, kwargs)
|
||||
if video_format.get('input_color_depth', '8bit') == '16bit':
|
||||
images = tensor_to_shorts(images)
|
||||
if images.shape[-1] == 4:
|
||||
i_pix_fmt = 'rgba64'
|
||||
else:
|
||||
i_pix_fmt = 'rgb48'
|
||||
else:
|
||||
images = tensor_to_bytes(images)
|
||||
if images.shape[-1] == 4:
|
||||
i_pix_fmt = 'rgba'
|
||||
else:
|
||||
i_pix_fmt = 'rgb24'
|
||||
if pingpong:
|
||||
if batch_manager is not None:
|
||||
logger.error("pingpong is incompatible with batched output")
|
||||
images = np.concatenate((images, images[-2:0:-1]))
|
||||
file = f"{filename}_{counter:05}.{video_format['extension']}"
|
||||
file_path = os.path.join(full_output_folder, file)
|
||||
dimensions = f"{len(images[0][0])}x{len(images[0])}"
|
||||
loop_args = ["-vf", "loop=loop=" + str(loop_count)+":size=" + str(len(images))]
|
||||
bitrate_arg = []
|
||||
bitrate = video_format.get('bitrate')
|
||||
if bitrate is not None:
|
||||
bitrate_arg = ["-b:v", str(bitrate) + "M" if video_format.get('megabit') == 'True' else str(bitrate) + "K"]
|
||||
args = [ffmpeg_path, "-v", "error", "-f", "rawvideo", "-pix_fmt", i_pix_fmt,
|
||||
"-s", dimensions, "-r", str(frame_rate), "-i", "-"] \
|
||||
+ loop_args + video_format['main_pass'] + bitrate_arg
|
||||
|
||||
env=os.environ.copy()
|
||||
if "environment" in video_format:
|
||||
env.update(video_format["environment"])
|
||||
|
||||
if output_process is None:
|
||||
output_process = ffmpeg_process(args, video_format, video_metadata, file_path, env)
|
||||
#Proceed to first yield
|
||||
output_process.send(None)
|
||||
if batch_manager is not None:
|
||||
batch_manager.outputs[unique_id] = (counter, output_process)
|
||||
|
||||
output_process.send(images.tobytes())
|
||||
if batch_manager is not None:
|
||||
requeue_workflow((batch_manager.unique_id, not batch_manager.has_closed_inputs))
|
||||
if batch_manager is None or batch_manager.has_closed_inputs:
|
||||
#Close pipe and wait for termination.
|
||||
try:
|
||||
output_process.send(None)
|
||||
except StopIteration:
|
||||
pass
|
||||
if batch_manager is not None:
|
||||
batch_manager.outputs.pop(unique_id)
|
||||
if len(batch_manager.outputs) == 0:
|
||||
batch_manager.reset()
|
||||
else:
|
||||
#batch is unfinished
|
||||
#TODO: Check if empty output breaks other custom nodes
|
||||
return {"ui": {"unfinished_batch": [True]}, "result": ((save_output, []),)}
|
||||
|
||||
output_files.append(file_path)
|
||||
|
||||
|
||||
# Audio Injection after video is created, saves additional video with -audio.mp4
|
||||
|
||||
# Create audio file if input was provided
|
||||
if audio:
|
||||
output_file_with_audio = f"{filename}_{counter:05}-audio.{video_format['extension']}"
|
||||
output_file_with_audio_path = os.path.join(full_output_folder, output_file_with_audio)
|
||||
if "audio_pass" not in video_format:
|
||||
logger.warn("Selected video format does not have explicit audio support")
|
||||
video_format["audio_pass"] = ["-c:a", "libopus"]
|
||||
|
||||
|
||||
# FFmpeg command with audio re-encoding
|
||||
#TODO: expose audio quality options if format widgets makes it in
|
||||
#Reconsider forcing apad/shortest
|
||||
mux_args = [ffmpeg_path, "-v", "error", "-n", "-i", file_path,
|
||||
"-i", "-", "-c:v", "copy"] \
|
||||
+ video_format["audio_pass"] \
|
||||
+ ["-af", "apad", "-shortest", output_file_with_audio_path]
|
||||
|
||||
try:
|
||||
res = subprocess.run(mux_args, input=audio(), env=env,
|
||||
capture_output=True, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise Exception("An error occured in the ffmpeg subprocess:\n" \
|
||||
+ e.stderr.decode("utf-8"))
|
||||
if res.stderr:
|
||||
print(res.stderr.decode("utf-8"), end="", file=sys.stderr)
|
||||
output_files.append(output_file_with_audio_path)
|
||||
#Return this file with audio to the webui.
|
||||
#It will be muted unless opened or saved with right click
|
||||
file = output_file_with_audio
|
||||
|
||||
previews = [
|
||||
{
|
||||
"filename": file,
|
||||
"subfolder": subfolder,
|
||||
"type": "output" if save_output else "temp",
|
||||
"format": format,
|
||||
}
|
||||
]
|
||||
return {"ui": {"gifs": previews}, "result": ((save_output, output_files),)}
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(self, format, **kwargs):
|
||||
return True
|
||||
|
||||
class LoadAudio:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
#Hide ffmpeg formats if ffmpeg isn't available
|
||||
return {
|
||||
"required": {
|
||||
"audio_file": ("STRING", {"default": "input/", "vhs_path_extensions": ['wav','mp3','ogg','m4a','flac']}),
|
||||
},
|
||||
"optional" : {"seek_seconds": ("FLOAT", {"default": 0, "min": 0})}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("VHS_AUDIO",)
|
||||
RETURN_NAMES = ("audio",)
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
FUNCTION = "load_audio"
|
||||
def load_audio(self, audio_file, seek_seconds):
|
||||
if audio_file is None or validate_path(audio_file) != True:
|
||||
raise Exception("audio_file is not a valid path: " + audio_file)
|
||||
#Eagerly fetch the audio since the user must be using it if the
|
||||
#node executes, unlike Load Video
|
||||
audio = get_audio(audio_file, start_time=seek_seconds)
|
||||
return (lambda : audio,)
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(s, audio_file, seek_seconds):
|
||||
return hash_path(audio_file)
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(s, audio_file, **kwargs):
|
||||
return validate_path(audio_file, allow_none=True)
|
||||
|
||||
class PruneOutputs:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"filenames": ("VHS_FILENAMES",),
|
||||
"options": (["Intermediate", "Intermediate and Utility"],)
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
FUNCTION = "prune_outputs"
|
||||
|
||||
def prune_outputs(self, filenames, options):
|
||||
if len(filenames[1]) == 0:
|
||||
return ()
|
||||
assert(len(filenames[1]) <= 3 and len(filenames[1]) >= 2)
|
||||
delete_list = []
|
||||
if options in ["Intermediate", "Intermediate and Utility", "All"]:
|
||||
delete_list += filenames[1][1:-1]
|
||||
if options in ["Intermediate and Utility", "All"]:
|
||||
delete_list.append(filenames[1][0])
|
||||
if options in ["All"]:
|
||||
delete_list.append(filenames[1][-1])
|
||||
|
||||
output_dirs = [os.path.abspath("output"), os.path.abspath("temp")]
|
||||
for file in delete_list:
|
||||
#Check that path is actually an output directory
|
||||
if (os.path.commonpath([output_dirs[0], file]) != output_dirs[0]) \
|
||||
and (os.path.commonpath([output_dirs[1], file]) != output_dirs[1]):
|
||||
raise Exception("Tried to prune output from invalid directory: " + file)
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
||||
return ()
|
||||
|
||||
class BatchManager:
|
||||
def __init__(self, frames_per_batch=-1):
|
||||
self.frames_per_batch = frames_per_batch
|
||||
self.inputs = {}
|
||||
self.outputs = {}
|
||||
self.unique_id = None
|
||||
self.has_closed_inputs = False
|
||||
def reset(self):
|
||||
self.close_inputs()
|
||||
for key in self.outputs:
|
||||
if getattr(self.outputs[key][-1], "gi_suspended", False):
|
||||
try:
|
||||
self.outputs[key][-1].send(None)
|
||||
except StopIteration:
|
||||
pass
|
||||
self.__init__(self.frames_per_batch)
|
||||
def has_open_inputs(self):
|
||||
return len(self.inputs) > 0
|
||||
def close_inputs(self):
|
||||
for key in self.inputs:
|
||||
if getattr(self.inputs[key][-1], "gi_suspended", False):
|
||||
try:
|
||||
self.inputs[key][-1].send(1)
|
||||
except StopIteration:
|
||||
pass
|
||||
self.inputs = {}
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"frames_per_batch": ("INT", {"default": 16, "min": 1, "max": 128, "step": 1})
|
||||
},
|
||||
"hidden": {
|
||||
"prompt": "PROMPT",
|
||||
"unique_id": "UNIQUE_ID"
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("VHS_BatchManager",)
|
||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||
FUNCTION = "update_batch"
|
||||
|
||||
def update_batch(self, frames_per_batch, prompt=None, unique_id=None):
|
||||
if unique_id is not None and prompt is not None:
|
||||
requeue = prompt[unique_id]['inputs'].get('requeue', 0)
|
||||
else:
|
||||
requeue = 0
|
||||
if requeue == 0:
|
||||
self.reset()
|
||||
self.frames_per_batch = frames_per_batch
|
||||
self.unique_id = unique_id
|
||||
#onExecuted seems to not be called unless some message is sent
|
||||
return (self,)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"VHS_VideoCombine": VideoCombine,
|
||||
"VHS_LoadVideo": LoadVideoUpload,
|
||||
"VHS_LoadVideoPath": LoadVideoPath,
|
||||
"VHS_LoadImages": LoadImagesFromDirectoryUpload,
|
||||
"VHS_LoadImagesPath": LoadImagesFromDirectoryPath,
|
||||
"VHS_LoadAudio": LoadAudio,
|
||||
"VHS_PruneOutputs": PruneOutputs,
|
||||
"VHS_BatchManager": BatchManager,
|
||||
# Latent and Image nodes
|
||||
"VHS_SplitLatents": SplitLatents,
|
||||
"VHS_SplitImages": SplitImages,
|
||||
"VHS_SplitMasks": SplitMasks,
|
||||
"VHS_MergeLatents": MergeLatents,
|
||||
"VHS_MergeImages": MergeImages,
|
||||
"VHS_MergeMasks": MergeMasks,
|
||||
"VHS_SelectEveryNthLatent": SelectEveryNthLatent,
|
||||
"VHS_SelectEveryNthImage": SelectEveryNthImage,
|
||||
"VHS_SelectEveryNthMask": SelectEveryNthMask,
|
||||
"VHS_GetLatentCount": GetLatentCount,
|
||||
"VHS_GetImageCount": GetImageCount,
|
||||
"VHS_GetMaskCount": GetMaskCount,
|
||||
"VHS_DuplicateLatents": DuplicateLatents,
|
||||
"VHS_DuplicateImages": DuplicateImages,
|
||||
"VHS_DuplicateMasks": DuplicateMasks,
|
||||
# Batched Nodes
|
||||
"VHS_VAEEncodeBatched": VAEEncodeBatched,
|
||||
"VHS_VAEDecodeBatched": VAEDecodeBatched,
|
||||
}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VHS_VideoCombine": "Video Combine 🎥🅥🅗🅢",
|
||||
"VHS_LoadVideo": "Load Video (Upload) 🎥🅥🅗🅢",
|
||||
"VHS_LoadVideoPath": "Load Video (Path) 🎥🅥🅗🅢",
|
||||
"VHS_LoadImages": "Load Images (Upload) 🎥🅥🅗🅢",
|
||||
"VHS_LoadImagesPath": "Load Images (Path) 🎥🅥🅗🅢",
|
||||
"VHS_LoadAudio": "Load Audio (Path)🎥🅥🅗🅢",
|
||||
"VHS_PruneOutputs": "Prune Outputs 🎥🅥🅗🅢",
|
||||
"VHS_BatchManager": "Batch Manager 🎥🅥🅗🅢",
|
||||
# Latent and Image nodes
|
||||
"VHS_SplitLatents": "Split Latent Batch 🎥🅥🅗🅢",
|
||||
"VHS_SplitImages": "Split Image Batch 🎥🅥🅗🅢",
|
||||
"VHS_SplitMasks": "Split Mask Batch 🎥🅥🅗🅢",
|
||||
"VHS_MergeLatents": "Merge Latent Batches 🎥🅥🅗🅢",
|
||||
"VHS_MergeImages": "Merge Image Batches 🎥🅥🅗🅢",
|
||||
"VHS_MergeMasks": "Merge Mask Batches 🎥🅥🅗🅢",
|
||||
"VHS_SelectEveryNthLatent": "Select Every Nth Latent 🎥🅥🅗🅢",
|
||||
"VHS_SelectEveryNthImage": "Select Every Nth Image 🎥🅥🅗🅢",
|
||||
"VHS_SelectEveryNthMask": "Select Every Nth Mask 🎥🅥🅗🅢",
|
||||
"VHS_GetLatentCount": "Get Latent Count 🎥🅥🅗🅢",
|
||||
"VHS_GetImageCount": "Get Image Count 🎥🅥🅗🅢",
|
||||
"VHS_GetMaskCount": "Get Mask Count 🎥🅥🅗🅢",
|
||||
"VHS_DuplicateLatents": "Duplicate Latent Batch 🎥🅥🅗🅢",
|
||||
"VHS_DuplicateImages": "Duplicate Image Batch 🎥🅥🅗🅢",
|
||||
"VHS_DuplicateMasks": "Duplicate Mask Batch 🎥🅥🅗🅢",
|
||||
# Batched Nodes
|
||||
"VHS_VAEEncodeBatched": "VAE Encode Batched 🎥🅥🅗🅢",
|
||||
"VHS_VAEDecodeBatched": "VAE Decode Batched 🎥🅥🅗🅢",
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
import server
|
||||
import folder_paths
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
from .utils import is_url, get_sorted_dir_files_from_directory, ffmpeg_path, validate_sequence
|
||||
from comfy.k_diffusion.utils import FolderOfImages
|
||||
|
||||
web = server.web
|
||||
|
||||
def is_safe(path):
|
||||
if "VHS_STRICT_PATHS" not in os.environ:
|
||||
return True
|
||||
basedir = os.path.abspath('.')
|
||||
try:
|
||||
common_path = os.path.commonpath([basedir, path])
|
||||
except:
|
||||
#Different drive on windows
|
||||
return False
|
||||
return common_path == basedir
|
||||
|
||||
@server.PromptServer.instance.routes.get("/viewvideo")
|
||||
async def view_video(request):
|
||||
query = request.rel_url.query
|
||||
if "filename" not in query:
|
||||
return web.Response(status=404)
|
||||
filename = query["filename"]
|
||||
|
||||
#Path code misformats urls on windows and must be skipped
|
||||
if is_url(filename):
|
||||
file = filename
|
||||
else:
|
||||
filename, output_dir = folder_paths.annotated_filepath(filename)
|
||||
|
||||
type = request.rel_url.query.get("type", "output")
|
||||
if type == "path":
|
||||
#special case for path_based nodes
|
||||
#NOTE: output_dir may be empty, but non-None
|
||||
output_dir, filename = os.path.split(filename)
|
||||
if output_dir is None:
|
||||
output_dir = folder_paths.get_directory_by_type(type)
|
||||
|
||||
if output_dir is None:
|
||||
return web.Response(status=400)
|
||||
|
||||
if not is_safe(output_dir):
|
||||
return web.Response(status=403)
|
||||
|
||||
if "subfolder" in request.rel_url.query:
|
||||
output_dir = os.path.join(output_dir, request.rel_url.query["subfolder"])
|
||||
|
||||
filename = os.path.basename(filename)
|
||||
file = os.path.join(output_dir, filename)
|
||||
|
||||
if query.get('format', 'video') == 'folder':
|
||||
if not os.path.isdir(file):
|
||||
return web.Response(status=404)
|
||||
else:
|
||||
if not os.path.isfile(file) and not validate_sequence(file):
|
||||
return web.Response(status=404)
|
||||
|
||||
if query.get('format', 'video') == "folder":
|
||||
#Check that folder contains some valid image file, get it's extension
|
||||
#ffmpeg seems to not support list globs, so support for mixed extensions seems unfeasible
|
||||
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
|
||||
concat_file = os.path.join(folder_paths.get_temp_directory(), "image_sequence_preview.txt")
|
||||
skip_first_images = int(query.get('skip_first_images', 0))
|
||||
select_every_nth = int(query.get('select_every_nth', 1))
|
||||
valid_images = get_sorted_dir_files_from_directory(file, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
|
||||
if len(valid_images) == 0:
|
||||
return web.Response(status=400)
|
||||
with open(concat_file, "w") as f:
|
||||
f.write("ffconcat version 1.0\n")
|
||||
for path in valid_images:
|
||||
f.write("file '" + os.path.abspath(path) + "'\n")
|
||||
f.write("duration 0.125\n")
|
||||
in_args = ["-safe", "0", "-i", concat_file]
|
||||
else:
|
||||
in_args = ["-an", "-i", file]
|
||||
|
||||
args = [ffmpeg_path, "-v", "error"] + in_args
|
||||
vfilters = []
|
||||
if int(query.get('force_rate',0)) != 0:
|
||||
vfilters.append("fps=fps="+query['force_rate'] + ":round=up:start_time=0.001")
|
||||
if int(query.get('skip_first_frames', 0)) > 0:
|
||||
vfilters.append(f"select=gt(n\\,{int(query['skip_first_frames'])-1})")
|
||||
if int(query.get('select_every_nth', 1)) > 1:
|
||||
vfilters.append(f"select=not(mod(n\\,{query['select_every_nth']}))")
|
||||
if query.get('force_size','Disabled') != "Disabled":
|
||||
size = query['force_size'].split('x')
|
||||
if size[0] == '?' or size[1] == '?':
|
||||
size[0] = "-2" if size[0] == '?' else f"'min({size[0]},iw)'"
|
||||
size[1] = "-2" if size[1] == '?' else f"'min({size[1]},ih)'"
|
||||
else:
|
||||
#Aspect ratio is likely changed. A more complex command is required
|
||||
#to crop the output to the new aspect ratio
|
||||
ar = float(size[0])/float(size[1])
|
||||
vfilters.append(f"crop=if(gt({ar}\\,a)\\,iw\\,ih*{ar}):if(gt({ar}\\,a)\\,iw/{ar}\\,ih)")
|
||||
size = ':'.join(size)
|
||||
vfilters.append(f"scale={size}")
|
||||
vfilters.append("setpts=PTS-STARTPTS")
|
||||
if len(vfilters) > 0:
|
||||
args += ["-vf", ",".join(vfilters)]
|
||||
if int(query.get('frame_load_cap', 0)) > 0:
|
||||
args += ["-frames:v", query['frame_load_cap']]
|
||||
#TODO:reconsider adding high frame cap/setting default frame cap on node
|
||||
|
||||
args += ['-c:v', 'libvpx-vp9','-deadline', 'realtime', '-cpu-used', '8', '-f', 'webm', '-']
|
||||
|
||||
try:
|
||||
with subprocess.Popen(args, stdout=subprocess.PIPE) as proc:
|
||||
try:
|
||||
resp = web.StreamResponse()
|
||||
resp.content_type = 'video/webm'
|
||||
resp.headers["Content-Disposition"] = f"filename=\"{filename}\""
|
||||
await resp.prepare(request)
|
||||
while True:
|
||||
bytes_read = proc.stdout.read()
|
||||
if bytes_read is None:
|
||||
#TODO: check for timeout here
|
||||
time.sleep(.1)
|
||||
continue
|
||||
if len(bytes_read) == 0:
|
||||
break
|
||||
await resp.write(bytes_read)
|
||||
except ConnectionResetError as e:
|
||||
#Kill ffmpeg before stdout closes
|
||||
proc.kill()
|
||||
except BrokenPipeError as e:
|
||||
pass
|
||||
return resp
|
||||
|
||||
@server.PromptServer.instance.routes.get("/getpath")
|
||||
async def get_path(request):
|
||||
query = request.rel_url.query
|
||||
if "path" not in query:
|
||||
return web.Response(status=404)
|
||||
path = os.path.abspath(query["path"])
|
||||
|
||||
if not os.path.exists(path) or not is_safe(path):
|
||||
return web.json_response([])
|
||||
|
||||
#Use get so None is default instead of keyerror
|
||||
valid_extensions = query.get("extensions")
|
||||
valid_items = []
|
||||
for item in os.scandir(path):
|
||||
try:
|
||||
if item.is_dir():
|
||||
valid_items.append(item.name + "/")
|
||||
continue
|
||||
if valid_extensions is None or item.name.split(".")[-1] in valid_extensions:
|
||||
valid_items.append(item.name)
|
||||
except OSError:
|
||||
#Broken symlinks can throw a very unhelpful "Invalid argument"
|
||||
pass
|
||||
|
||||
return web.json_response(valid_items)
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
import hashlib
|
||||
import os
|
||||
from typing import Iterable
|
||||
import shutil
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
import server
|
||||
from .logger import logger
|
||||
|
||||
def ffmpeg_suitability(path):
|
||||
try:
|
||||
version = subprocess.run([path, "-version"], check=True,
|
||||
capture_output=True).stdout.decode("utf-8")
|
||||
except:
|
||||
return 0
|
||||
score = 0
|
||||
#rough layout of the importance of various features
|
||||
simple_criterion = [("libvpx", 20),("264",10), ("265",3),
|
||||
("svtav1",5),("libopus", 1)]
|
||||
for criterion in simple_criterion:
|
||||
if version.find(criterion[0]) >= 0:
|
||||
score += criterion[1]
|
||||
#obtain rough compile year from copyright information
|
||||
copyright_index = version.find('2000-2')
|
||||
if copyright_index >= 0:
|
||||
copyright_year = version[copyright_index+6:copyright_index+9]
|
||||
if copyright_year.isnumeric():
|
||||
score += int(copyright_year)
|
||||
return score
|
||||
|
||||
|
||||
if "VHS_FORCE_FFMPEG_PATH" in os.environ:
|
||||
ffmpeg_path = os.env["VHS_FORCE_FFMPEG_PATH"]
|
||||
else:
|
||||
ffmpeg_paths = []
|
||||
try:
|
||||
from imageio_ffmpeg import get_ffmpeg_exe
|
||||
imageio_ffmpeg_path = get_ffmpeg_exe()
|
||||
ffmpeg_paths.append(imageio_ffmpeg_path)
|
||||
except:
|
||||
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
|
||||
raise
|
||||
logger.warn("Failed to import imageio_ffmpeg")
|
||||
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
|
||||
ffmpeg_path = imageio_ffmpeg_path
|
||||
else:
|
||||
system_ffmpeg = shutil.which("ffmpeg")
|
||||
if system_ffmpeg is not None:
|
||||
ffmpeg_paths.append(system_ffmpeg)
|
||||
if len(ffmpeg_paths) == 0:
|
||||
logger.error("No valid ffmpeg found.")
|
||||
ffmpeg_path = None
|
||||
else:
|
||||
ffmpeg_path = max(ffmpeg_paths, key=ffmpeg_suitability)
|
||||
|
||||
|
||||
def get_sorted_dir_files_from_directory(directory: str, skip_first_images: int=0, select_every_nth: int=1, extensions: Iterable=None):
|
||||
directory = directory.strip()
|
||||
dir_files = os.listdir(directory)
|
||||
dir_files = sorted(dir_files)
|
||||
dir_files = [os.path.join(directory, x) for x in dir_files]
|
||||
dir_files = list(filter(lambda filepath: os.path.isfile(filepath), dir_files))
|
||||
# filter by extension, if needed
|
||||
if extensions is not None:
|
||||
extensions = list(extensions)
|
||||
new_dir_files = []
|
||||
for filepath in dir_files:
|
||||
ext = "." + filepath.split(".")[-1]
|
||||
if ext.lower() in extensions:
|
||||
new_dir_files.append(filepath)
|
||||
dir_files = new_dir_files
|
||||
# start at skip_first_images
|
||||
dir_files = dir_files[skip_first_images:]
|
||||
dir_files = dir_files[0::select_every_nth]
|
||||
return dir_files
|
||||
|
||||
|
||||
# modified from https://stackoverflow.com/questions/22058048/hashing-a-file-in-python
|
||||
def calculate_file_hash(filename: str, hash_every_n: int = 1):
|
||||
#Larger video files were taking >.5 seconds to hash even when cached,
|
||||
#so instead the modified time from the filesystem is used as a hash
|
||||
h = hashlib.sha256()
|
||||
h.update(filename.encode())
|
||||
h.update(str(os.path.getmtime(filename)).encode())
|
||||
return h.hexdigest()
|
||||
|
||||
prompt_queue = server.PromptServer.instance.prompt_queue
|
||||
def requeue_workflow_unchecked():
|
||||
"""Requeues the current workflow without checking for multiple requeues"""
|
||||
currently_running = prompt_queue.currently_running
|
||||
(_, _, prompt, extra_data, outputs_to_execute) = next(iter(currently_running.values()))
|
||||
|
||||
#Ensure batch_managers are marked stale
|
||||
prompt = prompt.copy()
|
||||
for uid in prompt:
|
||||
if prompt[uid]['class_type'] == 'VHS_BatchManager':
|
||||
prompt[uid]['inputs']['requeue'] = prompt[uid]['inputs'].get('requeue',0)+1
|
||||
|
||||
#execution.py has guards for concurrency, but server doesn't.
|
||||
#TODO: Check that this won't be an issue
|
||||
number = -server.PromptServer.instance.number
|
||||
server.PromptServer.instance.number += 1
|
||||
prompt_id = str(server.uuid.uuid4())
|
||||
prompt_queue.put((number, prompt_id, prompt, extra_data, outputs_to_execute))
|
||||
|
||||
requeue_guard = [None, 0, 0, {}]
|
||||
def requeue_workflow(requeue_required=(-1,True)):
|
||||
assert(len(prompt_queue.currently_running) == 1)
|
||||
global requeue_guard
|
||||
(run_number, _, prompt, _, _) = next(iter(prompt_queue.currently_running.values()))
|
||||
if requeue_guard[0] != run_number:
|
||||
#Calculate a count of how many outputs are managed by a batch manager
|
||||
managed_outputs=0
|
||||
for bm_uid in prompt:
|
||||
if prompt[bm_uid]['class_type'] == 'VHS_BatchManager':
|
||||
for output_uid in prompt:
|
||||
if prompt[output_uid]['class_type'] in ["VHS_VideoCombine"]:
|
||||
for inp in prompt[output_uid]['inputs'].values():
|
||||
if inp == [bm_uid, 0]:
|
||||
managed_outputs+=1
|
||||
requeue_guard = [run_number, 0, managed_outputs, {}]
|
||||
requeue_guard[1] = requeue_guard[1]+1
|
||||
requeue_guard[3][requeue_required[0]] = requeue_required[1]
|
||||
if requeue_guard[1] == requeue_guard[2] and max(requeue_guard[3].values()):
|
||||
requeue_workflow_unchecked()
|
||||
|
||||
def get_audio(file, start_time=0, duration=0):
|
||||
args = [ffmpeg_path, "-v", "error", "-i", file]
|
||||
if start_time > 0:
|
||||
args += ["-ss", str(start_time)]
|
||||
if duration > 0:
|
||||
args += ["-t", str(duration)]
|
||||
return subprocess.run(args + ["-f", "wav", "-"],
|
||||
stdout=subprocess.PIPE, check=True).stdout
|
||||
|
||||
|
||||
def lazy_eval(func):
|
||||
class Cache:
|
||||
def __init__(self, func):
|
||||
self.res = None
|
||||
self.func = func
|
||||
def get(self):
|
||||
if self.res is None:
|
||||
self.res = self.func()
|
||||
return self.res
|
||||
cache = Cache(func)
|
||||
return lambda : cache.get()
|
||||
|
||||
|
||||
def is_url(url):
|
||||
return url.split("://")[0] in ["http", "https"]
|
||||
|
||||
def validate_sequence(path):
|
||||
#Check if path is a valid ffmpeg sequence that points to at least one file
|
||||
(path, file) = os.path.split(path)
|
||||
if not os.path.isdir(path):
|
||||
return False
|
||||
match = re.search('%0?\d+d', file)
|
||||
if not match:
|
||||
return False
|
||||
seq = match.group()
|
||||
if seq == '%d':
|
||||
seq = '\\\\d+'
|
||||
else:
|
||||
seq = '\\\\d{%s}' % seq[1:-1]
|
||||
file_matcher = re.compile(re.sub('%0?\d+d', seq, file))
|
||||
for file in os.listdir(path):
|
||||
if file_matcher.fullmatch(file):
|
||||
return True
|
||||
return False
|
||||
|
||||
def hash_path(path):
|
||||
if path is None:
|
||||
return "input"
|
||||
if is_url(path):
|
||||
return "url"
|
||||
return calculate_file_hash(path.strip("\""))
|
||||
|
||||
|
||||
def validate_path(path, allow_none=False, allow_url=True):
|
||||
if path is None:
|
||||
return allow_none
|
||||
if is_url(path):
|
||||
#Probably not feasible to check if url resolves here
|
||||
return True if allow_url else "URLs are unsupported for this path"
|
||||
if not os.path.isfile(path.strip("\"")):
|
||||
return "Invalid file path: {}".format(path)
|
||||
return True
|
||||
+1090
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,102 @@
|
||||
import { app } from '../../../scripts/app.js'
|
||||
|
||||
|
||||
function getVideoMetadata(file) {
|
||||
return new Promise((r) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
const videoData = new Uint8Array(event.target.result);
|
||||
const dataView = new DataView(videoData.buffer);
|
||||
|
||||
let decoder = new TextDecoder();
|
||||
// Check for known valid magic strings
|
||||
if (dataView.getUint32(0) == 0x1A45DFA3) {
|
||||
//webm
|
||||
//see http://wiki.webmproject.org/webm-metadata/global-metadata
|
||||
//and https://www.matroska.org/technical/elements.html
|
||||
//contrary to specs, tag seems consistently at start
|
||||
//COMMENT + 0x4487 + packed length?
|
||||
//length 0x8d8 becomes 0x48d8
|
||||
//
|
||||
//description for variable length ints https://github.com/ietf-wg-cellar/ebml-specification/blob/master/specification.markdown
|
||||
let offset = 4 + 8; //COMMENT is 7 chars + 1 to realign
|
||||
while(offset < videoData.length-16) {
|
||||
//Check for text tags
|
||||
if (dataView.getUint16(offset) == 0x4487) {
|
||||
//check that name of tag is COMMENT
|
||||
const name = String.fromCharCode(...videoData.slice(offset-7,offset));
|
||||
if (name === "COMMENT") {
|
||||
let vint = dataView.getUint32(offset+2);
|
||||
let n_octets = Math.clz32(vint)+1;
|
||||
if (n_octets < 4) {//250MB sanity cutoff
|
||||
let length = (vint >> (8*(4-n_octets))) & ~(1 << (7*n_octets));
|
||||
const content = decoder.decode(videoData.slice(offset+2+n_octets, offset+2+n_octets+length));
|
||||
const json = JSON.parse(content);
|
||||
r(json);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
offset+=1;
|
||||
}
|
||||
} else if (dataView.getUint32(4) == 0x66747970 && dataView.getUint32(8) == 0x69736F6D) {
|
||||
//mp4
|
||||
//see https://developer.apple.com/documentation/quicktime-file-format
|
||||
//Seems to make no guarantee for alignment
|
||||
let offset = videoData.length-4;
|
||||
while (offset > 16) {//rough safe guess
|
||||
if (dataView.getUint32(offset) == 0x64617461) {//any data tag
|
||||
if (dataView.getUint32(offset - 8) == 0xa9636d74) {//cmt data tag
|
||||
let type = dataView.getUint32(offset+4); //seemingly 1
|
||||
let locale = dataView.getUint32(offset+8); //seemingly 0
|
||||
let size = dataView.getUint32(offset-4) - 4*4;
|
||||
const content = decoder.decode(videoData.slice(offset+12, offset+12+size));
|
||||
const json = JSON.parse(content);
|
||||
r(json);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
offset-=1;
|
||||
}
|
||||
} else {
|
||||
console.error("Unknown magic: " + dataView.getUint32(0))
|
||||
r();
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
function isVideoFile(file) {
|
||||
if (file?.name?.endsWith(".webm")) {
|
||||
return true;
|
||||
}
|
||||
if (file?.name?.endsWith(".mp4")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
let originalHandleFile = app.handleFile;
|
||||
app.handleFile = handleFile;
|
||||
async function handleFile(file) {
|
||||
if (file?.type?.startsWith("video/") || isVideoFile(file)) {
|
||||
const videoInfo = await getVideoMetadata(file);
|
||||
if (videoInfo) {
|
||||
if (videoInfo.workflow) {
|
||||
|
||||
app.loadGraphData(videoInfo.workflow);
|
||||
}
|
||||
//Potentially check for/parse A1111 metadata here.
|
||||
}
|
||||
} else {
|
||||
return await originalHandleFile.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
//hijack comfy-file-input to allow webm/mp4
|
||||
document.getElementById("comfy-file-input").accept += ",video/webm,video/mp4";
|
||||
Reference in New Issue
Block a user