ffmpeg
| Kind | ffi-c |
|---|---|
| Categories | multimedia video audio |
| Keywords | ffmpeg video audio media encoding decoding transcoding |
FFmpeg bindings for Kit - video and audio processing
Files
| File | Description |
|---|---|
kit.toml | Package manifest with metadata and dependencies |
src/ffmpeg.kit | Media info, transcoding, frame extraction, and thumbnails |
tests/ffmpeg.test.kit | Tests for error types and API function existence |
examples/convert.kit | Transcode video to different formats and resolutions |
examples/frames.kit | Extract frames and analyze pixel brightness |
examples/info.kit | Display media file metadata and properties |
examples/thumbnail.kit | Generate thumbnails at various timestamps |
LICENSE | MIT license file |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-ffmpeg.gitUsage
import Kit.FfmpegLicense
MIT License - see LICENSE for details.
Exported Functions & Types
FFMPEGError
FFMPEG error type with specific variants for different failure modes.
Variants
FFMPEGOpenError {message}FFMPEGExtractError {message}FFMPEGProcessError {message}close
Close a media file and free associated resources.
Should be called when done working with a media file to release FFmpeg resources.
Parameters:
media- Record - Media handle returned from open
Returns: () - Unit value
{ptr: Ptr, ..} -> ()
format
Get the container format name.
Returns the name of the container format (e.g., "mp4", "matroska", "avi", "mov").
Parameters:
media- Record - Media handle returned from open
Returns: String - Format name
{ptr: Ptr, ..} -> String
duration
Get the total duration of the media file in seconds.
Parameters:
media- Record - Media handle returned from open
Returns: Float - Duration in seconds
{ptr: Ptr, ..} -> Float
bitrate
Get the overall bitrate in bits per second.
This is the combined bitrate of all streams (video + audio).
Parameters:
media- Record - Media handle returned from open
Returns: Int - Bitrate in bits per second
{ptr: Ptr, ..} -> Int
width
Get the width of the video stream in pixels.
Parameters:
media- Record - Media handle returned from open
Returns: Int - Width in pixels, or 0 if no video stream
{ptr: Ptr, ..} -> Int
height
Get the height of the video stream in pixels.
Parameters:
media- Record - Media handle returned from open
Returns: Int - Height in pixels, or 0 if no video stream
{ptr: Ptr, ..} -> Int
fps
Get the frame rate (frames per second) of the video stream.
Parameters:
media- Record - Media handle returned from open
Returns: Float - Frame rate in frames per second
{ptr: Ptr, ..} -> Float
video-codec
Get the name of the video codec.
Returns codec names like "h264", "vp9", "hevc", "av1", etc.
Parameters:
media- Record - Media handle returned from open
Returns: String - Video codec name
{ptr: Ptr, ..} -> String
audio-codec
Get the name of the audio codec.
Returns codec names like "aac", "mp3", "opus", "vorbis", etc.
Parameters:
media- Record - Media handle returned from open
Returns: String - Audio codec name
{ptr: Ptr, ..} -> String
sample-rate
Get the audio sample rate in Hz.
Common sample rates are 44100 Hz, 48000 Hz, 96000 Hz.
Parameters:
media- Record - Media handle returned from open
Returns: Int - Sample rate in Hz
{ptr: Ptr, ..} -> Int
channels
Get the number of audio channels.
Common values are 1 (mono), 2 (stereo), 6 (5.1 surround).
Parameters:
media- Record - Media handle returned from open
Returns: Int - Number of audio channels
{ptr: Ptr, ..} -> Int
has-video?
Check if the file contains a video stream.
Parameters:
media- Record - Media handle returned from open
Returns: Bool - True if file has a video stream, false otherwise
{ptr: Ptr, ..} -> Bool
has-audio?
Check if the file contains an audio stream.
Parameters:
media- Record - Media handle returned from open
Returns: Bool - True if file has an audio stream, false otherwise
{ptr: Ptr, ..} -> Bool
info
Get all media information as a record.
Convenience function that gathers all metadata into a single record.
Parameters:
media- Record - Media handle returned from open
Returns: Record - Record containing all media metadata with fields:format, duration, bitrate, width, height, fps,video-codec, audio-codec, sample-rate, channels,has-video, has-audio
{ptr: Ptr, ..} -> {format: String, duration: Float, bitrate: Int, width: Int, height: Int, fps: Float, video-codec: String, audio-codec: String, sample-rate: Int, channels: Int, has-video: Bool, has-audio: Bool}
result = open "video.mp4"
match result
| Ok media ->
info-rec = info media
print "Resolution: ${Int.to-string info-rec.width}x${Int.to-string info-rec.height}"
| Err msg -> print msg
print-info
Print formatted media information to stdout.
Displays format, duration, bitrate, video specs (if present), and audio specs (if present).
Parameters:
media- Record - Media handle returned from open
Returns: () - Unit value
{ptr: Ptr, ..} -> ()
result = open "video.mp4"
match result
| Ok media ->
print-info media
close media
| Err msg -> print msg
extract-frame
{ptr: Ptr, ..} -> Float -> Result {ptr: Ptr, width: Int, height: Int} FFMPEGError
free-frame
{ptr: Ptr, ..} -> ()
frame-width
{width: Int, ..} -> Int
frame-height
{height: Int, ..} -> Int
pixel-r
{ptr: Ptr, ..} -> Int -> Int -> Int
pixel-g
{ptr: Ptr, ..} -> Int -> Int -> Int
pixel-b
{ptr: Ptr, ..} -> Int -> Int -> Int
get-pixel
{ptr: Ptr, ..} -> Int -> Int -> {r: Int, g: Int, b: Int}
save-thumbnail
{ptr: Ptr, ..} -> Float -> Int -> Int -> String -> Result () FFMPEGError
generate-thumbnail
{ptr: Ptr, ..} -> Int -> Int -> String -> Result () FFMPEGError
extract-audio
{ptr: Ptr, ..} -> Float -> Float -> Result {ptr: Ptr, num-samples: Int} FFMPEGError
free-audio
{ptr: Ptr, ..} -> ()
audio-num-samples
{num-samples: Int, ..} -> Int
audio-get-sample
{ptr: Ptr, ..} -> Int -> Float
create-transcoder
String -> String -> Int -> Int -> Int -> Result {ptr: Ptr} FFMPEGError
transcode-process
{ptr: Ptr, ..} -> Int
transcode-finish
{ptr: Ptr, ..} -> ()
convert
String -> String -> Int -> Int -> Int -> Result () FFMPEGError
convert-simple
String -> String -> Result () FFMPEGError
convert-resize
String -> String -> Int -> Int -> Result () FFMPEGError
guess-format
String -> String
can-encode?
String -> Bool
can-decode?
String -> Bool
resolution-string
{ptr: Ptr, ..} -> String
duration-string
{ptr: Ptr, ..} -> String
duration-string-long
{ptr: Ptr, ..} -> String
bitrate-string
{ptr: Ptr, ..} -> String
is-video?
{ptr: Ptr, ..} -> Bool
is-audio-only?
{ptr: Ptr, ..} -> Bool