NAME="ffmpeg"
DESC="Solution to record, convert and stream audio and video"
VERSION="6.0"
FILES=(
  "https://ffmpeg.org/releases/ffmpeg-$VERSION.tar.xz"
  "https://www.linuxfromscratch.org/patches/blfs/12.0/ffmpeg-$VERSION-chromium_method-1.patch"
  "https://www.linuxfromscratch.org/patches/blfs/12.0/ffmpeg-$VERSION-binutils_2.41-1.patch"
)
HASHES=(
  "47b6c5d930937413c3e308e2fdb3dfb5"
  "ba75bed1121425b15b485c0af10673900ab9df48d86e64a706aff3ef94f2e139"
  "cf4e1644af090ba41b357f2ae24937de95feba59508d184bfd4c7cfbb3e6daa6"
)
DEPENDS=(
  "libaom" "libass" "fdk-aac" "freetype" "lame"
  "libtheora" "libvorbis" "libvpx" "opus" "x264"
  "x265" "alsa-lib" "libva" "libvdpau" "sdl2"
)

PACKAGE() {
  tar xf $NAME-$VERSION.tar.xz
  cd $NAME-$VERSION
  
  patch -Np1 -i ../ffmpeg-$VERSION-chromium_method-1.patch
  patch -Np1 -i ../ffmpeg-$VERSION-binutils_2.41-1.patch

  ./configure --prefix=/usr      \
            --enable-gpl         \
            --enable-version3    \
            --enable-nonfree     \
            --disable-static     \
            --enable-shared      \
            --disable-debug      \
            --enable-libaom      \
            --enable-libass      \
            --enable-libfdk-aac  \
            --enable-libfreetype \
            --enable-libmp3lame  \
            --enable-libopus     \
            --enable-libtheora   \
            --enable-libvorbis   \
            --enable-libvpx      \
            --enable-libx264     \
            --enable-libx265     \
            --enable-openssl     \
            --docdir=/usr/share/doc/ffmpeg-$VERSION
  make && doxygen doc/Doxyfile
  gcc tools/qt-faststart.c -o tools/qt-faststart

  make DESTDIR="$ROOTDIR" install
  install -v -m755    tools/qt-faststart "$ROOTDIR/usr/bin"
  install -v -m755 -d "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION"
  install -v -m644    doc/*.txt "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION"
    
  install -v -m755 -d "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION/api"
  cp -vr doc/doxy/html/* "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION/api"

  find "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION/api" -type f -exec chmod -c 0644 \{} \;
  find "$ROOTDIR/usr/share/doc/ffmpeg-$VERSION/api" -type d -exec chmod -c 0755 \{} \;

  cd .. && rm -r $NAME-$VERSION
}
