PHP code example of subhashladumor1 / laravel-ai-video
1. Go to this page and download the library: Download subhashladumor1/laravel-ai-video 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/ */
subhashladumor1 / laravel-ai-video example snippets
use Subhashladumor1\LaravelAiVideo\Facades\AiVideo;
$path = AiVideo::driver('composed')->textToVideo(
"A cyberpunk detective walking through neon-lit rainy streets of Tokyo.",
[
'duration' => 15, // Total video duration (approx)
'template' => 'youtube-short' // 9:16 Aspect Ratio
]
);
return response()->download($path);
use Subhashladumor1\LaravelAiVideo\Jobs\ProcessVideoJob;
ProcessVideoJob::dispatch(
'text-to-video',
"Create a 30-second commercial for a new eco-friendly coffee brand.",
[
'template' => 'instagram-reel',
'voice_id' => 'alloy',
'style' => 'Cinematic, Warm Lighting, Slow Motion',
'fps' => 30
],
'composed'
);
use Subhashladumor1\LaravelAiVideo\Facades\AiVideo;
// Using Runway Gen-4 Turbo
$videoPath = AiVideo::driver('runway')->imageToVideo(
public_path('images/product-shoe.jpg'),
[
'prompt' => 'Cinematic slow motion, floating in air', // Text prompt odel' => 'KLING2_1'
]
);
$scenes = AiVideo::driver('openai')->generateScenes(
"A history of the Roman Empire in 60 seconds."
);
// Returns:
// [
// [
// 'scene_number' => 1,
// 'visual_description' => 'Aerial view of the Colosseum at sunset...',
// 'voiceover_text' => 'It began as a small city-state...',
// 'duration_seconds' => 5
// ],
// ...
// ]
$audioPath = AiVideo::driver('openai')->generateVoice(
"Welcome to the future of video generation.",
'nova', // Voice options: alloy, echo, fable, onyx, nova, shimmer
['model' => 'tts-1-hd']
);
'guard' => [
'enabled' => true,
'cost_limit_per_video' => 5.00, // Maximum USD per video
],
try {
// This will throw an Exception if estimated cost > $5.00
AiVideo::driver('composed')->textToVideo("An extremely long 1-hour movie description...");
} catch (\Exception $e) {
// "Estimated cost $12.50 exceeds budget limit of $5.00"
return back()->with('error', $e->getMessage());
}
namespace App\Drivers;
use Subhashladumor1\LaravelAiVideo\Contracts\VideoDriver;
class MyCustomDriver implements VideoDriver
{
public function textToVideo(string $prompt, array $options = []): string
{
// Call your custom AI API here
return 'path/to/video.mp4';
}
// implement other methods...
}
AiVideo::extend('custom', function ($app) {
return new MyCustomDriver();
});