How to generate video preview thumbnails for use in VideoJS?

后端 未结 2 1306
心在旅途
心在旅途 2020-12-11 23:26

I moved over to VideoJs (html5) and need to figure out how to generate thumbnails for the seekbar. I have tried using videojs-thumbnails, however that requires having a prel

2条回答
  •  爱一瞬间的悲伤
    2020-12-11 23:40

    Surprised I didn't get a single comment/answer. Either way, after taking quite a few days I was able to find a working solution. At first I thought the solution would be using ffmpeg, however while it did work it was drastically slow. I eventually found the linux tool (available in Windows as well) called mtn (Movie Thumbnailer) found here. This tool was able to to create a sprite image from a two hour movie within about 6 seconds. I used the shell_exec function in php with the -v (verbose) option in order to parse out the time of each thumbnail as such:

    mtn -v -P -s 60 .jpg file.ext 2>&1
    

    Once there, it was simple logic, parsing, and math to create the necessary WebVTT file. All of this was done in php natively with the exception of having to use mtn with shell_exec.

    This solution works great and is pretty accurate. The only real issue is that the user has to wait a couple of seconds before the video is ready to be watched. I am currently looking at options to load the video first, generate the thumbnails in the background, and incorporate it into the video source once ready.

    I hope this solution helps anyone else out there that needs to dynamically generate thumbnails for their video player.

提交回复
热议问题