1

Iam using ffmpeg with php to create thumbnails for videos on the fly .It saves the thumbnails to a particular file and then i retrieve it using php. I want to create thumbnails for all types of videos possible. The problem with ffmpeg that iam facing is that iam not able to create thumbnails for videos with .mp4 extensions.

<?
$ffmpeg = '/usr/bin/ffmpeg/ffmpeg'; //to load the extension ffmpeg

$video = '/path/to/video'.$file_thumb; //path to the video

$image = '/store/it/here'; //path to store the thumbnail

$interval = 5;
$size = '640x480';

//It runs with the below command    
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size 
$image 2>&1"; 

?>

hakre
  • 178,314
  • 47
  • 389
  • 754
user1411837
  • 1,327
  • 6
  • 22
  • 37

6 Answers6

2

You can use this.

$in = root/path/to/video/filename/with/extension
$out = root/path/to/video/filename/with extension .jpg // always use jpg as image extension

exec("/PATH/TO/FFMPEG -itsoffset -4  -i ".$in." -vcodec mjpeg -vframes 1 -an -f rawvideo -s 120x100 ".$out);

It will create thumbnail of 120x100 size image at $out location and worked for me.

Govind Totla
  • 1,028
  • 11
  • 16
0

Try this:

<?php
     exec("$ffmpeg -itsoffset -105 -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image");
?>

Hope this helps.

AlphaMale
  • 23,514
  • 4
  • 57
  • 77
  • The above commands work fine .But i still cant create thumbnails for mp4 videos. Except mp4,the thumbnails are created for all the other videos. – user1411837 May 23 '12 at 08:29
0

try this:

ffmpeg required safe_mode Off in apache configuration file

then need to code:

// where ffmpeg is located, such as /usr/sbin/ffmpeg
$ffmpeg = 'ffmpeg';

// the input video file
$video = 'videos/'.$file_thumb;

// where you'll save the image
$image = 'uploads/videothumb/'.strtotime("now").'.jpg';

// default time to get the image
$second = 1;

// get the duration and a random place within that
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";

shell_exec($cmd);

i hope it works ..

Shadman
  • 660
  • 2
  • 10
  • 17
0

Verify your ffmpeg installation it supports the video you ask for. Try in the shell on the computer if it run independent form PHP. If it is not able to create the image, fix the ffmpeg installation first.

Ffmpeg is a free software project, and many of it's related persons are available for consultation in case you're not able to setup your own copy: http://ffmpeg.org/consulting.html

hakre
  • 178,314
  • 47
  • 389
  • 754
0

Try this

$ffmpeg = '/usr/bin/ffmpeg/ffmpeg';
$video = '/path/to/video'.$file_thumb; //path to the video
$image = '/store/it/here'; //path to store the thumbnail
$interval = 1;
$size = '640x480';
shell_exec($ffmpeg.' -i '. $video.' -deinterlace -an -ss $interval -t 00:00:01 -r 1 -y -s 1242x400 -vcodec mjpeg -f mjpeg '. $thumbnail.' 2>&1');
Alpesh Trivedi
  • 744
  • 2
  • 10
  • 30
-2

ffmpeg is deprecate now you can use "avconv"

here is sample example.

avconv  -itsoffset -4  -i VIDEO0001_8265186396728169230.mp4 -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg 
Zeeshan Akhter
  • 1,801
  • 18
  • 19
  • It is not deprecated. see this post: http://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv – Andre M Apr 29 '16 at 18:02