laravel-ffmpeg icon indicating copy to clipboard operation
laravel-ffmpeg copied to clipboard

How to set thumbnail to the video?

Open foremtehan opened this issue 5 years ago • 3 comments

How can i set a thumbnail to first frame of the video ? most of my videos have black screen intro.

image

foremtehan avatar Nov 14 '20 21:11 foremtehan

I've got this working in a new branch, but it needs some cleaning up and polishing: https://github.com/protonemedia/laravel-ffmpeg/commit/a2928e9c83eff2b7a6b9535eae7315c06a6f70e5

If you're using HTML, you can also set the thumbnail with the poster attribute: https://www.w3schools.com/tags/att_video_poster.asp

pascalbaljet avatar Nov 18 '20 21:11 pascalbaljet

I've come up with a built-in solution that looks something like this:

FFMpeg::open(['video.mp4', 'thumb.jpg'])
    ->export()
    ->addFormatOutputMapping(new CopyFormat, null, ['0'])
    ->addFormatOutputMapping(new AttachedPicFormat, Media::make('local', 'video_with_thumb.mp4'), ['1'])
    ->save();

I'll add some additional tests to check if it works with multiple videos and other codecs as well. I still think it can be refactored to something more elegant 🤔

pascalbaljet avatar Nov 20 '20 08:11 pascalbaljet

The Class is not found for CopyFormat, AttachedPicFormat and Media.

omer-habib-blocship avatar Sep 07 '23 11:09 omer-habib-blocship