Mplayer is a free and open source media player that available for all major operating systems including Windows, Unix and Mac OS X. Basically Mplayer is a command line application but it also has GUI front end that differs to its supported operating system.
In PHP, we can execute Mplayer’s command line to get thumbnail and duration of a video file.
The basic command line to get thumbnail is:
[lorenz@localhost] mplayer -ss <position> videofile – frames <numofthumb> -nosound -vo jpeg<:outdir=path/to/outdir>.
where:
position, is seek position in seconds or in hh:mm:ss when the thumbnail is taken
videofile, is the video file or path to video file
numbofthumb, is the number of thumbnail created
:outdir=path/to/outdir, is the output directory. If the outdir is not specified, the default current working directory will be the output directory, make sure the output directory is writetable.
Example
[lorenz@localhost] mplayer -ss 10 video.flv -frames 1 -nosound -vo jpeg:outdir=/home/lorenz/video
The command above will create one thumbnail from video.flv at 10th second position, the output directory is /home/lorenz/video. The resulted thumbnail filename will be 00000001.jpg and will increase in accordance with number of thumbnail created, -frames 10 will result ten thumbnails with filename starts from 00000001.jpg to 00000010.jpg.
To execute in PHP, use exec command
exec("mplayer -ss 10 video.flv -frames 1 -nosound -vo jpeg:outdir=/home/lorenz");
The basic command line to get duration is:
[lorenz@localhost] mplayer -vo null -ao null -frames 0 -identify video.flv
The command above will output a lot of video information, the video duration is on ID_LENGTH=duration line.
To get the duration in PHP, we have to extract ID_LENGTH line from the output string.
The PHP code :
exec('mplayer -vo null -ao null -frames 0 -identify video.flv', $output); while (list($key, $value) = each($output)) { if ($length = strstr($v, "ID_LENGTH=")) break; } $data = explode('=', $length); $duration = $data [1];







I am doing a live streaming project where I have found similar scenario. I got a script in which the code was written but due to some problem the code is not working. The code something like this:
$cmd = $config['mplayer']. ' -quiet -nolirc -vo null -ao null -frames 0 -identify "' .$video_path. '"';
exec($cmd, $output);
Where, $config[‘mplayer’] = ‘/usr/bin/mplayer’; and $video_path is path to video. Exec command doest give any output.
try to remove -quite option
If it says invalid output device, you probably don’t have jpeg installed for mplayer. You can try “png” instead and then convert the png to jpg later.
hi friends
Please give me a example to create thumbnail of video.
Thank in advance