class Ffmpegthumbnailer < Formula
  desc "Create thumbnails for your video files"
  homepage "https://github.com/dirkvdb/ffmpegthumbnailer"
  url "https://github.com/dirkvdb/ffmpegthumbnailer/releases/download/2.2.0/ffmpegthumbnailer-2.2.0.tar.bz2"
  sha256 "e5c31299d064968198cd378f7488e52cd5e738fac998eea780bc77d7f32238c2"
  head "https://github.com/dirkvdb/ffmpegthumbnailer.git"

  bottle do
    cellar :any
    sha256 "ffea0f7d8407442caec4844c58c19ec31f25ccaea60ad38ae27d09b016d3334e" => :sierra
    sha256 "d9cd4573c942fc2d2349d6c3759459b3d41c73507ec6272caaca498e7ba74b22" => :el_capitan
    sha256 "49e38cce4b81b1033a6745b803fea77ec6b07f22c69269474e04ada7ca0044b5" => :yosemite
    sha256 "1f8df8ca350cdd5cd49a46aa20170afbdef3421475f5142df6cdbb77c2f21d9e" => :mavericks
  end

  depends_on "cmake" => :build
  depends_on "pkg-config" => :build
  depends_on "jpeg"
  depends_on "libpng"
  depends_on "ffmpeg"

  def install
    ENV.cxx11 if MacOS.version < :mavericks

    args = std_cmake_args
    args << "-DENABLE_GIO=ON"
    args << "-DENABLE_THUMBNAILER=ON"

    system "cmake", *args
    system "make"
    system "make", "install"
  end

  test do
    f = Formula["ffmpeg"].opt_bin/"ffmpeg"
    png = test_fixtures("test.png")
    system f.to_s, "-loop", "1", "-i", png.to_s, "-c:v", "libx264", "-t", "30",
                   "-pix_fmt", "yuv420p", "v.mp4"
    assert File.exist?("v.mp4"), "Failed to generate source video!"
    system "#{bin}/ffmpegthumbnailer", "-i", "v.mp4", "-o", "out.jpg"
    assert File.exist?("out.jpg"), "Failed to create thumbnail!"
  end
end
