title: encoding video with HEVC codec in opencv (ffmpeg)
body: <p>I have read documentation(<a href="https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu</a> and <a href="https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html" rel="nofollow noreferrer">https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html</a>) about opencv and ffmpeg, so I have compiled both parts. And when I call:</p>
  <pre><code>import cv2
  writer = cv2.VideoWriter('test.mkv', cv2.VideoWriter_fourcc(*'HEVC'), 30, (1080, 1920))
  </code></pre>
  <p>or</p>
  <pre><code>import cv2
  writer = cv2.VideoWriter('test.mp4', cv2.VideoWriter_fourcc(*'HEVC'), 30, (1080, 1920))
  </code></pre>
  <p>I'm getting following error <code>OpenCV: FFMPEG: tag 0x43564548/'HEVC' is not found (format 'mp4 / MP4 (MPEG-4 Part 14)')'</code>. What is interesting, it works with h264 codec, previous version without compiling doesn't support h264. Do I have problem with ffmpeg or opencv?</p>
  <p>I have docker image as follows:</p>
  <pre><code>FROM ubuntu:18.04
  ENV DEBIAN_FRONTEND noninteractive
  
  RUN apt-get update -y --fix-missing &amp;&amp; \
      apt-get install -y  git cmake gcc g++ build-essential curl \
                          vim wget unzip yasm python3-dev \
                          python3-numpy libavcodec-dev libavformat-dev \
                          libswscale-dev libpng-dev libjpeg-dev libwebp-dev &amp;&amp; \
      rm -rf /var/lib/apt/lists/*
  
  # compile ffmpeg
  RUN apt-get install -y  autoconf automake build-essential cmake \
                          git-core libass-dev libfreetype6-dev \
                          libgnutls28-dev libsdl2-dev libtool \
                          libunistring-dev libva-dev libvdpau-dev \
                          libvorbis-dev libxcb1-dev \
                          libxcb-shm0-dev libxcb-xfixes0-dev \
                          pkg-config texinfo wget yasm \
                          zlib1g-dev libx264-dev libx265-dev libnuma-dev &amp;&amp; \
      mkdir -p ~/ffmpeg_sources &amp;&amp; \
      cd ~/ffmpeg_sources &amp;&amp; \
      git -C x265_git pull 2&gt; /dev/null || git clone --depth 1 https://bitbucket.org/multicoreware/x265_git &amp;&amp; \
      cd x265_git/build/linux &amp;&amp; \
      cmake -G &quot;Unix Makefiles&quot; -DCMAKE_INSTALL_PREFIX=&quot;$HOME/ffmpeg_build&quot; -DENABLE_SHARED=off ../../source &amp;&amp; \
      make &amp;&amp; \
      make install &amp;&amp; \
      cd ~/ffmpeg_sources &amp;&amp; \
      wget -q -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 &amp;&amp; \
      tar xjf ffmpeg-snapshot.tar.bz2 &amp;&amp; \
      cd ffmpeg &amp;&amp; \
      PATH=&quot;$HOME/bin:$PATH&quot; PKG_CONFIG_PATH=&quot;$HOME/ffmpeg_build/lib/pkgconfig&quot; ./configure \
        --prefix=&quot;$HOME/ffmpeg_build&quot; \
        --pkg-config-flags=&quot;--static&quot; \
        --extra-cflags=&quot;-I$HOME/ffmpeg_build/include&quot; \
        --extra-ldflags=&quot;-L$HOME/ffmpeg_build/lib&quot; \
        --extra-libs=&quot;-lpthread -lm&quot; \
        --bindir=&quot;/usr/local/bin&quot; \
        --enable-gpl \
        --enable-gnutls \
        --enable-libass \
        --enable-libfreetype \
        --enable-libvorbis \
        --enable-libx264 \
        --enable-libx265 \
        --enable-nonfree &amp;&amp; \
      PATH=&quot;$HOME/bin:$PATH&quot; make &amp;&amp; \
      make install &amp;&amp; \
      hash -r &amp;&amp; \
      rm -rf /var/lib/apt/lists/*
  
  # compile opencv
  RUN mkdir -p ~/opencv_sources &amp;&amp; \
      git clone --depth 1 --branch 4.5.0 https://github.com/opencv/opencv.git ~/opencv_sources &amp;&amp; \
      mkdir -p ~/opencv_sources/build &amp;&amp; cd ~/opencv_sources/build &amp;&amp; \
      cmake -D WITH_FFMPEG=ON ../ &amp;&amp;
      make &amp;&amp; make install
  </code></pre>