Skip to content

Commit f49b1f9

Browse files
author
David Eigen
committed
stream and video utils files
1 parent 74cd874 commit f49b1f9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

clarifai/runners/utils/video_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def stream_video_from_url(url, download_ok=True):
2626
# otherwise download the whole file
2727
# e.g. if linking to a streamable file format like mpegts (not mp4)
2828
file = tempfile.NamedTemporaryFile(delete=True)
29-
_download_video(url, file)
29+
download_file(url, file.name)
3030
container = av.open(file.name)
3131
else:
3232
# TODO others: s3, etc.
@@ -36,13 +36,12 @@ def stream_video_from_url(url, download_ok=True):
3636
yield from container.decode(video=0)
3737

3838

39-
def _download_video(url, file):
39+
def download_file(url, file_name):
4040
response = requests.get(url, stream=True)
4141
response.raise_for_status()
42-
for chunk in response.iter_content(chunk_size=1024):
43-
file.write(chunk)
44-
file.flush()
45-
return file
42+
with open(file_name, 'wb') as f:
43+
for chunk in response.iter_content(chunk_size=1024):
44+
f.write(chunk)
4645

4746

4847
def stream_video_from_bytes(bytes_iterator):

0 commit comments

Comments
 (0)