TransWikia.com

Use Video as Featured Image

WordPress Development Asked by tsquez on December 31, 2021

I have been looking for a non plugin solution where a user can upload a video, say, something from a site like http://www.coverr.co/.

When the user adds the video via the featured image link in the post/page editor, a static image will be generated and used as the featured image, but when the post is viewed, the title of the post is displayed on top of the actual video being played.

Hope that made sense. So far I haven’t found anything. Ideas?

One Answer

You can work around if you have time.
- Install http://ffmpeg-php.sourceforge.net/
- Create a custom meta field (upload field - you can use a plugin)
- In your template or loop, get retrieve the uploaded video URL and assign it to a variable
- Use the following function to generate an image from the retrieved video (I am not entirely sure if it will work and if it will not slow down your website)

$frame = 10;
$movie = 'test.mp4';   // this could be the variable from the vid url
$thumbnail = 'thumbnail.png';

$mov = new ffmpeg_movie($movie);  
$frame = $mov->getFrame($frame);
if ($frame) {
    $gd_image = $frame->toGDImage();
    if ($gd_image) {
       imagepng($gd_image, $thumbnail);
       imagedestroy($gd_image);
       echo '<img src="'.$thumbnail.'">';
    }
}

Original question: https://stackoverflow.com/questions/2043007/generate-preview-image-from-video-file

Answered by user23355 on December 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP