• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Projects
    • GStaticMap WP Plugin
  • Contact
  • Privacy Policy

Lorenz Blog

All About Web & Mobile Application Development

  • Featured Articles
  • Gadgets
    • Android
    • Blackberry
  • Programming
    • Android
    • PHP
    • Java Script
    • MySQL
    • Postgresql
    • Flex
    • Web
  • Software
    • Mac OS
    • Windows
    • Linux
  • Web
You are Here » Home >> Information Technology >> Programming >> PHP >> How to Get Video Thumbnail and Duration Using Mplayer and PHP

How to Get Video Thumbnail and Duration Using Mplayer and PHP

February 13, 2010 by Lorensius Londa 4 Comments

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];
Facebooktwitterredditpinterestlinkedinmailby feather

Related posts:

  1. Convert Video with Free Video Converter
  2. How to Use Flowplayer as Your Web Video Player (Beginner’s Guide)
  3. How to Overlay Video Using JQuery Tools and Flowplayer
  4. How to List A Directory Contents Using PHP (Recursive)

Filed Under: PHP, Programming Tagged With: get video duration, get video thumbnail, mplayer, video gallery, video player, video player php

About Lorensius Londa

Passionate web and mobile application developer. Co-founder of TRUSTUDIO, loves programming, Android, aviation, travelling, photography, coffee and gym mania.

Reader Interactions

Comments

  1. Rakesh Tembhurne says

    May 19, 2010 at 10:37 pm

    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.

    Reply
    • lorenz says

      May 19, 2010 at 11:08 pm

      try to remove -quite option

      Reply
  2. Michael Butler says

    May 20, 2011 at 9:15 pm

    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.

    Reply
  3. vijay gupta says

    August 13, 2012 at 1:38 pm

    hi friends
    Please give me a example to create thumbnail of video.
    Thank in advance

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About Me

A husband, father of two, passionate software developer, diy lover and home baker who loves to learn new things. Read More…

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube

Featured Articles

How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Blue Bamboo P25 Printer Android Demo Application With Source Code

Simple JSON RPC Client for Android

How to Send Message to Google Cloud Messaging (GCM) Server Using JSON and PHP

Footer

Recent Comments

  • Aditya Dabas on About
  • Ayten Göksenin Barutçu on How to Make Android Map Scrollable Inside a ScrollView Layout
  • mang jojot on About
  • Hussain on How to Programmatically Scan or Discover Android Bluetooth Devices

Recent Posts

  • How to Fix Blank Screen on WordPress Add/Edit Post Page
  • How to Programmatically Restart the ESP32 Board
  • How to Get Hardware Info of ESP32
  • How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Latest Tweets

  • @tricahyono_bowo @infobandung @infobdg Wah kejauhan om 355 days ago
  • Wilujeng enjing sadayana..Mohon info tempat powder coating dan sandblasting yg recommended di Bandung dunk @infobandung @infobdg359 days ago

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in