UbuntuサーバでOpenCVで動画ファイルが扱えない→sk-videoを使ってみるけどエラーが出る
動画ファイルがUbuntuサーバで扱えない
サーバ内でプログラムを動かそうとした際に以下のようなエラーと遭遇。
username@ubuntu:~/Projects/keras-datagenerator$ python datagen.py /home/username/miniconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters Using TensorFlow backend. [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] moov atom not found Unable to stop the stream: Inappropriate ioctl for device [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0x8a9f48: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0x94f0aa: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0xa0b946: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0xb61882: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0xbfa4c0: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0xd30b21: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x5601f54464a0] stream 0, offset 0xd31517: partial file
調べてみると、どうやらMOVファイルが壊れているっぽい。 Macで見れていたものをそのまま上げたし、ダウンロードしたら見れるのに…。
以下のサイトとか見ると色々インストールしてるけど、今他人のサーバ借りているのでパスワード知らなくて「sudo apt-get」出来ない。 stackoverflow.com
OpenCVインストール
そういやこのサーバ、OpenCV入れてたっけ?ってことでcondaで入れる。
$ conda install -c conda-forge opencv : : Downloading and Extracting Packages scipy 1.1.0: ### | 100% qt 5.6.2: ### | 100% sqlite 3.20.1: ### | 100% certifi 2018.4.16: ### | 100% ffmpeg 3.2.4: ### | 100% freetype 2.8.1: ### | 100% pyqt 5.6.0: #### | 100% numpy 1.15.0: ###| 100% libgcc 7.2.0: ### | 100% matplotlib 2.2.2: ### | 100% opencv 3.4.1: ### | 100% openssl 1.0.2o: ### | 100%
上のサイトでapt-getしてたffmpegとか入ってるのか! ってことで再実行。
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c896e4160] moov atom not found Unable to stop the stream: Inappropriate ioctl for device OpenCV(3.4.1) Error: Unspecified error (GStreamer: your gstreamer installation is missing a required plugin ) in handlemessage, file /feedstock_root/build_artefacts/opencv_1520722599420/work/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp, line 1869 VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised OpenCV exception: OpenCV(3.4.1) /feedstock_root/build_artefacts/opencv_1520722599420/work/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp:1869: error: (-2) GStreamer: your gstreamer installation is missing a required plugin in function handlemessage [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0x8a9f48: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0x94f0aa: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0xa0b946: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0xb61882: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0xbfa4c0: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0xd30b21: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c897d1040] stream 0, offset 0xd31517: partial file
どうも通らない。
sk-videoを使ってみる
会社の人に聞いたところsk-video使ってMOVを読み込んだら大丈夫だったことがあるということなので使ってみる。
まずはインストール。
$ sudo pip install sk-video
公式サイト: Reading and Writing Videos — scikit-video 1.1.10 documentation このサンプル通りにやってみる。
import skvideo.io import skvideo.datasets videodata = skvideo.io.vread(skvideo.datasets.bigbuckbunny()) print(videodata.shape)
以下のようなエラーが出る。
Traceback (most recent call last): File "skvideo.py", line 1, in <module> import skvideo.io File "/Users/saneatsuwakana/Code/ほげほげ/skvideo.py", line 1, in <module> import skvideo.io ModuleNotFoundError: No module named 'skvideo.io'; 'skvideo' is not a package
pip installしたsk-videoをアンインストール
以下のサイトを参考にして、sk-videoをuninstallしてcondaからインストールしてみる。 import error: sk video is not found · Issue #71 · scikit-video/scikit-video · GitHub
$ pip uninstall sk-video Uninstalling sk-video-1.1.10: Would remove: /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/* /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/skvideo/* Proceed (y/n)? y Exception: Traceback (most recent call last): File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/shutil.py", line 544, in move os.rename(src, real_dst) PermissionError: [Errno 13] Permission denied: '/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/DESCRIPTION.rst' -> '/private/var/folders/dd/lnp7gbfd799d1b6btyglr_xm0000gn/T/pip-uninstall-vhafcp4r/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/DESCRIPTION.rst' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/pip/_internal/basecommand.py", line 141, in main status = self.run(options, args) File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/pip/_internal/commands/uninstall.py", line 74, in run auto_confirm=options.yes, verbose=self.verbosity > 0, File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/pip/_internal/req/req_install.py", line 864, in uninstall uninstalled_pathset.remove(auto_confirm, verbose) File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/pip/_internal/req/req_uninstall.py", line 221, in remove renames(path, new_path) File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/pip/_internal/utils/misc.py", line 276, in renames shutil.move(old, new) File "/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/shutil.py", line 559, in move os.unlink(src) PermissionError: [Errno 13] Permission denied: '/Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/DESCRIPTION.rst'
エラー出た。
$ sudo pip uninstall sk-video Password: The directory '/Users/saneatsuwakana/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Uninstalling sk-video-1.1.10: Would remove: /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/* /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages/skvideo/* Proceed (y/n)? y Successfully uninstalled sk-video-1.1.10 The directory '/Users/saneatsuwakana/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
まだ出る。
以下を参考に「--user」オプションを付けてみる。 stackoverflow.com
$ pip install --user sk-video Collecting sk-video Downloading https://files.pythonhosted.org/packages/dd/3f/ce848b8b2062ad1ccf1449094a740c775f6c761339f411e44f1e090f23a7/sk_video-1.1.10-py2.py3-none-any.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 74kB/s Requirement already satisfied: scipy in /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages (from sk-video) (1.1.0) Requirement already satisfied: numpy in /Users/saneatsuwakana/.pyenv/versions/anaconda3-5.2.0/lib/python3.6/site-packages (from sk-video) (1.14.3) Installing collected packages: sk-video Successfully installed sk-video-1.1.10
出来た。と思いきや「python -m pip freeze」で見てみるとまだ残ってる…。 もう一回uninstallしてみると成功してるけどfreezeで確認すると残ってるのなんでだろ。
$ pip uninstall sk-video Uninstalling sk-video-1.1.10: Would remove: /Users/saneatsuwakana/.local/lib/python3.6/site-packages/sk_video-1.1.10.dist-info/* /Users/saneatsuwakana/.local/lib/python3.6/site-packages/skvideo/* Proceed (y/n)? y Successfully uninstalled sk-video-1.1.10
結局いかのコマンドを実行するとちゃんとアンインストールされた。
$ python -m pip uninstall sk-video
condaでsk-videoをインストール
さっきも貼ったけど以下を参考にしてインストールする。 github.com
$ conda install -c conda-forge sk-video
いざ実行。
$ python skvideo.py Traceback (most recent call last): File "skvideo.py", line 1, in <module> import skvideo.io File "/Users/saneatsuwakana/Code/AlgoAge/keras-datagentest/skvideo.py", line 1, in <module> import skvideo.io ModuleNotFoundError: No module named 'skvideo.io'; 'skvideo' is not a package
まだエラーが出るのでインストールされてるか確認する。
$ conda list : : sk-video 1.1.10 py_3 conda-forge
うーん。ほかが「py36_0」とかなのに「py_3」になってるのは気になるけどされてることはされてる。
OpenCVで再挑戦したら別のエラーに遭遇したけど長いし次の記事に書くことにする。