Search code examples
phpffmpegffmpeg-php

FFMpeg - Creating Thumbnail for Video file


I am new to php. I have installed ffmpeg in my local iis.. Is it possible to generate a thumbnail image for a flv file.? Please help..


Solution

  • Try this

    $ffmpeg = 'ffmpeg.exe';
    
    //video dir
    $video = 'video.flv';
    
    //where to save the image
    $image = 'image.jpg';
    
    //time to take screenshot at
    $interval = 5;
    
    //screenshot size
    $size = '320x240';
    
    //ffmpeg command
    $cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";       
    $return = `$cmd`;
    

    An explanation of the command options:

    -i filename (the source video's file path)
    -deinterlace (converts interlaced video to non-interlaced form)
    -an (audio recording is disabled; we don't need it for thumbnails)
    -ss position (input video is decoded and dumped until the timestamp reaches position, our thumbnail's position in seconds)
    -f output file format
    -t duration (the output file stops writing after duration seconds)
    -r fps (sets the frame rate to write at; fps is expressed in Hertz (1/seconds); we use 1 so that we grab only one frame)
    -y (overwrites the output file if it already exists)
    -s widthxheight (size of the frame in pixels)