Skip to content
Advertisement

Generate thumbnail from video using ffmpeg and add to mysql database

Im a noobie in php but still im trying πŸ™‚ Im making bulk video uploader/importer to database. Looking ideas how to extract thumbnails from videos on upload and add those thumbnails to mysql database for each video… :/ Im trying using ffmpeg, but i dont found the way how to implement it to my code…

JavaScript

Advertisement

Answer

Concerning the FFMpeg part, I think a good way to start is to actually use the PHP-FFMpeg library. The Basic Usage section in the documentation contains an example on how to generate a frame for a given video:

JavaScript

A simplified process would be as follows:

  1. The user uploads a video, after which the video gets moved to a different directory.
  2. Now you can use the snippet above, with the frame method to get a thumbnail for your video.
  3. After the image saving is done, you just need to add it to your database.
    • If the thumbnails refer to the image column in your table, you can get away with just inserting the filename, frame.jpg (or even the complete filepath, /public/path/to/frame.jpg).
    • If the thumbnails refer to the screenshots column in your table, and you want to have multiple thumbnails for your video, then you should consider creating a new table with a one-to-many relationship (from your video/application to a new table, e.g. thumbnails)
  4. Then when the user gets to a page where the image should be displayed, just select it from the table and display it with an <img> tag (with the public filepath).

I would also strongly recommend not to save the complete <video> tag into your database, but instead add it to the page where you actually want to show your video.

Example:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement