how to create a thumbnail, at the time of video up

2019-07-19 09:07发布

问题:

I am trying to create a thumbnail for my uploading video. searching for easiest way to generate thumbnail at the time of video upload itself. i think if some provide the code without using ffmpeg will be life saving for me. because i'm running my code on windows wamp or any other alternative welcomed too thank you.

my real code is in CodeIgniter, not able to figure out how to do it.

$postname = $this->input->post('post-name');

            $configVideo['upload_path'] = './video';
            $configVideo['max_size'] = '1000000024';
            $configVideo['allowed_types'] = 'avi|flv|wmv|mp4';
            $configVideo['overwrite'] = TRUE;
            $configVideo['remove_spaces'] = TRUE;
            $ext = get_mime_by_extension($_FILES['video']['name']);
            $video_name = str_replace(' ', '_', $postname);
            $configVideo['file_name'] = $video_name;

            $this->load->library('upload', $configVideo);
            $this->upload->initialize($configVideo);

            if (!$this->upload->do_upload('video')) {

                $msg = $this->upload->display_errors();
                $this->session->set_flashdata('error', $msg);


            } else {
                $videoDetails = $this->upload->data(); 

回答1:

I think you will find it hard to get a solution for video manipulation that does not use ffmpeg in the open source world. Even if you can find something specifically for thumbnails, you may find in future you want to do other things like compression, add audio tracks etc for which ffpmeg will be useful.

The good news is that ffmpeg on a windows server and using PHP is a common solution, and there is a well used and supported PHP ffmpeg library you can use:

  • https://github.com/PHP-FFMpeg/PHP-FFMpeg

This includes a link to a set of ffmpeg builds that you can download onto your windows server, so you don't need to build ffmpeg yourself.

Take a look at the 'frame' method to capture a still to use as a thumbnail at a particular time in the video:

$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('frame.jpg');