PHP code example of b7s / fluentcut

1. Go to this page and download the library: Download b7s/fluentcut library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

b7s / fluentcut example snippets


use B7s\FluentCut\Enums\VideoEffect;

$result = FluentCut::make()
    ->fullHd()
    ->addImage('photo.jpg', duration: 3, effect: VideoEffect::SoftZoom)
    ->addText('Hello, world!')
    ->saveTo('output.mp4')
    ->render();

use B7s\FluentCut\FluentCut;
use B7s\FluentCut\Enums\VideoEffect;

$result = FluentCut::make()
    ->fullHd()
    ->addImage('slide1.jpg', duration: 3, effect: VideoEffect::SoftZoom)
    ->addImage('slide2.jpg', duration: 3)
    ->addImage('slide3.jpg', duration: 2)
    ->fade(0.5)
    ->saveTo('output/slideshow.mp4')
    ->render();

echo "Saved to: " . $result->outputPath;
echo "Duration: " . $result->getFormattedDuration();

$result = FluentCut::make()
    ->fromVideo('input.mp4')
    ->fullHd()
    ->addImage('background.jpg', duration: 5)
    ->addText(
        text: 'Welcome to FluentCut',
        x: 'center',
        y: '10%',
        fontSize: 64,
        fontColor: 'white',
        borderWidth: 3,
        borderColor: 'black',
        shadowX: 3,
        shadowY: 3,
        shadowColor: '[email protected]',
    )
    ->addText(
        'A fluent video editing API',
        x: 'center',
        y: '25%',
        fontSize: 28,
        fontColor: '#cccccc'
    )
    ->saveTo('output/text-overlay.mp4')
    ->render();

$result = FluentCut::make()
    ->fromVideo('input.mp4')
    ->resize(1280, 720)
    ->saveTo('output/resized.mp4')
    ->render();

$result = FluentCut::make()
    ->fromVideo('long-video.mp4', start: 10.0, end: 30.0)
    ->saveTo('output/clip.mp4')
    ->render();

$result = FluentCut::make()
    ->forGif()
    ->addImage('frame1.jpg', duration: 0.5)
    ->addImage('frame2.jpg', duration: 0.5)
    ->addImage('frame3.jpg', duration: 0.5)
    ->addImage('frame4.jpg', duration: 0.5)
    ->saveTo('output/animation.gif')
    ->render();

use B7s\FluentCut\Enums\VideoEffect;

$result = FluentCut::make()
    ->fullHd()
    ->addImage('photo1.jpg', duration: 3, effect: VideoEffect::SoftZoom)
    ->addText('Ken Burns Effect', x: 'center', y: 'bottom', fontSize: 36)
    ->addImage('photo2.jpg', duration: 3, effect: [VideoEffect::Sepia, VideoEffect::Vignette])
    ->addText('Sepia + Vignette', x: 'center', y: 'bottom', fontSize: 36)
    ->addImage('photo3.jpg', duration: 3)
    ->effect(VideoEffect::Grayscale, VideoEffect::Sharpen)
    ->addImage('photo4.jpg', duration: 3)
    ->fade(0.5)
    ->saveTo('output/effects-demo.mp4')
    ->render();

use B7s\FluentCut\Enums\Transition;

$result = FluentCut::make()
    ->fullHd()
    ->addVideo('intro.mp4')
    ->addImage('slide.png', duration: 5)
    ->addText('Chapter 1', x: 'center', y: 'top', fontSize: 64, borderWidth: 3)
    ->overlayImage('logo.png', x: '90%', y: '5%', width: 120)
    ->addBlack(0.5)
    ->addVideo('outro.mp4', start: 0, end: 10)
    ->addText('Thanks for watching!', x: 'center', y: 'center', fontSize: 48)
    ->transition(Transition::Fade, 0.5)
    ->withAudio('bgm.mp3', volume: 0.7)
    ->keepSourceAudio()
    ->saveTo('output/composition.mp4')
    ->render();

use B7s\FluentCut\Enums\HardwareAccel;

// Auto-detect best available GPU (NVIDIA, Intel, AMD, or Apple Silicon)
$result = FluentCut::make()
    ->fullHd()
    ->useGpu()
    ->addImage('slide1.jpg', duration: 3)
    ->addImage('slide2.jpg', duration: 3)
    ->fade(0.5)
    ->saveTo('output/fast_render.mp4')
    ->render();

// Explicit GPU backend
$result = FluentCut::make()
    ->useGpu(HardwareAccel::Nvenc)   // Force NVIDIA
    ->useGpu(HardwareAccel::VideoToolbox)  // Force Apple Silicon
    ->useGpu(HardwareAccel::Qsv)     // Force Intel Quick Sync
    ->useGpu(HardwareAccel::Vaapi)   // Force AMD/Intel VA-API
    // ... build composition
    ->render();

// Custom canvas
->canvas(1280, 720)  // Custom width x height

// Presets
->hd()         // 1280x720
->fullHd()     // 1920x1080
->fourK()      // 3840x2160
->vertical()   // 1080x1920 (portrait / stories)
->square()     // 1080x1080 (social media)

// Framerate
->fps(30)      // Custom framerate
->fps(60)      // High framerate

// Resize mode (how clips fit the canvas)
->resizeMode(ResizeMode::ContainBlur)  // Default

// Add entire video
->addVideo('clip.mp4')

// Trim a segment
->addVideo('clip.mp4', start: 5.0, end: 15.0)

// With a visual effect
->addVideo('clip.mp4', effect: VideoEffect::Grayscale)

// With multiple effects
->addVideo('clip.mp4', effect: [VideoEffect::Grayscale, VideoEffect::Vignette])

// Alias
->fromVideo('clip.mp4', start: 5.0, end: 15.0)

// Single image (1 second default)
->addImage('photo.jpg', duration: 3)

// With a single effect
->addImage('photo.jpg', duration: 3, effect: VideoEffect::SoftZoom)

// With multiple effects
->addImage('photo.jpg', duration: 3, effect: [VideoEffect::SoftZoom, VideoEffect::Vignette])

// Multiple images at once
->addImages(['img1.jpg', 'img2.jpg', 'img3.jpg'], duration: 2)

// Multiple images with effects
->addImages(['img1.jpg', 'img2.jpg'], duration: 2, effect: [VideoEffect::Sepia, VideoEffect::Sharpen])

// Custom color
->addColor('#1a1a2e', duration: 2)
->addColor('red', duration: 1)

// With effects
->addColor('black', duration: 2, effect: VideoEffect::Vignette)
->addColor('black', duration: 2, effect: [VideoEffect::Brightness, VideoEffect::Vignette])

// Presets
->addBlack(0.5)  // Half-second black screen
->addWhite(1.0)  // One-second white screen

// Text with just the text parameter (all other options have sensible defaults)
->addText('Hello')

// Custom position, size, and color
->addText('Title', x: 'center', y: 'top', fontSize: 64, fontColor: 'white')

// Add border/outline
->addText('Subtitle', borderWidth: 3, borderColor: 'black')

// Add drop shadow
->addText('With Shadow', shadowX: 3, shadowY: 3, shadowColor: '[email protected]')

// Both border and shadow combined
->addText('Styled', borderWidth: 2, borderColor: 'black', shadowX: 2, shadowY: 2, shadowColor: '[email protected]')

// Custom font file
->addText('Custom', fontFile: '/path/to/font.ttf')

->overlayImage('logo.png', x: '90%', y: '5%', width: 120)

// Full parameters
->overlayImage(
    path: 'watermark.png',
    x: 'right',
    y: 'bottom',
    width: 200,
    height: 100,
    start: 0.0,
    end: null  // null = visible for entire clip
)

// Single background music track (plays once, full volume)
->withAudio('bgm.mp3')

// Single track with custom volume
->withAudio('bgm.mp3', volume: 0.7)

// Loop audio until video ends (with fade in at start, fade out at end)
->withAudio('bgm.mp3', loop: true)

// Loop with custom fade duration
->withAudio('bgm.mp3', loop: true, fadeDuration: 0.5)
->withAudio('bgm.mp3', loop: true, fadeDuration: 1)
->withAudio('bgm.mp3', loop: true, fadeDuration: 2.25)

// Multiple audio tracks - each call adds a new track
->withAudio('intro.mp3', volume: 1.0)           // Track 1: full volume from start
->withAudio('background.mp3', volume: 0.5)      // Track 2: half volume from start
->withAudio('ending.mp3', volume: 0.8, startAt: 30.0)  // Track 3: starts at 30s

// Multiple tracks with different start times and cut times
->withAudio('music.mp3', volume: 0.6, startAt: 0.0)   // Plays from 0s until video ends
->withAudio('narration.mp3', volume: 1.0, startAt: 5.0, endAt: 35.0)  // Plays from 5s to 35s

// Each track can have its own loop and fade settings
->withAudio('loop-music.mp3', loop: true, fadeDuration: 0.3)  // Loop with quick fade
->withAudio('intro.mp3', loop: false, fadeDuration: 0.5)      // No loop with default fade

// Cut audio at specific time with fade out
->withAudio('music.mp3', endAt: 30.0, fadeDuration: 0.5)

// Keep audio from source video clips
->keepSourceAudio()

// Adjust volume of the last added audio track
->audioVolume(0.5)

// Add audio specifically to the current clip (not global)
->addAudioToClip('narration.mp3')

use B7s\FluentCut\Enums\Transition;

// Generic transition method
->transition(Transition::Fade, 0.5)
->transition(Transition::WipeLeft, 0.3)
->transition(Transition::Dissolve, 1.0)
->transition(Transition::CircleOpen, 0.8)
->transition(Transition::Radial, 1.0)

// Shorthand presets
->fade(0.5)               // Crossfade
->fadeThroughBlack(0.5)   // Fade through black
->noTransition()          // Hard cut

use B7s\FluentCut\Enums\VideoEffect;

// Single effect when adding a clip
->addImage('photo.jpg', duration: 3, effect: VideoEffect::SoftZoom)
->addVideo('clip.mp4', effect: VideoEffect::Grayscale)
->addColor('black', duration: 2, effect: VideoEffect::Vignette)

// Multiple effects via array
->addImage('photo.jpg', duration: 3, effect: [VideoEffect::SoftZoom, VideoEffect::Vignette])
->addImages(['a.jpg', 'b.jpg'], duration: 2, effect: [VideoEffect::Sepia, VideoEffect::Sharpen])

// Variadic effect() on the last clip (merges with existing effects)
->addImage('photo.jpg', duration: 3)
->effect(VideoEffect::Sepia, VideoEffect::Sharpen)

// No effect (default)
->addImage('photo.jpg', duration: 3)

use B7s\FluentCut\Enums\ResizeMode;

->resizeMode(ResizeMode::ContainBlur)  // Fit + blurred background (default)
->resizeMode(ResizeMode::Contain)      // Fit with letterboxing
->resizeMode(ResizeMode::Cover)        // Crop to fill (aspect preserved)
->resizeMode(ResizeMode::Stretch)      // Stretch to fill (aspect distorted)

// Output path
->saveTo('output/video.mp4')  // Save to specific location
->output('output/video.mp4')  // alias

// Codec selection
use B7s\FluentCut\Enums\Codec;
->codec(Codec::H264)  // Most compatible (default)
->codec(Codec::H265)  // Better compression
->codec(Codec::Vp9)   // WebM format

// Resize output (independent of canvas)
->resize(1280, 720)

->forSlideshow()      // Full HD, 30fps, fade transition, contain with blur
->forPresentation()   // Full HD, 24fps, contain mode
->forSocialMedia()    // Vertical (1080x1920), 30fps, cover mode
->forGif()            // 480x270, 10fps, cover mode
->forWeb()            // Full HD, 30fps, H.264, contain with blur

->onProgress(function (\B7s\FluentCut\Results\ProgressInfo $progress) {
    $bar = str_repeat('=', (int) round($progress->percentage / 2.5));
    $pad = str_repeat(' ', 40 - strlen($bar));
    echo "\r  [{$bar}{$pad}] {$progress->getFormattedPercentage()} "
       . "| Time: {$progress->getFormattedTime()} "
       . "| Speed: {$progress->getFormattedSpeed()} "
       . "| {$progress->phase}";
})

use B7s\FluentCut\Enums\HardwareAccel;

// Auto-detect best available GPU (NVIDIA, Intel, AMD, Apple Silicon)
->useGpu()

// Explicit backend
->useGpu(HardwareAccel::Nvenc)        // NVIDIA NVENC
->useGpu(HardwareAccel::VideoToolbox) // Apple Silicon
->useGpu(HardwareAccel::Qsv)          // Intel Quick Sync
->useGpu(HardwareAccel::Vaapi)        // AMD/Intel VA-API

$result = FluentCut::make()
    ->fullHd()
    ->addVideo('clip.mp4')
    ->saveTo('output.mp4')
    ->render();

$result->isSuccessful();           // bool - Check if render succeeded
$result->getPath();                // string - Output file path
$result->getDuration();            // float - Duration in seconds
$result->getFormattedDuration();   // string - "02:30.50" format
$result->getFormattedSize();       // string - Human-readable file size
$result->width;                    // int - Video width
$result->height;                   // int - Video height
$result->format;                   // string - Output format
$result->fileSize;                 // int - File size in bytes
$result->error;                    // string|null - Error message if failed
$result->metadata;                 // array - Render parameters used
$result->toArray();                // array - All data as array

use B7s\FluentCut\FluentCut;

// Probe a media file (returns full metadata)
$info = FluentCut::probe('video.mp4');

// Get specific properties
$duration = FluentCut::getDuration('video.mp4');     // ?float - seconds
$dimensions = FluentCut::getDimensions('video.mp4'); // ?array ['width' => ..., 'height' => ...]

// Check system 



declare(strict_types=1);

return [
    // FFmpeg / FFprobe paths (null = auto-detect from PATH)
    'ffmpeg_path' => null,
    'ffprobe_path' => null,

    // Default canvas dimensions
    'default_width' => 1920,
    'default_height' => 1080,

    // Default framerate
    'default_fps' => 30,

    // Default video codec
    'default_codec' => 'libx264',

    // Default clip duration (for image/color clips)
    'default_duration' => 1.0,

    // Process timeout in seconds (0 = unlimited, default)
    'timeout' => 0,

    // Enable verbose FFmpeg output
    'verbose' => false,
];