Skip to content

Commit

Permalink
FFplay filters support
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebanana420 committed Jun 22, 2024
1 parent b945f63 commit b51ba37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
8 changes: 5 additions & 3 deletions docs/ffplay.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ You can play any supported media with FFplay. These functions allow you to open
---

```scala
def execplay(input: String, args: List[String] = List(), quiet: Boolean = true, exec: String = "ffplay"): Int
def execplay(input: String, args: List[String] = List(), filters: List[String] = List(), quiet: Boolean = true, exec: String = "ffplay"): Int
```
Executes FFplay to play back the media located in the path ```input```. The args that go here are the ones you generate with the functions seen here.
Executes FFplay to play back the media located in the path ```input```. The ```args``` that go here are the ones you generate with the functions seen here.

You can also pass common FFmpeg video and audio filters to FFplay through ```filters```.

---

Expand Down Expand Up @@ -107,4 +109,4 @@ Sets the seek interval for when you seek using the left and right arrow keys.
```scala
def enableHWaccel(): List[String]
```
Enables hardware acceleration for playback.
Enables hardware acceleration for playback.
16 changes: 2 additions & 14 deletions src/ffmpeg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,12 @@ hwaccel: String = "", quiet: Boolean = true, exec: String = "ffmpeg"
if !isAlright then
-1
else
val filterlist = processFilters(filters)
val filters_v =
if filterlist(0).length > 0 then
List("-filter:v", filterlist(0))
else
List()
val filters_a =
if filterlist(1).length > 0 then
List("-filter:a", filterlist(1))
else
List()
val nonfilters = getNonFilters(filters)
val filter_args = mkFilterArgs(filters)
try
val cmd: List[String] =
getBaseArgs_hw(exec, quiet, hwaccel)
++ List("-i", input)
++ args ++ filters_v ++ filters_a
++ nonfilters :+ output
++ args ++ filter_args :+ output
cmd.!
catch
case e: Exception => -1
Expand Down
9 changes: 5 additions & 4 deletions src/ffplay/ffplay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import ffscala.misc.*

//FFplay functionality to play media

def execplay(input: String, args: List[String] = List(), quiet: Boolean = true, exec: String = "ffplay"): Int =
def execplay(input: String, args: List[String] = List(), filters: List[String] = List(), quiet: Boolean = true, exec: String = "ffplay"): Int =
if File(input).isFile() == true then
try
val filter_args = mkFilterArgs(filters)
val cmd =
if quiet then
List(exec, "-loglevel", "quiet", input) ++ args
List(exec, "-loglevel", "quiet", input) ++ args ++ filter_args
else
List(exec, "-hide_banner", input)
List(exec, "-hide_banner", input) ++ args ++ filter_args
cmd.!
catch
case e: Exception => -1
Expand Down Expand Up @@ -121,4 +122,4 @@ def setSeekInterval(interval: Float): List[String] =
else
List("-seek_interval", interval.toString)

def enableHWaccel(): List[String] = List("-hwaccel")
def enableHWaccel(): List[String] = List("-hwaccel")
20 changes: 18 additions & 2 deletions src/misc_encode.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package ffscala.misc

def processFilters(filters: List[String], vf: String = "", af: String = "", i: Int = 0): List[String] =
def mkFilterArgs(filters: Seq[String]): List[String] =
val filterlist = processFilters(filters)
val nonfilters = getNonFilters(filters)
val filters_v =
if filterlist(0).length > 0 then
List("-vf", filterlist(0))
else
List()
val filters_a =
if filterlist(1).length > 0 then
List("-af", filterlist(1))
else
List()

filters_v ++ filters_a ++ nonfilters

def processFilters(filters: Seq[String], vf: String = "", af: String = "", i: Int = 0): List[String] =
val comma =
if i >= filters.length-2 then
""
Expand All @@ -15,7 +31,7 @@ def processFilters(filters: List[String], vf: String = "", af: String = "", i: I
else
processFilters(filters, vf, af, i+1)

def getNonFilters(filters: List[String], nf: List[String] = List(), i: Int = 0): List[String] =
def getNonFilters(filters: Seq[String], nf: List[String] = List(), i: Int = 0): List[String] =
if i >= filters.length then
nf
else if filters(i) == "v" || filters(i) == "a" then
Expand Down

0 comments on commit b51ba37

Please sign in to comment.