How to get a video preview from the FLV file in PHP

Source: Internet
Author: User
Tags flv file
This article describes how to obtain a video preview from a FLV file in PHP. The example analyzes the php flv file acquisition skills and provides some reference value, for more information about how to obtain a video preview from a FLV file in PHP, see the following example. Share it with you for your reference. The specific implementation method is as follows:

The code is as follows:

<? Php
// References http://www.longtailvideo.com/support/forum/Modules/12661/External-PHP-with-FFmpeg-using-readfile-
// Generate a preview image from an FLV file on-the-fly, or to save
// Call with: ffmpeg_image.php? File = video. flv & time = 00:00:05 & browser = true
// Call with: ffmpeg_image.php? File = video. flv & percent = 75.3 & browser = true
// No time defaults to "00:00:01" (one second), no browser defaults to "true"
$ Videofile = (isset ($ _ GET ['file'])? Strval ($ _ GET ['file']): 'Video. flv ';
$ Image = substr ($ videofile, 0, strlen ($ videofile)-4 );
$ Time = (isset ($ _ GET ['Time'])? Strval ($ _ GET ['Time']): '00: 00: 01 ';
// Debug ("File:", $ videofile );
// Debug ("Image:", $ image );
// Debug ("Time:", $ time );
// Check time format
If (! Preg_match ('/\ d: \ d/', $ time ))
{
$ Time = "00:00:00 ";
}
If (isset ($ _ GET ['percent '])
{
$ Percent = $ _ GET ['percent '];
// Debug ("Percent:", $ percent );
Ob_start ();
Exec ("/usr/bin/ffmpeg-I \" ". $ videofile." \ "2> & 1 ");
$ Duration = ob_get_contents ();
Ob_end_clean ();
// Debug ("Duration:", $ duration );
Preg_match ('/Duration :(.*?), /', $ Duration, $ matches );
$ Duration = $ matches [1];
// Debug ("Duration:", $ duration );
$ Duration_array = split (':', $ duration );
$ Duration = $ duration_array [0] X 3600 + $ duration_array [1] * 60 + $ duration_array [2];
$ Time = $ duration * $ percent/100;
// Debug ("Time:", $ time );
$ Time = intval ($ time/3600 ). ":". intval ($ time-(intval ($ time/3600) * 3600)/60 ). ":". sprintf ("% 01.3f", ($ time-(intval ($ time/60) * 60 )));
// Debug ("Time:", $ time );
}
$ Browser = (isset ($ _ GET ['browser'])? Strval ($ _ GET ['Browser ']): 'true ';
// Debug ("Browser:", $ browser );
If ($ browser = "true ")
{
Header ('content-Type: image/png ');
Exec ("/usr/bin/ffmpeg-vcodec png-I \"". $ videofile. "\"-ss ". $ time. "-vframes 1-f image2 -");
// Header ('content-Type: image/jpeg ');
// Exec ("/usr/bin/ffmpeg-vcodec mjpeg-I \"". $ videofile. "\"-ss ". $ time. "-vframes 1-f image2 -");
}
Else
{
Exec ("/usr/bin/ffmpeg-vcodec png-I \"". $ videofile. "\"-ss ". $ time. "-vframes 1-f image2 \"". $ image. "\" mongod.png ");
// Exec ("/usr/bin/ffmpeg-vcodec mjpeg-I \"". $ videofile. "\"-ss ". $ time. "-vframes 1-f image2 \"". $ image. "\" d.jpg ");
}
?>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.