about summary refs log tree commit diff
path: root/pkgs/applications/video/ccextractor/default.nix
blob: 399287c93f7ff879df04c1b752b86267cbe641f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ lib
, stdenv
, fetchFromGitHub
, pkg-config
, cmake
, libiconv
, zlib
, enableOcr ? true
, makeWrapper
, tesseract4
, leptonica
, ffmpeg_4
}:

stdenv.mkDerivation rec {
  pname = "ccextractor";
  version = "0.93";

  src = fetchFromGitHub {
    owner = "CCExtractor";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-usVAKBkdd8uz9cD5eLd0hnwGonOJLscRdc+iWDlNXVc=";
  };

  postPatch = ''
    # https://github.com/CCExtractor/ccextractor/issues/1467
    sed -i '/allheaders.h/a#include <leptonica/pix_internal.h>' src/lib_ccx/ocr.c
  '' + lib.optionalString stdenv.isDarwin ''
    substituteInPlace src/CMakeLists.txt \
    --replace 'add_definitions(-DGPAC_CONFIG_LINUX)' 'add_definitions(-DGPAC_CONFIG_DARWIN)'
  '';

  cmakeDir = "../src";

  nativeBuildInputs = [ pkg-config cmake makeWrapper ];

  buildInputs = [ zlib ]
    ++ lib.optional (!stdenv.isLinux) libiconv
    ++ lib.optionals enableOcr [ leptonica tesseract4 ffmpeg_4 ];

  cmakeFlags = [
    # file RPATH_CHANGE could not write new RPATH:
    "-DCMAKE_SKIP_BUILD_RPATH=ON"
  ] ++ lib.optionals enableOcr [ "-DWITH_OCR=on" "-DWITH_HARDSUBX=on" ];

  postInstall = lib.optionalString enableOcr ''
    wrapProgram "$out/bin/ccextractor" \
      --set TESSDATA_PREFIX "${tesseract4}/share/"
  '';

  meta = with lib; {
    homepage = "https://www.ccextractor.org";
    description = "Tool that produces subtitles from closed caption data in videos";
    longDescription = ''
      A tool that analyzes video files and produces independent subtitle files from
      closed captions data. CCExtractor is portable, small, and very fast.
      It works on Linux, Windows, and OSX.
    '';
    platforms = platforms.unix;
    # undefined reference to `png_do_expand_palette_rgba8_neon'
    # undefined reference to `png_riffle_palette_neon'
    # undefined reference to `png_do_expand_palette_rgb8_neon'
    # undefined reference to `png_init_filter_functions_neon'
    # during Linking C executable ccextractor
    broken = stdenv.isAarch64;
    license = licenses.gpl2Only;
    maintainers = with maintainers; [ ];
    mainProgram = "ccextractor";
  };
}