<commit_before># Handbrake normally uses its own copies of the libraries it uses, for better
# control over library patches.
#
# This derivation patches HB so it doesn't do that. The relevant patches
# are added to the Nix packages and proposed upstream instead. In several cases
# upstream already incorporated these patches.
# This has the benefits of providing improvements to other packages,
# making licenses more clear and reducing compile time/install size.
#
# Only tested on Linux

{ stdenv, lib, fetchFromGitHub,
  python2, pkgconfig, yasm, harfbuzz, zlib,
  autoconf, automake, cmake, libtool, m4, jansson,
  libass, libiconv, libsamplerate, fribidi, libxml2, bzip2,
  libogg, libopus, libtheora, libvorbis, libdvdcss, a52dec,
  lame, ffmpeg, libdvdread, libdvdnav, libbluray,
  mp4v2, mpeg2dec, x264, x265, libmkv,
  fontconfig, freetype, hicolor-icon-theme,
  glib, gtk3, intltool, libnotify,
  gst_all_1, dbus-glib, udev, libgudev, libvpx,
  useGtk ? true, wrapGAppsHook ? null, libappindicator-gtk3 ? null, useFdk ? false, fdk_aac ? null
}:

stdenv.mkDerivation rec {
  version = "1.0.7";
  name = "handbrake-${version}";

  src = fetchFromGitHub {
    owner  = "HandBrake";
    repo   = "HandBrake";
    rev    = "${version}";
    sha256 = "1pdrvicq40s8n23n6k8k097kkjs3ah5wbz1mvxnfy3h2mh5rwk57";
  };

  nativeBuildInputs = [
    cmake python2 pkgconfig yasm autoconf automake libtool m4
  ] ++ (lib.optionals useGtk [
    intltool wrapGAppsHook
  ]);

  buildInputs = [
    fribidi fontconfig freetype jansson zlib
    libass libiconv libsamplerate libxml2 bzip2
    libogg libopus libtheora libvorbis libdvdcss a52dec libmkv
    lame ffmpeg libdvdread libdvdnav libbluray mp4v2 mpeg2dec x264 x265 libvpx
  ] ++ (lib.optionals useGtk [
    glib gtk3 libappindicator-gtk3 libnotify
    gst_all_1.gstreamer gst_all_1.gst-plugins-base dbus-glib udev
    libgudev
  ]) ++ (lib.optionals useFdk [fdk_aac]);

  dontUseCmakeConfigure = true;

  enableParallelBuilding = true;

  preConfigure = ''
    patchShebangs scripts

    echo 'TAG=${version}' > version.txt

    # `configure` errors out when trying to read the current year which is too low
    substituteInPlace make/configure.py \
      --replace developer release \
      --replace 'repo.date.strftime("%Y-%m-%d %H:%M:%S")' '""'

    substituteInPlace libhb/module.defs \
      --replace /usr/include/libxml2 ${libxml2.dev}/include/libxml2

    # Force using nixpkgs dependencies
    sed -i '/MODULES += contrib/d' make/include/main.defs
    sed -i '/PKG_CONFIG_PATH=/d' gtk/module.rules
  '';

  configureFlags = [
    "--disable-df-fetch"
    "--disable-df-verify"<commit_msg>handbrake: switch to libav_12 (#38811)<commit_after># Handbrake normally uses its own copies of the libraries it uses, for better
# control over library patches.
#
# This derivation patches HB so it doesn't do that. The relevant patches
# are added to the Nix packages and proposed upstream instead. In several cases
# upstream already incorporated these patches.
# This has the benefits of providing improvements to other packages,
# making licenses more clear and reducing compile time/install size.
#
# Only tested on Linux

{ stdenv, lib, fetchFromGitHub,
  python2, pkgconfig, yasm, harfbuzz, zlib,
  autoconf, automake, cmake, libtool, m4, jansson,
  libass, libiconv, libsamplerate, fribidi, libxml2, bzip2,
  libogg, libopus, libtheora, libvorbis, libdvdcss, a52dec,
  lame, libdvdread, libdvdnav, libbluray,
  mp4v2, mpeg2dec, x264, x265, libmkv,
  fontconfig, freetype, hicolor-icon-theme,
  glib, gtk3, intltool, libnotify,
  gst_all_1, dbus-glib, udev, libgudev, libvpx,
  useGtk ? true, wrapGAppsHook ? null, libappindicator-gtk3 ? null,
  useFfmpeg ? false, libav_12 ? null, ffmpeg ? null,
  useFdk ? false, fdk_aac ? null
}:

stdenv.mkDerivation rec {
  version = "1.0.7";
  name = "handbrake-${version}";

  src = fetchFromGitHub {
    owner  = "HandBrake";
    repo   = "HandBrake";
    rev    = "${version}";
    sha256 = "1pdrvicq40s8n23n6k8k097kkjs3ah5wbz1mvxnfy3h2mh5rwk57";
  };

  nativeBuildInputs = [
    cmake python2 pkgconfig yasm autoconf automake libtool m4
  ] ++ lib.optionals useGtk [
    intltool wrapGAppsHook
  ];

  buildInputs = [
    fribidi fontconfig freetype jansson zlib
    libass libiconv libsamplerate libxml2 bzip2
    libogg libopus libtheora libvorbis libdvdcss a52dec libmkv
    lame ffmpeg libdvdread libdvdnav libbluray mp4v2 mpeg2dec x264 x265 libvpx
  ] ++ lib.optionals useGtk [
    glib gtk3 libappindicator-gtk3 libnotify
    gst_all_1.gstreamer gst_all_1.gst-plugins-base dbus-glib udev
    libgudev
  ] ++ (if useFfmpeg then [ ffmpeg ] else [ libav_12 ])
  ++ lib.optional useFdk fdk_aac;

  dontUseCmakeConfigure = true;

  enableParallelBuilding = true;

  preConfigure = ''
    patchShebangs scripts

    echo 'TAG=${version}' > version.txt

    # `configure` errors out when trying to read the current year which is too low
    substituteInPlace make/configure.py \
      --replace developer release \
      --replace 'repo.date.strftime("%Y-%m-%d %H:%M:%S")' '""'

    substituteInPlace libhb/module.defs \
      --replace /usr/include/libxml2 ${libxml2.dev}/include/libxml2

    # Force using nixpkgs dependencies
    sed -i '/MODULES += contrib/d' make/include/main.defs
    sed -i '/PKG_CONFIG_PATH=/d' gtk/module.rules
  '';

  configureFlags = [
    "--disable-df-fetch"
    "--disable-df-verify"
{'fraction_non_alphanumeric': 0.09698873083317938, 'fraction_numerical': 0.02604840199519675, 'mean_word_length': 3.782685512367491, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4883098', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1944, 'n_words': 520}