Hello everyone,
I'm pleased to release the
Video Media Utils library, which I've been using in my own projects for a while.
Video Media Utils is a comprehensive FFmpeg and FFprobe library that brings full-featured audio and video processing directly into your desktop applications. Designed for non-blocking, asynchronous execution, it runs heavy media jobs in a background thread while reporting real-time frame counts, processing speed, and completion percentages through events, alongside clean cancellation support for active tasks.
Beyond standard container conversion, codec configuration (including H.264, H.265, AV1, VP9, AAC, MP3, and Opus), and lossless stream copying, the library provides a wide range of ready-to-use editing and inspection tools. You can easily trim, crop, rotate, resize, or compress videos to a target file size in megabytes, as well as extract audio tracks, generate animated GIFs, capture frame thumbnails, and overlay custom image or text watermarks. It also includes built-in audio loudness normalisation, playback speed control, visual filters such as grayscale, colour inversion, and tilt-shift miniature effects, and fast media metadata probing via FFprobe.
B4J Library Tab
B4J - Example app screenshot
Video showing the example app
SS_MediaUtils
Author: Peter Simpson
Version: 1.0
- MediaUtils
- Events:
- complete (Success As Boolean)
- error (Message As String)
- progress (Frame As Long, OutTimeNs As Long, Speed As Double, Percentage As Double)
- Functions:
- AddImageWatermark (Input As String, Output As String, ImagePath As String, X As Int, Y As Int, Opacity As Double)
Overlays an image watermark onto a video file.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path.
ImagePath specifies the path to the watermark image (e.g., .png).
X specifies the horizontal position offset in pixels.
Y specifies the vertical position offset in pixels.
Opacity specifies the transparency level from 0.0 (invisible) to 1.0 (solid).
- AddTextWatermark (Input As String, Output As String, Text As String, X As Int, Y As Int, FontFile As String, FontSize As Int, FontColor As String, Opacity As Double, CenterText As Boolean)
Burns a custom text watermark onto a video file.
Input specifies the source video file path.
Output specifies the output video file path.
Text specifies the string characters to overlay onto the video.
X specifies the horizontal position offset in pixels (typically 0 if CenterText is true).
Y specifies the vertical position offset in pixels (typically 0 if CenterText is true).
FontFile specifies the full system path to a valid TTF font file.
FontSize specifies the font size dimension in points.
FontColor specifies the text color (e.g., white, black, #FFFFFF).
Opacity specifies the transparency level from 0.0 (invisible) to 1.0 (solid).
CenterText specifies whether to ignore X and Y and center the text automatically.
- Cancel As String
Requests cancellation of the currently active encoding job, kills the FFmpeg OS process, and interrupts the worker thread.
Returns the full path of the target output file. (Return only)
- CaptureFrame (Input As String, OutputImage As String, Seconds As Int)
Captures a single image frame from a video at a designated time position.
Input specifies the source video file path (e.g., .mp4, .mkv).
OutputImage specifies the output image file path. This must be a supported image extension (e.g., .jpg, .png) as the image2 muxer is used.
Seconds specifies the frame position offset in seconds.
- ChangePlaybackSpeed (Input As String, Output As String, SpeedMultiplier As Double)
Modifies the playback speed multiplier of a video file.
Input specifies the source video file path.
Output specifies the output video file path.
SpeedMultiplier specifies the speed adjustment factor (e.g., 2.0 for double speed, 0.5 for half speed). Note that the internal audio tempo filter is bounded between 0.5 and 2.0.
- ChangeVolume (Input As String, Output As String, VolumeMultiplier As Double)
Adjusts the overall volume level of a media file.
Input specifies the source media file path.
Output specifies the output media file path.
VolumeMultiplier specifies the volume adjustment factor (e.g., 1.5 for 150% volume boost, 0.5 for 50% volume reduction).
- Convert (Input As String, Output As String, OutputFormat As String)
Converts an input file to a target output file and format asynchronously.
Input specifies the path to the input media file (e.g., .avi, .mkv, .mov).
Output specifies the path to the output target file (e.g., .mp4, .mkv).
OutputFormat specifies the container format extension (e.g., mp4, mkv, avi). This MUST match the extension used in the Output path.
- ConvertToBlackAndWhite (Input As String, Output As String)
Converts a colour video to black and white (grayscale).
Input specifies the source video file path.
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- ConvertToTiltShift (Input As String, Output As String, Vignette As Boolean)
Converts a video to a Tilt-Shift Effect.
Input specifies the source video file path.
Output specifies the output video file path.
Vignette specifies whether to apply a darkened border effect.
- ConvertToTiltShiftMiniature (Input As String, Output As String, Vignette As Boolean)
Converts a video to a Tilt-Shift Miniature Effect.
Input specifies the source video file path.
Output specifies the output video file path.
Vignette specifies whether to apply a darkened border effect.
- CopyAudioStream (Input As String, Output As String)
Copies the audio stream to a new file without re-encoding.
Input specifies the source media file path (e.g., .mp4, .avi).
Output specifies the output audio file path (e.g., .m4a, .mp3). The target container must support the copied codec.
- CopyVideoStream (Input As String, Output As String)
Copies the video and audio streams to a new file without re-encoding.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path (e.g., .mp4, .mkv). The target container must support the copied codecs.
- CreateGif (Input As String, Output As String)
Creates a GIF animation from a video file.
Input specifies the source video file path (e.g., .mp4, .avi).
Output specifies the destination GIF file path. This strictly requires a .gif extension.
- CreateThumbnail (Input As String, OutputImage As String)
Creates a thumbnail image from the first second of the video.
Input specifies the source video file path (e.g., .mp4, .avi).
OutputImage specifies the output image file path. This must be a supported image extension (e.g., .jpg, .png).
- CropVideo (Input As String, Output As String, CropWidth As Int, CropHeight As Int, X As Int, Y As Int)
Crops a video to a specific rectangular dimension.
Input specifies the source video file path.
Output specifies the output video file path.
CropWidth specifies the width of the cropped area in pixels.
CropHeight specifies the height of the cropped area in pixels.
X specifies the horizontal starting position from the top-left in pixels.
Y specifies the vertical starting position from the top-left in pixels.
- ExtractAudio (Input As String, OutputMp3 As String)
Extracts the audio track from a media file and saves it as an MP3 file.
Input specifies the source media file path (e.g., .mp4, .avi).
OutputMp3 specifies the destination file path. This strictly requires a .mp3 extension as the libmp3lame encoder is hardcoded.
- ExtractAudioWav (Input As String, OutputWav As String)
Extracts the audio track from a media file and saves it as an uncompressed WAV file.
Input specifies the source media file path (e.g., .mp4, .avi).
OutputWav specifies the destination file path. This strictly requires a .wav extension as the pcm_s16le encoder is hardcoded.
- FileExists (Path As String) As Boolean
Returns true if a file exists at the given path. (Return only)
Path specifies the target file path.
- GetDuration (VideoPath As String) As Double
Returns the duration of a video file in seconds. (Return only)
VideoPath specifies the path of the target video file (e.g., .mp4, .mkv).
- GetFileSize (FilePath As String) As Long
Returns the file size of a media file in bytes. (Return only)
FilePath specifies the path of the target file.
- GetVideoInfo (VideoPath As String) As Map
Retrieves stream and container metadata from a video file. (Return only)
VideoPath specifies the path of the target video file (e.g., .mp4, .mkv, .avi).
- Initialize (EventName As String, ffmpegPath As String, ffprobePath As String)
Initializes the FFmpeg CLI wrapper with binary paths and event name prefix.
EventName specifies the event name prefix for callbacks.
ffmpegPath specifies the full path to the ffmpeg executable.
ffprobePath specifies the full path to the ffprobe executable.
- InvertVideoColorsNegative (Input As String, Output As String)
Inverts the colors of a video (negative) - Almost matched RGB.
Input specifies the source video file path.
Output specifies the output video file path.
- InvertVideoColorsRGB (Input As String, Output As String)
Inverts the colors of a video (full RGB) - Almost matched negative.
Input specifies the source video file path.
Output specifies the output video file path.
- IsBusy As Boolean
Returns true if the encoding process is currently running. (Return only)
- IsCancelled As Boolean
Returns true if the most recent encoding process was requested to cancel. (Return only)
- IsInitialized As Boolean
Returns true if the wrapper has been successfully initialized. (Return only)
- IsRunning As Boolean
Returns true if the encoding process is currently running. (Return only)
- MuteVideo (Input As String, Output As String)
Removes the audio track from a video file.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- NormalizeAudio (Input As String, Output As String)
Normalises the audio volume of a media file to a standardized broadcasting loudness level.
Input specifies the source media file path.
Output specifies the output media file path.
- QualityBalanced
Set balanced quality output encoding parameters (CRF 23).
- QualityHigh
Set high quality output encoding parameters (CRF 18).
- QualitySmall
Set small file output encoding parameters (CRF 28).
- QualityVerySmall
Set very small file output encoding parameters (CRF 32).
- RemoveAudio (Input As String, Output As String)
Removes the audio track from a video file.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- ResetSettings
Resets all configuration settings and runtime state to their default values.
- Rotate180 (Input As String, Output As String)
Rotates a video 180 degrees.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- Rotate270 (Input As String, Output As String)
Rotates a video 90 degrees counter-clockwise (270 degrees).
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- Rotate90 (Input As String, Output As String)
Rotates a video 90 degrees clockwise.
Input specifies the source video file path (e.g., .mp4, .mkv).
Output specifies the output video file path. The extension should match the input to prevent format conflicts.
- SetAudioCodecAC3
Sets the audio codec to Dolby Digital (ac3).
- SetAudioCodecCopy
Sets the audio codec to copy the stream without re-encoding (copy).
- SetAudioCodecMP3
Sets the audio codec to MP3 (libmp3lame).
- SetAudioCodecOpus
Sets the audio codec to Opus (libopus).
- SetCodecAV1
Sets the video codec to AV1 (libaom-av1).
- SetCodecCopy
Sets the video codec to copy the stream without re-encoding (copy).
- SetCodecFLV
Sets the video codec to Flash Video (flv).
- SetCodecH264
Sets the video codec to H.264 (libx264).
- SetCodecH265
Sets the video codec to H.265 (libx265).
- SetCodecMPEG4
Sets the video codec to MPEG-4 (mpeg4).
- SetCodecVP9
Sets the video codec to VP9 (libvpx-vp9).
- SetPresetFast
Sets the encoding speed preset to fast.
- SetPresetMedium
Sets the encoding speed preset to medium.
- SetPresetSlow
Sets the encoding speed preset to slow.
- SetPresetUltraFast
Sets the encoding speed preset to ultrafast.
- SetPresetVerySlow
Sets the encoding speed preset to veryslow.
- SetResolution (Width As Int, Height As Int)
Sets the output target resolution dimensions.
Width specifies the frame width in pixels.
Height specifies the frame height in pixels.
- StartCompression
Starts the video encoding and compression job asynchronously in a separate thread.
- TrimVideo (Input As String, Output As String, StartSeconds As Int, DurationSeconds As Int)
Trims a video or audio file to a specific duration.
Input specifies the source media file path (e.g., .mp4, .mp3).
Output specifies the output media file path. The extension should match the input to prevent format conflicts.
StartSeconds specifies the start position in seconds.
DurationSeconds specifies the duration to keep in seconds.
- Properties:
- AudioBitrate As Int
Gets or sets the target audio bitrate in bits per second.
Bitrate specifies the audio bitrate in bps (e.g., 64000, 128000, 192000, 320000).
- AudioCodec As String
Gets or sets the audio encoder codec string.
Codec specifies the FFmpeg audio encoder name (e.g., aac, libmp3lame, copy).
Use "copy" to stream-copy without re-encoding.
- CRF As Int
Gets or sets the Constant Rate Factor value for quality target encoding.
Value specifies the CRF integer value (typically 0-51).
- FrameRate As Int
Gets or sets the target video frame rate.
FrameRate specifies the frames per second.
- Height As Int
Gets or sets the output target frame height.
Height specifies the frame height in pixels.
- InputFile As String
Gets or sets the path of the input video or audio file.
Path specifies the target input file path (e.g., .mp4, .mkv, .avi, .wav).
- OutputFile As String
Gets or sets the path of the target output file.
Path specifies the output file path (e.g., .mp4, .mkv, .avi, .mp3).
The file extension must align with the configured output format.
- OutputFormat As String
Gets or sets the output container format.
Format specifies the container format extension (e.g., mp4, mkv, avi, webm, mp3).
Note: The wrapper automatically maps "mkv" to the internal "matroska" format.
- Overwrite As Boolean
Gets or sets whether existing output files should be overwritten.
Value specifies true to force overwrite existing output files.
- Preset As String
Gets or sets the encoding speed preset string.
Preset specifies the FFmpeg preset string (e.g., ultrafast, fast, medium, slow, veryslow).
- TargetSizeMB As Int
Gets or sets a target output file size in megabytes.
MB specifies the target size in MB.
- VideoBitrate As Int
Gets or sets an explicit target video bitrate in bits per second.
Bitrate specifies the target bitrate in bps.
- VideoCodec As String
Gets or sets the custom video encoder codec string.
Codec specifies the FFmpeg encoder name (e.g., libx264, libx265, libvpx-vp9, libaom-av1, copy, gif).
Use "copy" to stream-copy without re-encoding.
- Width As Int
Gets or sets the output target frame width.
Width specifies the frame width in pixels.
PLEASE NOTE:
THE B4X EXAMPLE PROJECT HAS TWO LARGE EXE FILES INCLUDED, SO YOU MUST DOWNLOAD THE PROJECT FROM THE LINK BELOW
CLICK HERE - Download B4X Project <<<<<<<<<<<<<<<<<<<<<<<<
TO RUN THE B4J EXAMPLE PROJECT, YOU NEED TO DOWNLOAD THE THIRD-PARTY JAVA DEPENDENCIES LINKED BELOW, AS WELL AS USING THE ATTACHED LIBRARY.
CLICK HERE - Download Extra Libraries <<<<<<<<<<<<<<<<<<<<<<<<
Enjoy...