Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sonata Media Provider Video Bundle Laravel Package

goncziakos/sonata-media-provider-video-bundle

Adds a video media provider to Sonata Media Bundle, letting you manage and render video assets alongside images in your Sonata admin. Integrates video handling into the familiar media workflow, simplifying uploads, storage, and display for video content.

View on GitHub
Deep Wiki
Context7

Getting Started

This bundle plugs a real-file video provider into Sonata Media Bundle, using FFmpeg to probe uploads and generate poster frames. Treat it as a thin provider layer on top of Sonata Media — if Sonata Media isn't already working in your project, set that up first.

  1. Install alongside Sonata Media (the bundle assumes sonata-project/media-bundle and an FFmpeg binary on the host):
    composer require goncziakos/sonata-media-provider-video-bundle
    
  2. Register the bundle in config/bundles.php (or AppKernel) after SonataMediaBundle.
  3. Verify FFmpeg is available to PHP — the provider shells out, so test as the web user:
    sudo -u www-data ffmpeg -version
    
    If it's not on PATH, note the absolute path; you'll need it in config.
  4. Look here first, in this order:
    • DependencyInjection/Configuration.php — the actual config keys and defaults (FFmpeg binary, thumbnail sizes, allowed extensions). Don't guess from the README alone.
    • Provider/*.php — the provider class, its getName(), and which metadata keys it writes.
    • Resources/config/services.xml — the service id you'll reference in sonata_media.providers.
  5. Wire it into Sonata Media under sonata_media.providers, using the provider name from the class (see Gotchas — it may collide with Sonata's built-in video provider):
    sonata_media:
        providers:
            video_file:
                service: sonata.media.provider.video   # confirm id in services.xml
    
  6. First use case: upload an .mp4 through the Sonata admin Media form, confirm the entry saves, then hit the media's thumbnail route (/media/{context}/reference/{id}/small) and check that a frame was extracted. If both work, the integration is sound.

Implementation Patterns

Admin-driven uploads. The most common path: enable the provider on a media context (default, news, etc.) and restrict allowed_extensions to mp4, webm, mov. Editors upload in the Sonata Media form; the bundle handles persistence and thumbnail generation via the postPersist/postUpdate hooks inherited from BaseVideoProvider.

Rendering in Twig. Don't hand-roll the <video> tag against the raw file URL — use the Sonata helpers so the CDN/context paths stay correct:

<video controls poster="{{ sonata_media_thumbnail(media, 'small') }}">
    <source src="{{ sonata_media_path(media, 'reference') }}" type="{{ media.contentType }}">
</video>

Override SonataMediaBundle:MediaAdmin:view.html.twig (or provide a per-provider view template in the provider config) if you need a player component instead of the default preview.

Programmatic creation. For ingest pipelines (user uploads outside admin, imports), create a Sonata\MediaBundle\Model\Media and hand it to the media manager rather than saving the entity:

$media = $mediaManager->create();
$media->setBinaryContent($absolutePath);
$media->setContext('default');
$media->setProviderName('video_file');
$mediaManager->save($media);

Thumbnail extraction runs synchronously here — batch imports should be queued (see Gotchas).

Custom poster frames. If the provider exposes a thumbnail offset/timestamp option, set it per provider entry so all videos in a context default to a deterministic frame (e.g. 5s in) instead of frame zero, which is often black.

Integration tips.

  • Register the provider under a custom context (e.g. course_videos) with its own download strategy if you need signed/streaming URLs separate from image media.
  • For HTTP range requests (required for scrub-seeking in Safari), your web server must serve the reference file directly — Symfony's default BinaryFileResponse handles this, but custom CDN rules often don't. Test seeking explicitly.
  • Use a formatter (sonata.media.formatter.twig) so frontend templates don't hardcode sizes; swap poster size per breakpoint via a srcset built from your configured thumbnail formats.

Gotchas and Tips

Provider name collision. Sonata Media already ships a video provider (for YouTube/Vimeo by URL). Register this one under a distinct key (video_file, local_video) — if you reuse video, Sonata's provider mapping will fight yours and the admin form will show the URL-based widget instead of a file upload.

FFmpeg is a runtime dependency, not a Composer one. The bundle can't install it. Pin the binary path in config in every environment, and add a deploy check (which ffmpeg || exit 1). Also confirm codec support on the host — minimal containers often ship FFmpeg without libx264, so H.264 uploads fail to probe.

Synchronous thumbnail generation. Large files (100MB+) will block the request and likely blow past max_execution_time and Nginx's fastcgi_read_timeout. For anything user-facing, override the provider service and defer thumbnail extraction to a Messenger job; the media save should return immediately.

Permissions and temp space. FFmpeg writes temp files under the configured temp dir. If the web user can't write there, you get a silent null thumbnail with no exception — always log FFmpeg's stderr, and check the temp path is on the same filesystem as uploads to avoid a copy-then-fail.

Upload limits stack. Remember the three layers: upload_max_filesize / post_max_size (PHP), client_max_body_size (Nginx), and any max_size in Sonata's provider config. Mismatched values produce confusing "file too large" errors from the wrong layer.

Very low adoption — pin the version. Zero stars and zero dependents means you are the QA. Commit to an exact tag in composer.json ("goncziakos/sonata-media-provider-video-bundle": "1.x.y"), and diff the provider class on upgrade — Sonata Media base-provider signatures change between majors, and this bundle has no test suite to catch a break.

Debugging. Reproduce failures outside PHP first: run FFmpeg manually against the offending file and read stderr. Then enable the sonata.media logger channel and watch for RuntimeException from Process — the exception message usually carries the FFmpeg error verbatim. ffprobe -show_format -show_streams <file> tells you whether the file is even valid before blaming the bundle.

Extension points. The clean override is a compiler pass or service decoration of the provider to add metadata keys (duration, bitrate, codec) onto the media — the admin view template can then render runtime. Subclassing the provider class directly is brittle here; prefer decoration until the bundle stabilises.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox