Skip to content

Commit

Permalink
feat: Attempt to fix FfmegSpec when missing inkscape
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanSkraba committed Dec 6, 2024
1 parent 0414e86 commit 28ccc7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class Card(
/** The title card in PNG format. */
val png: FileMaker = maker
.green(dstPath = dirPng / (filename + ".png"), tag = "png") {
Ffmpeg().osProc("inkscape", "-w", "1920", "-h", "1080", svg.dst.get, "--export-filename", _)
Ffmpeg().osProc(Card.Inkscape, "-w", "1920", "-h", "1080", svg.dst.get, "--export-filename", _)
}

private lazy val mp4Cache = collection.mutable.Map[Int, FileMaker]()
Expand All @@ -53,6 +53,9 @@ case class Card(

object Card {

/** The command to call to run the Inkscape CLI. */
val Inkscape: String = "inkscape"

/** Given a template string, searches and replaces some lines in the template.
*
* The tags in the template look like `[[TAG4.3]]` where the first digit is the total number of lines that were found
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skraba.byexample.scala.ammonite.video

import com.skraba.byexample.scala.ammonite.OsPathScalaRelectIOConverters._
import com.skraba.byexample.scala.ammonite.video.Card.Inkscape
import org.scalactic.source.Position
import org.scalatest.{BeforeAndAfterAll, Tag}
import org.scalatest.funspec.AnyFunSpecLike
Expand Down Expand Up @@ -79,7 +80,7 @@ class FfmpegSpec extends AnyFunSpecLike with BeforeAndAfterAll with Matchers {
/** Determine if the tests should be run or not. */
val enabled: Boolean = {
import scala.sys.process._
try { "ffmpeg -version".! == 0 && "ffprobe -version".! == 0 && "inkscape --version".! == 0 }
try { "ffmpeg -version".! == 0 && "ffprobe -version".! == 0 && s"$Inkscape --version".! == 0 }
catch { case _: Exception => false }
}
override def apply(specText: String, testTags: Tag*)(testFun: => Any)(implicit pos: Position): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ object CountdownTask {

val Description = "Generate a countdown timer from a template."

/** The command to run Inkscape on the CLI */
private val Inkscape: String = "inkscape"

/** The command to run Ffmeg on the CLI */
private val Ffmeg: String = "ffmeg"

/** Represents the countdown video.
*
* @param src
Expand Down Expand Up @@ -105,7 +111,7 @@ object CountdownTask {
private lazy val execCache = collection.mutable.Map[String, File]()

private def execInkscape(f: Int, src: String, dst: String): Unit = {
Seq("inkscape", "-w", dx.toString, "-h", dy.toString, src, "--export-filename", dst).!!
Seq(Inkscape, "-w", dx.toString, "-h", dy.toString, src, "--export-filename", dst).!!
if ((f + 1) % frameRate == 0) {
if (f / frameRate % 10 == 0) print(f / frameRate)
else print("x")
Expand All @@ -115,7 +121,7 @@ object CountdownTask {
private def execFfmpeg(dst: File): Unit = {
println(".")
Seq(
"ffmpeg",
Ffmeg,
"-y",
"-framerate",
frameRate.toString,
Expand Down Expand Up @@ -236,7 +242,7 @@ object CountdownTask {
case class XmlFrame(v: Video, num: Int) {
val dst: File = (v.dstDir / (v.src.stripExtension + f".$num%05d" + "." + v.src.extension)).toFile
def find(in: Node, key: String, pre: String = "inkscape"): Option[String] =
def find(in: Node, key: String, pre: String = Inkscape): Option[String] =
in.attributes.collectFirst { case p: PrefixedAttribute if p.pre == pre && p.key == key => p }.map(_.toString)
def replaceLayer(in: Node, layerName: String)(thunk: Node => Option[Node]): Node = in match {
Expand Down

0 comments on commit 28ccc7f

Please sign in to comment.