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.