FFscala is a simple wrapper library for the FFmpeg command line, written in Scala 3.
FFscala works by using functions to transform your video encoding parameters into string lists composed of FFmpeg arguments. The command execution is independent of shell and OS, which makes it more portable.
FFscala is still in an early phase and so a new version update might bring big changes to the design and structure of the library.
To get started with using FFscala, I recommend reading this page
val encodeParams =
setVideoEncoder("x264")
++ setVideoBitrate(4000)
++ setPixFmt("yuv420p")
++ setAudioEncoder("opus")
++ setAudioBitrate(320)
val filters = scale(1920, 1080)
encode("/home/banana/Videos/gameplay.mov", "/home/banana/Videos/gameplay.mp4", encodeParams, filters)
The equivalent command should be
ffmpeg -loglevel quiet -y -i /home/banana/Videos/gameplay.mov -c:v libx264 -b:v 4000k -filter:v scale=1920:1080 -pix_fmt yuv420p -c:a libopus -b:a 320k /home/banana/Videos/gameplay_new.mp4
Like when you use FFmpeg directly, most parameters are optional, as you can see in the second example.
val scaleimg = scale(700, 800)
encode("image.bmp", "biggerimage.png", filters = scaleimg)
The equivalent command should be
ffmpeg -loglevel quiet -y -i image.bmp -filter:v scale=700:800 biggerimage.png
Here, the relative paths for the images are used. Many less parameters are used here, you don't have to use all functions of this library.
Your path names can have spaces between them, as the command execution is shell-independent.
FFmpeg tested with version 6, but you won't have problems using other versions.
By default, you need FFmpeg to be in your PATH, but encode()
and similar functions let you optionally specify the path to the executable or the program name if you prefer that way. Any function that has the optional argument exec
lets you set a custom executable path or name.
(See example 11)
You can find releases of FFscala here
Choose the version of your choice (although the latest is recommended) and download the source code from that release.
You can download the archive on the releases page, if you just want the library files, or you can download the whole project from the repository.
Add all code in src
into your project and import ffscala
. For video and audio capture support, you need to import ffscala.capture
:
import ffscala.* //Most functionality
import ffscala.capture.* //Video and audio capture functionality
(See example 7)
FFscala has documentation separated into multiple pages, each being respective to a component of the library and a different type of FFmpeg functionality.
- Getting Started
- An introductory guide to FFscala, what it can do and how to use the library.
- FFmpeg
- Main functions for media encoding
- Base
- Base encoding and FFmpeg arguments.
- Video
- Encoder-specific parameters for video and image.
- Audio
- Encoder-specific parameters for audio.
- Filters
- Filter parameters
- FFprobe
- Media parsing/probing functions
- FFplay
- Media playback with FFplay
- Capture
- Screen and audio capture and recording functionality
- Batch
- Batch processing and multiple file encoding functions