Unusual network activity when trying to decode video using smart_open
Created by: yoanisgil
Overview
I'm using smart_open to decode videos from a Google Cloud Storage bucket. While running my sample script I've noticed that the decoding time is much more longer than when running the same script against a local copy of the video.
Here is what my script looks like:
import av
import sys
import time
from smart_open import open
if __name__ == "__main__":
video_urls = [video_url.replace("\n", "") for video_url in open(sys.argv[1]).readlines()]
for video_url in video_urls:
start_time = time.time()
with open(video_url, 'rb') as f:
f.read()
print(f"time to read file {video_url}: {time.time() - start_time}")
with open(video_url, 'rb' , transport_params=dict(buffer_size=1024*10124)) as f:
container = av.open(f, buffer_size=1024*1024)
container.streams.video[0].thread_type = "AUTO"
stream = container.streams.video[0]
video_duration = float(container.streams.video[0].duration * container.streams.video[0].time_base)
decoded_stream = container.decode(stream)
print(f"time to start decoding: {time.time() - start_time}")
decode_start_time = time.time()
frame_count = 0
for frame in decoded_stream:
print(f"Decode time: {time.time() - decode_start_time}")
decode_start_time = time.time()
frame_count += 1
print(f"Decoding time: {video_url}: {time.time() - start_time}. Video duration: {video_duration}. Frame count: {frame_count}")
break
Expected behavior
This is the output of my script when running against a local file:
Decoding time: file.mov: 0.6404592990875244. Video duration: 11.27. Frame count: 676
Actual behavior
This is the output of my script when running against the same file but stored in GCS bucket:
Decoding time: file.move: 47.5357666015625. Video duration: 11.27. Frame count: 676
Investigation
When I look at the network activity from my box, I see an usual download activity:

Reproduction
You can try this against any GCS file and a local copy of it.
Versions
- OS:
Linux yoanis-b0f5bf-1 5.4.0-1092-gcp #101~18.04.1-Ubuntu SMP Mon Oct 17 18:29:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
- PyAV runtime:
PyAV v10.0.0
library configuration: --disable-static --enable-shared --libdir=/tmp/vendor/lib --prefix=/tmp/vendor --disable-alsa --disable-doc --disable-mediafoundation --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-lzma --enable-version3 --enable-zlib
library license: GPL version 3 or later
libavcodec 59. 37.100
libavdevice 59. 7.100
libavfilter 8. 44.100
libavformat 59. 27.100
libavutil 57. 28.100
libswresample 4. 7.100
libswscale 6. 7.100
- FFmpeg:
ffmpeg version 3.4.11-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Research
I have done the following:
-
Checked the PyAV documentation -
Searched on Google -
Searched on Stack Overflow -
Looked through old GitHub issues -
Asked on PyAV Gitter -
... and waited 72 hours for a response.