Installation
composer require coa/videolibraryms-bundle
Add to config/bundles.php:
return [
// ...
Coa\VideoLibraryMsBundle\CoaVideoLibraryMsBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console coa:videolibraryms:install
Update config/packages/coa_videolibraryms.yaml with your:
First Use Case: Upload a Video
use Coa\VideoLibraryMsBundle\Service\VideoService;
$videoService = $container->get(VideoService::class);
$result = $videoService->uploadVideo(
'path/to/local/video.mp4',
'my-video-title',
['tags' => ['demo', 'test']]
);
Video entity with S3 metadata and job IDs for processing.Video Processing Pipeline
graph TD
A[Upload] --> B[S3 Storage]
B --> C[MediaConvert Job]
C --> D[Transcoding]
D --> E[Notification via Broker]
VideoService::triggerProcessing($videoId) to kick off MediaConvert.MediaConvertListener to handle job completion events from the broker.Message Broker Integration
$this->get('coa_videolibraryms.message_producer')
->publish('video.processing.started', ['video_id' => $videoId]);
$consumer = new MediaConvertJobConsumer($this->get('coa_videolibraryms.message_consumer'));
$consumer->consume();
Thumbnails and Metadata
$thumbnailUrl = $videoService->generateThumbnail($videoId, 30); // 30s timestamp
$videoService->updateMetadata($videoId, ['description' => 'Updated desc']);
coa_videolibraryms.video.uploaded or coa_videolibraryms.video.processed for custom logic.VideoController with endpoints like:
#[Route('/videos/{id}/status', name: 'video_status')]
public function getStatus(VideoService $videoService, int $id): JsonResponse
{
return new JsonResponse($videoService->getVideoStatus($id));
}
VideoBatchService for bulk uploads/operations:
$batchService->processBatch([
['file' => 'video1.mp4', 'title' => 'Batch Video 1'],
['file' => 'video2.mp4', 'title' => 'Batch Video 2'],
]);
AWS Credentials
.env. Always use environment variables:
# config/packages/coa_videolibraryms.yaml
aws:
credentials:
key: '%env(AWS_ACCESS_KEY_ID)%'
secret: '%env(AWS_SECRET_ACCESS_KEY)%'
MediaConvert Job Failures
MediaConvertJobRetryListener to handle retries:
$listener = new MediaConvertJobRetryListener(
$this->get('coa_videolibraryms.media_convert_client'),
$this->get('coa_videolibraryms.message_producer')
);
$videoService->logMediaConvertError($jobId, $errorMessage);
Broker Message Timeouts
message_ttl in config:
broker:
message_ttl: 3600000 # 1 hour in ms
S3 Storage Classes
STANDARD storage class, which is costly for long-term storage. Override in config:
s3:
storage_class: 'GLACIER_IR'
Enable Verbose Logging:
php bin/console debug:config coa_videolibraryms
Set debug: true in config to log AWS/MediaConvert API calls.
Test Locally with Mocks:
Use the Coa\VideoLibraryMsBundle\Tests\Mock\* classes to mock AWS services during development.
Custom Video Fields
Extend the Video entity by overriding the VideoRepository:
class CustomVideoRepository extends VideoRepository
{
public function addCustomField(Video $video, string $field, $value): void
{
// Custom logic
}
}
Register the service in services.yaml:
Coa\VideoLibraryMsBundle\Repository\VideoRepository:
class: App\Repository\CustomVideoRepository
Pre/Post Processing Hooks
Implement Coa\VideoLibraryMsBundle\Event\VideoEventSubscriber:
class CustomVideoSubscriber implements VideoEventSubscriber
{
public function onVideoUploaded(VideoUploadedEvent $event): void
{
// Add watermark, etc.
}
}
Register the subscriber in services.yaml:
services:
App\Event\CustomVideoSubscriber:
tags: ['coa_videolibraryms.event_subscriber']
Custom MediaConvert Presets
Define presets in config/packages/coa_videolibraryms.yaml:
media_convert:
presets:
hd:
video_description: 'HD Video'
container: 'mp4'
codec: 'h264'
Use them in the service:
$videoService->uploadVideo(..., ['preset' => 'hd']);
How can I help you explore Laravel packages today?