##
##  ffmpeg.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_tarball 8.0
%define       V_subdir  8.0

#   package information
Name:         ffmpeg
Summary:      Audio/Video Codec Toolkit
URL:          http://ffmpeg.org/
Vendor:       Various
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Video
License:      GPL/LGPL
Version:      %{V_tarball}
Release:      20250823

#   list of sources
Source0:      https://ffmpeg.org/releases/ffmpeg-%{V_tarball}.tar.xz
Patch0:       ffmpeg.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, perl, make, gcc, gcc::with_cxx = yes, yasm, pkgconfig
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  x264, x265, dirac, vorbis-libs, lame, xvid, theora, openssl
PreReq:       x264, x265, dirac, vorbis-libs, lame, xvid, theora, openssl
BuildPreReq:  libnut, gsm, zlib, bzip2, openjpeg, libvpx, opus, webp, aom, srt, librist, dav1d, svt-av1
PreReq:       libnut, gsm, zlib, bzip2, openjpeg, libvpx, opus, webp, aom, srt, librist, dav1d, svt-av1

%description
    FFmpeg is a toolkit of various audio and video codecs.

%track
    prog ffmpeg = {
        version   = %{V_tarball}
        url       = https://ffmpeg.org/download.html
        regex     = ffmpeg-(__VER__)\.tar\.xz
    }

%prep
    %setup -q -n ffmpeg-%{V_subdir}
    %patch -p0

%build
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O} -pthread" \
    CXXFLAGS="%{l_cxxflags -O} -pthread" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} -pthread" \
    LIBS="-lm" \
    TERM="vt100" \
    ./configure \
        --cc="%{l_cc}" \
        --cxx="%{l_cxx}" \
        --ld="%{l_cc}" \
        --extra-cflags="%{l_cflags -O} -pthread %{l_cppflags}" \
        --extra-cxxflags="%{l_cxxflags -O} -pthread %{l_cppflags}" \
        --extra-ldflags="%{l_ldflags} -pthread" \
        --extra-libs="-lm" \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --enable-gpl \
        --enable-nonfree \
        --enable-pthreads \
        --enable-libvorbis \
        --disable-libopenh264 \
        --enable-libx264 \
        --enable-libx265 \
        --enable-libwebp \
        --enable-libvpx \
        --enable-libmp3lame \
        --enable-libxvid \
        --enable-libtheora \
        --enable-libopus \
        --enable-libgsm \
        --enable-libaom \
        --enable-libdav1d \
        --enable-libsvtav1 \
        --enable-libsrt \
        --enable-librist \
        --disable-libtesseract \
        --disable-libopenjpeg \
        --enable-openssl \
        --enable-bzlib \
        --enable-zlib \
        --disable-libspeex \
        --disable-protocol=udp \
        --disable-devices \
        --disable-shared
    %{l_make} %{l_mflags} M=""

%install
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

