Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
diffusers
Commits
3e460432
Unverified
Commit
3e460432
authored
Aug 16, 2024
by
Dhruv Nair
Committed by
GitHub
Aug 16, 2024
Browse files
Small improvements for video loading (#9183)
* update * update
parent
1a92bc05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
src/diffusers/utils/loading_utils.py
src/diffusers/utils/loading_utils.py
+14
-3
No files found.
src/diffusers/utils/loading_utils.py
View file @
3e460432
import
os
import
tempfile
from
typing
import
Callable
,
List
,
Optional
,
Union
from
urllib.parse
import
unquote
,
urlparse
import
PIL.Image
import
PIL.ImageOps
...
...
@@ -80,12 +81,22 @@ def load_video(
)
if
is_url
:
video_data
=
requests
.
get
(
video
,
stream
=
True
).
raw
suffix
=
os
.
path
.
splitext
(
video
)[
1
]
or
".mp4"
response
=
requests
.
get
(
video
,
stream
=
True
)
if
response
.
status_code
!=
200
:
raise
ValueError
(
f
"Failed to download video. Status code:
{
response
.
status_code
}
"
)
parsed_url
=
urlparse
(
video
)
file_name
=
os
.
path
.
basename
(
unquote
(
parsed_url
.
path
))
suffix
=
os
.
path
.
splitext
(
file_name
)[
1
]
or
".mp4"
video_path
=
tempfile
.
NamedTemporaryFile
(
suffix
=
suffix
,
delete
=
False
).
name
was_tempfile_created
=
True
video_data
=
response
.
iter_content
(
chunk_size
=
8192
)
with
open
(
video_path
,
"wb"
)
as
f
:
f
.
write
(
video_data
.
read
())
for
chunk
in
video_data
:
f
.
write
(
chunk
)
video
=
video_path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment