1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

mp4vはブラウザで再生できない。

cv2.VideoWriterを使って動画を書き込む際、codecにmp4vを使うと、書き込んだ動画をブラウザで再生できない🥺

cv2.VideoWriter_fourcc(*'mp4v') # ブラウザで再生できないファイルになる

ブラウザで再生できるh264 codecを採用する必要があるです。

pip で入れたOpenCVではh264が使えない。

ということで、H264を使いたいですが、以下のようにH264を設定すると、pip install したOpenCVではH264を使えないので、書き込めない🥺🥺

cv2.VideoWriter_fourcc(*'avc1') # h264設定のavc1は書き込めない

解決方法

なので、pipではなく、以下の方法でOpenCVを入れます。

pip uninstall opencv-python
sudo apt install build-essential cmake git python3-dev python3-numpy \
libavcodec-dev libavformat-dev libswscale-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer1.0-dev libgtk-3-dev \
libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev \
libopencv-dev x264 libx264-dev libssl-dev ffmpeg


python -m pip install --no-binary opencv-python opencv-python

無事h264で書き出せました。
colab環境です。

Nov-30-2023 09-01-15.gif

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?